Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / chart2 / source / controller / chartapiwrapper / WrappedAxisAndGridExistenceProperties.cxx
blobad349fa0275a4eb8b17c0f92147e67c9b0d70960
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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;
32 namespace chart
34 namespace wrapper
37 class WrappedAxisAndGridExistenceProperty : public WrappedProperty
39 public:
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;
49 private: //member
50 std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
51 bool m_bAxis;
52 bool m_bMain;
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 )
78 , m_bAxis( bAxis )
79 , m_bMain( bMain )
80 , m_nDimensionIndex( nDimensionIndex )
82 switch( m_nDimensionIndex )
84 case 0:
86 if( m_bAxis )
88 if( m_bMain )
89 m_aOuterName = "HasXAxis";
90 else
91 m_aOuterName = "HasSecondaryXAxis";
93 else
95 if( m_bMain )
96 m_aOuterName = "HasXAxisGrid";
97 else
98 m_aOuterName = "HasXAxisHelpGrid";
101 break;
102 case 2:
104 if( m_bAxis )
106 OSL_ENSURE(m_bMain,"there is no secondary z axis at the old api");
107 m_bMain = true;
108 m_aOuterName = "HasZAxis";
110 else
112 if( m_bMain )
113 m_aOuterName = "HasZAxisGrid";
114 else
115 m_aOuterName = "HasZAxisHelpGrid";
118 break;
119 default:
121 if( m_bAxis )
123 if( m_bMain )
124 m_aOuterName = "HasYAxis";
125 else
126 m_aOuterName = "HasSecondaryYAxis";
128 else
130 if( m_bMain )
131 m_aOuterName = "HasYAxisGrid";
132 else
133 m_aOuterName = "HasYAxisHelpGrid";
136 break;
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 )
150 return;
152 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
153 if( bNewValue )
155 if( m_bAxis )
156 AxisHelper::showAxis( m_nDimensionIndex, m_bMain, xDiagram, m_spChart2ModelContact->m_xContext );
157 else
158 AxisHelper::showGrid( m_nDimensionIndex, 0, m_bMain, xDiagram );
160 else
162 if( m_bAxis )
163 AxisHelper::hideAxis( m_nDimensionIndex, m_bMain, xDiagram );
164 else
165 AxisHelper::hideGrid( m_nDimensionIndex, 0, m_bMain, xDiagram );
169 Any WrappedAxisAndGridExistenceProperty::getPropertyValue( const Reference< beans::XPropertySet >& /* xInnerPropertySet */ ) const
171 Any aRet;
172 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
173 if(m_bAxis)
175 bool bShown = AxisHelper::isAxisShown( m_nDimensionIndex, m_bMain, xDiagram );
176 aRet <<= bShown;
178 else
180 bool bShown = AxisHelper::isGridShown( m_nDimensionIndex, 0, m_bMain, xDiagram );
181 aRet <<= bShown;
183 return aRet;
186 Any WrappedAxisAndGridExistenceProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
188 Any aRet;
189 aRet <<= false;
190 return aRet;
193 class WrappedAxisTitleExistenceProperty : public WrappedProperty
195 public:
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;
205 private: //member
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 )
228 case 0:
229 m_aOuterName = "HasXAxisTitle";
230 m_eTitleType = TitleHelper::X_AXIS_TITLE;
231 break;
232 case 2:
233 m_aOuterName = "HasZAxisTitle";
234 m_eTitleType = TitleHelper::Z_AXIS_TITLE;
235 break;
236 case 3:
237 m_aOuterName = "HasSecondaryXAxisTitle";
238 m_eTitleType = TitleHelper::SECONDARY_X_AXIS_TITLE;
239 break;
240 case 4:
241 m_aOuterName = "HasSecondaryYAxisTitle";
242 m_eTitleType = TitleHelper::SECONDARY_Y_AXIS_TITLE;
243 break;
244 default:
245 m_aOuterName = "HasYAxisTitle";
246 m_eTitleType = TitleHelper::Y_AXIS_TITLE;
247 break;
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 )
261 return;
263 if( bNewValue )
265 TitleHelper::createTitle( m_eTitleType, OUString()
266 , m_spChart2ModelContact->getChartModel(), m_spChart2ModelContact->m_xContext );
268 else
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() )
280 bHasTitle = true;
282 Any aRet;
283 aRet <<= bHasTitle;
284 return aRet;
288 Any WrappedAxisTitleExistenceProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
290 Any aRet;
291 aRet <<= false;
292 return aRet;
295 class WrappedAxisLabelExistenceProperty : public WrappedProperty
297 public:
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;
307 private: //member
308 std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
309 bool m_bMain;
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 )
327 , m_bMain( bMain )
328 , m_nDimensionIndex( nDimensionIndex )
330 switch( m_nDimensionIndex )
332 case 0:
333 m_bMain ? m_aOuterName = "HasXAxisDescription" : m_aOuterName = "HasSecondaryXAxisDescription";
334 break;
335 case 2:
336 OSL_ENSURE(m_bMain,"there is no description available for a secondary z axis");
337 m_aOuterName = "HasZAxisDescription";
338 break;
339 default:
340 m_bMain ? m_aOuterName = "HasYAxisDescription" : m_aOuterName = "HasSecondaryYAxisDescription";
341 break;
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 )
355 return;
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 );
363 if( xProp.is() )
364 xProp->setPropertyValue( "Show", uno::Any( false ) );
366 if( xProp.is() )
367 xProp->setPropertyValue( "DisplayLabels", rOuterValue );
370 Any WrappedAxisLabelExistenceProperty::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
372 Any aRet;
373 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
374 Reference< beans::XPropertySet > xProp( AxisHelper::getAxis( m_nDimensionIndex, m_bMain, xDiagram ), uno::UNO_QUERY );
375 if( xProp.is() )
376 aRet = xProp->getPropertyValue( "DisplayLabels" );
377 else
378 aRet <<= false;
379 return aRet;
382 Any WrappedAxisLabelExistenceProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
384 Any aRet;
385 aRet <<= true;
386 return aRet;
389 } //namespace wrapper
390 } //namespace chart
392 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */