1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "WrappedAxisAndGridExistenceProperties.hxx"
21 #include <com/sun/star/beans/XPropertySet.hpp>
22 #include <AxisHelper.hxx>
23 #include <WrappedProperty.hxx>
24 #include "Chart2ModelContact.hxx"
25 #include <TitleHelper.hxx>
26 #include <osl/diagnose.h>
28 using namespace ::com::sun::star
;
29 using ::com::sun::star::uno::Any
;
30 using ::com::sun::star::uno::Reference
;
37 class WrappedAxisAndGridExistenceProperty
: public WrappedProperty
40 WrappedAxisAndGridExistenceProperty( bool bAxis
, bool bMain
, sal_Int32 nDimensionIndex
41 , const std::shared_ptr
<Chart2ModelContact
>& spChart2ModelContact
);
43 virtual void setPropertyValue( const css::uno::Any
& rOuterValue
, const css::uno::Reference
< css::beans::XPropertySet
>& xInnerPropertySet
) const override
;
45 virtual css::uno::Any
getPropertyValue( const css::uno::Reference
< css::beans::XPropertySet
>& xInnerPropertySet
) const override
;
47 virtual css::uno::Any
getPropertyDefault( const css::uno::Reference
< css::beans::XPropertyState
>& xInnerPropertyState
) const override
;
50 std::shared_ptr
< Chart2ModelContact
> m_spChart2ModelContact
;
53 sal_Int32 m_nDimensionIndex
;
56 void WrappedAxisAndGridExistenceProperties::addWrappedProperties( std::vector
< std::unique_ptr
<WrappedProperty
> >& rList
57 , const std::shared_ptr
< Chart2ModelContact
>& spChart2ModelContact
)
59 rList
.emplace_back( new WrappedAxisAndGridExistenceProperty( true, true, 0, spChart2ModelContact
) );//x axis
60 rList
.emplace_back( new WrappedAxisAndGridExistenceProperty( true, false, 0, spChart2ModelContact
) );//x secondary axis
61 rList
.emplace_back( new WrappedAxisAndGridExistenceProperty( false, true, 0, spChart2ModelContact
) );//x grid
62 rList
.emplace_back( new WrappedAxisAndGridExistenceProperty( false, false, 0, spChart2ModelContact
) );//x help grid
64 rList
.emplace_back( new WrappedAxisAndGridExistenceProperty( true, true, 1, spChart2ModelContact
) );//y axis
65 rList
.emplace_back( new WrappedAxisAndGridExistenceProperty( true, false, 1, spChart2ModelContact
) );//y secondary axis
66 rList
.emplace_back( new WrappedAxisAndGridExistenceProperty( false, true, 1, spChart2ModelContact
) );//y grid
67 rList
.emplace_back( new WrappedAxisAndGridExistenceProperty( false, false, 1, spChart2ModelContact
) );//y help grid
69 rList
.emplace_back( new WrappedAxisAndGridExistenceProperty( true, true, 2, spChart2ModelContact
) );//z axis
70 rList
.emplace_back( new WrappedAxisAndGridExistenceProperty( false, true, 2, spChart2ModelContact
) );//z grid
71 rList
.emplace_back( new WrappedAxisAndGridExistenceProperty( false, false, 2, spChart2ModelContact
) );//z help grid
74 WrappedAxisAndGridExistenceProperty::WrappedAxisAndGridExistenceProperty( bool bAxis
, bool bMain
, sal_Int32 nDimensionIndex
75 , const std::shared_ptr
<Chart2ModelContact
>& spChart2ModelContact
)
76 : WrappedProperty(OUString(),OUString())
77 , m_spChart2ModelContact( spChart2ModelContact
)
80 , m_nDimensionIndex( nDimensionIndex
)
82 switch( m_nDimensionIndex
)
89 m_aOuterName
= "HasXAxis";
91 m_aOuterName
= "HasSecondaryXAxis";
96 m_aOuterName
= "HasXAxisGrid";
98 m_aOuterName
= "HasXAxisHelpGrid";
106 OSL_ENSURE(m_bMain
,"there is no secondary z axis at the old api");
108 m_aOuterName
= "HasZAxis";
113 m_aOuterName
= "HasZAxisGrid";
115 m_aOuterName
= "HasZAxisHelpGrid";
124 m_aOuterName
= "HasYAxis";
126 m_aOuterName
= "HasSecondaryYAxis";
131 m_aOuterName
= "HasYAxisGrid";
133 m_aOuterName
= "HasYAxisHelpGrid";
140 void WrappedAxisAndGridExistenceProperty::setPropertyValue( const Any
& rOuterValue
, const Reference
< beans::XPropertySet
>& xInnerPropertySet
) const
142 bool bNewValue
= false;
143 if( ! (rOuterValue
>>= bNewValue
) )
144 throw lang::IllegalArgumentException( "Has axis or grid properties require boolean values", nullptr, 0 );
146 bool bOldValue
= false;
147 getPropertyValue( xInnerPropertySet
) >>= bOldValue
;
149 if( bOldValue
== bNewValue
)
152 Reference
< chart2::XDiagram
> xDiagram( m_spChart2ModelContact
->getChart2Diagram() );
156 AxisHelper::showAxis( m_nDimensionIndex
, m_bMain
, xDiagram
, m_spChart2ModelContact
->m_xContext
);
158 AxisHelper::showGrid( m_nDimensionIndex
, 0, m_bMain
, xDiagram
);
163 AxisHelper::hideAxis( m_nDimensionIndex
, m_bMain
, xDiagram
);
165 AxisHelper::hideGrid( m_nDimensionIndex
, 0, m_bMain
, xDiagram
);
169 Any
WrappedAxisAndGridExistenceProperty::getPropertyValue( const Reference
< beans::XPropertySet
>& /* xInnerPropertySet */ ) const
172 Reference
< chart2::XDiagram
> xDiagram( m_spChart2ModelContact
->getChart2Diagram() );
175 bool bShown
= AxisHelper::isAxisShown( m_nDimensionIndex
, m_bMain
, xDiagram
);
180 bool bShown
= AxisHelper::isGridShown( m_nDimensionIndex
, 0, m_bMain
, xDiagram
);
186 Any
WrappedAxisAndGridExistenceProperty::getPropertyDefault( const Reference
< beans::XPropertyState
>& /*xInnerPropertyState*/ ) const
193 class WrappedAxisTitleExistenceProperty
: public WrappedProperty
196 WrappedAxisTitleExistenceProperty( sal_Int32 nTitleIndex
197 , const std::shared_ptr
<Chart2ModelContact
>& spChart2ModelContact
);
199 virtual void setPropertyValue( const css::uno::Any
& rOuterValue
, const css::uno::Reference
< css::beans::XPropertySet
>& xInnerPropertySet
) const override
;
201 virtual css::uno::Any
getPropertyValue( const css::uno::Reference
< css::beans::XPropertySet
>& xInnerPropertySet
) const override
;
203 virtual css::uno::Any
getPropertyDefault( const css::uno::Reference
< css::beans::XPropertyState
>& xInnerPropertyState
) const override
;
206 std::shared_ptr
< Chart2ModelContact
> m_spChart2ModelContact
;
207 TitleHelper::eTitleType m_eTitleType
;
210 void WrappedAxisTitleExistenceProperties::addWrappedProperties( std::vector
< std::unique_ptr
<WrappedProperty
> >& rList
211 , const std::shared_ptr
< Chart2ModelContact
>& spChart2ModelContact
)
213 rList
.emplace_back( new WrappedAxisTitleExistenceProperty( 0, spChart2ModelContact
) );//x axis title
214 rList
.emplace_back( new WrappedAxisTitleExistenceProperty( 1, spChart2ModelContact
) );//y axis title
215 rList
.emplace_back( new WrappedAxisTitleExistenceProperty( 2, spChart2ModelContact
) );//z axis title
216 rList
.emplace_back( new WrappedAxisTitleExistenceProperty( 3, spChart2ModelContact
) );//secondary x axis title
217 rList
.emplace_back( new WrappedAxisTitleExistenceProperty( 4, spChart2ModelContact
) );//secondary y axis title
220 WrappedAxisTitleExistenceProperty::WrappedAxisTitleExistenceProperty(sal_Int32 nTitleIndex
221 , const std::shared_ptr
<Chart2ModelContact
>& spChart2ModelContact
)
222 : WrappedProperty(OUString(),OUString())
223 , m_spChart2ModelContact( spChart2ModelContact
)
224 , m_eTitleType( TitleHelper::Y_AXIS_TITLE
)
226 switch( nTitleIndex
)
229 m_aOuterName
= "HasXAxisTitle";
230 m_eTitleType
= TitleHelper::X_AXIS_TITLE
;
233 m_aOuterName
= "HasZAxisTitle";
234 m_eTitleType
= TitleHelper::Z_AXIS_TITLE
;
237 m_aOuterName
= "HasSecondaryXAxisTitle";
238 m_eTitleType
= TitleHelper::SECONDARY_X_AXIS_TITLE
;
241 m_aOuterName
= "HasSecondaryYAxisTitle";
242 m_eTitleType
= TitleHelper::SECONDARY_Y_AXIS_TITLE
;
245 m_aOuterName
= "HasYAxisTitle";
246 m_eTitleType
= TitleHelper::Y_AXIS_TITLE
;
251 void WrappedAxisTitleExistenceProperty::setPropertyValue( const Any
& rOuterValue
, const Reference
< beans::XPropertySet
>& xInnerPropertySet
) const
253 bool bNewValue
= false;
254 if( ! (rOuterValue
>>= bNewValue
) )
255 throw lang::IllegalArgumentException( "Has axis or grid properties require boolean values", nullptr, 0 );
257 bool bOldValue
= false;
258 getPropertyValue( xInnerPropertySet
) >>= bOldValue
;
260 if( bOldValue
== bNewValue
)
265 TitleHelper::createTitle( m_eTitleType
, OUString()
266 , m_spChart2ModelContact
->getChartModel(), m_spChart2ModelContact
->m_xContext
);
270 TitleHelper::removeTitle( m_eTitleType
, m_spChart2ModelContact
->getChartModel() );
274 Any
WrappedAxisTitleExistenceProperty::getPropertyValue( const Reference
< beans::XPropertySet
>& /*xInnerPropertySet*/ ) const
276 bool bHasTitle
= false;
278 Reference
< chart2::XTitle
> xTitle( TitleHelper::getTitle( m_eTitleType
, m_spChart2ModelContact
->getChartModel() ) );
279 if( xTitle
.is() && !TitleHelper::getCompleteString( xTitle
).isEmpty() )
288 Any
WrappedAxisTitleExistenceProperty::getPropertyDefault( const Reference
< beans::XPropertyState
>& /*xInnerPropertyState*/ ) const
295 class WrappedAxisLabelExistenceProperty
: public WrappedProperty
298 WrappedAxisLabelExistenceProperty( bool bMain
, sal_Int32 nDimensionIndex
299 , const std::shared_ptr
<Chart2ModelContact
>& spChart2ModelContact
);
301 virtual void setPropertyValue( const css::uno::Any
& rOuterValue
, const css::uno::Reference
< css::beans::XPropertySet
>& xInnerPropertySet
) const override
;
303 virtual css::uno::Any
getPropertyValue( const css::uno::Reference
< css::beans::XPropertySet
>& xInnerPropertySet
) const override
;
305 virtual css::uno::Any
getPropertyDefault( const css::uno::Reference
< css::beans::XPropertyState
>& xInnerPropertyState
) const override
;
308 std::shared_ptr
< Chart2ModelContact
> m_spChart2ModelContact
;
310 sal_Int32 m_nDimensionIndex
;
313 void WrappedAxisLabelExistenceProperties::addWrappedProperties( std::vector
< std::unique_ptr
<WrappedProperty
> >& rList
314 , const std::shared_ptr
< Chart2ModelContact
>& spChart2ModelContact
)
316 rList
.emplace_back( new WrappedAxisLabelExistenceProperty( true, 0, spChart2ModelContact
) );//x axis
317 rList
.emplace_back( new WrappedAxisLabelExistenceProperty( true, 1, spChart2ModelContact
) );//y axis
318 rList
.emplace_back( new WrappedAxisLabelExistenceProperty( true, 2, spChart2ModelContact
) );//z axis
319 rList
.emplace_back( new WrappedAxisLabelExistenceProperty( false, 0, spChart2ModelContact
) );//secondary x axis
320 rList
.emplace_back( new WrappedAxisLabelExistenceProperty( false, 1, spChart2ModelContact
) );//secondary y axis
323 WrappedAxisLabelExistenceProperty::WrappedAxisLabelExistenceProperty(bool bMain
, sal_Int32 nDimensionIndex
324 , const std::shared_ptr
<Chart2ModelContact
>& spChart2ModelContact
)
325 : WrappedProperty(OUString(),OUString())
326 , m_spChart2ModelContact( spChart2ModelContact
)
328 , m_nDimensionIndex( nDimensionIndex
)
330 switch( m_nDimensionIndex
)
333 m_bMain
? m_aOuterName
= "HasXAxisDescription" : m_aOuterName
= "HasSecondaryXAxisDescription";
336 OSL_ENSURE(m_bMain
,"there is no description available for a secondary z axis");
337 m_aOuterName
= "HasZAxisDescription";
340 m_bMain
? m_aOuterName
= "HasYAxisDescription" : m_aOuterName
= "HasSecondaryYAxisDescription";
345 void WrappedAxisLabelExistenceProperty::setPropertyValue( const Any
& rOuterValue
, const Reference
< beans::XPropertySet
>& xInnerPropertySet
) const
347 bool bNewValue
= false;
348 if( ! (rOuterValue
>>= bNewValue
) )
349 throw lang::IllegalArgumentException( "Has axis or grid properties require boolean values", nullptr, 0 );
351 bool bOldValue
= false;
352 getPropertyValue( xInnerPropertySet
) >>= bOldValue
;
354 if( bOldValue
== bNewValue
)
357 Reference
< chart2::XDiagram
> xDiagram( m_spChart2ModelContact
->getChart2Diagram() );
358 Reference
< beans::XPropertySet
> xProp( AxisHelper::getAxis( m_nDimensionIndex
, m_bMain
, xDiagram
), uno::UNO_QUERY
);
359 if( !xProp
.is() && bNewValue
)
361 //create axis if needed
362 xProp
.set( AxisHelper::createAxis( m_nDimensionIndex
, m_bMain
, xDiagram
, m_spChart2ModelContact
->m_xContext
), uno::UNO_QUERY
);
364 xProp
->setPropertyValue( "Show", uno::Any( false ) );
367 xProp
->setPropertyValue( "DisplayLabels", rOuterValue
);
370 Any
WrappedAxisLabelExistenceProperty::getPropertyValue( const Reference
< beans::XPropertySet
>& /*xInnerPropertySet*/ ) const
373 Reference
< chart2::XDiagram
> xDiagram( m_spChart2ModelContact
->getChart2Diagram() );
374 Reference
< beans::XPropertySet
> xProp( AxisHelper::getAxis( m_nDimensionIndex
, m_bMain
, xDiagram
), uno::UNO_QUERY
);
376 aRet
= xProp
->getPropertyValue( "DisplayLabels" );
382 Any
WrappedAxisLabelExistenceProperty::getPropertyDefault( const Reference
< beans::XPropertyState
>& /*xInnerPropertyState*/ ) const
389 } //namespace wrapper
392 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */