LibreOffice Module chart2 (master) 1
WrappedAxisAndGridExistenceProperties.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <sal/config.h>
21
22#include <string_view>
23
25#include <com/sun/star/beans/XPropertySet.hpp>
26#include <Axis.hxx>
27#include <AxisHelper.hxx>
28#include <WrappedProperty.hxx>
30#include <TitleHelper.hxx>
31#include <utility>
32#include <osl/diagnose.h>
33
34using namespace ::com::sun::star;
35using ::com::sun::star::uno::Any;
36using ::com::sun::star::uno::Reference;
37
38namespace chart::wrapper
39{
40
41namespace {
42
43class WrappedAxisAndGridExistenceProperty : public WrappedProperty
44{
45public:
46 WrappedAxisAndGridExistenceProperty( bool bAxis, bool bMain, sal_Int32 nDimensionIndex
47 , std::shared_ptr<Chart2ModelContact> spChart2ModelContact );
48
49 virtual void setPropertyValue( const css::uno::Any& rOuterValue, const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
50
51 virtual css::uno::Any getPropertyValue( const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
52
53 virtual css::uno::Any getPropertyDefault( const css::uno::Reference< css::beans::XPropertyState >& xInnerPropertyState ) const override;
54
55private: //member
56 std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
57 bool m_bAxis;
58 bool m_bMain;
60};
61
62}
63
64void WrappedAxisAndGridExistenceProperties::addWrappedProperties( std::vector< std::unique_ptr<WrappedProperty> >& rList
65 , const std::shared_ptr< Chart2ModelContact >& spChart2ModelContact )
66{
67 rList.emplace_back( new WrappedAxisAndGridExistenceProperty( true, true, 0, spChart2ModelContact ) );//x axis
68 rList.emplace_back( new WrappedAxisAndGridExistenceProperty( true, false, 0, spChart2ModelContact ) );//x secondary axis
69 rList.emplace_back( new WrappedAxisAndGridExistenceProperty( false, true, 0, spChart2ModelContact ) );//x grid
70 rList.emplace_back( new WrappedAxisAndGridExistenceProperty( false, false, 0, spChart2ModelContact ) );//x help grid
71
72 rList.emplace_back( new WrappedAxisAndGridExistenceProperty( true, true, 1, spChart2ModelContact ) );//y axis
73 rList.emplace_back( new WrappedAxisAndGridExistenceProperty( true, false, 1, spChart2ModelContact ) );//y secondary axis
74 rList.emplace_back( new WrappedAxisAndGridExistenceProperty( false, true, 1, spChart2ModelContact ) );//y grid
75 rList.emplace_back( new WrappedAxisAndGridExistenceProperty( false, false, 1, spChart2ModelContact ) );//y help grid
76
77 rList.emplace_back( new WrappedAxisAndGridExistenceProperty( true, true, 2, spChart2ModelContact ) );//z axis
78 rList.emplace_back( new WrappedAxisAndGridExistenceProperty( false, true, 2, spChart2ModelContact ) );//z grid
79 rList.emplace_back( new WrappedAxisAndGridExistenceProperty( false, false, 2, spChart2ModelContact ) );//z help grid
80}
81
82WrappedAxisAndGridExistenceProperty::WrappedAxisAndGridExistenceProperty( bool bAxis, bool bMain, sal_Int32 nDimensionIndex
83 , std::shared_ptr<Chart2ModelContact> spChart2ModelContact )
84 : WrappedProperty(OUString(),OUString())
85 , m_spChart2ModelContact(std::move( spChart2ModelContact ))
86 , m_bAxis( bAxis )
87 , m_bMain( bMain )
88 , m_nDimensionIndex( nDimensionIndex )
89{
90 switch( m_nDimensionIndex )
91 {
92 case 0:
93 {
94 if( m_bAxis )
95 {
96 if( m_bMain )
97 m_aOuterName = "HasXAxis";
98 else
99 m_aOuterName = "HasSecondaryXAxis";
100 }
101 else
102 {
103 if( m_bMain )
104 m_aOuterName = "HasXAxisGrid";
105 else
106 m_aOuterName = "HasXAxisHelpGrid";
107 }
108 }
109 break;
110 case 2:
111 {
112 if( m_bAxis )
113 {
114 OSL_ENSURE(m_bMain,"there is no secondary z axis at the old api");
115 m_bMain = true;
116 m_aOuterName = "HasZAxis";
117 }
118 else
119 {
120 if( m_bMain )
121 m_aOuterName = "HasZAxisGrid";
122 else
123 m_aOuterName = "HasZAxisHelpGrid";
124 }
125 }
126 break;
127 default:
128 {
129 if( m_bAxis )
130 {
131 if( m_bMain )
132 m_aOuterName = "HasYAxis";
133 else
134 m_aOuterName = "HasSecondaryYAxis";
135 }
136 else
137 {
138 if( m_bMain )
139 m_aOuterName = "HasYAxisGrid";
140 else
141 m_aOuterName = "HasYAxisHelpGrid";
142 }
143 }
144 break;
145 }
146}
147
148void WrappedAxisAndGridExistenceProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
149{
150 bool bNewValue = false;
151 if( ! (rOuterValue >>= bNewValue) )
152 throw lang::IllegalArgumentException( "Has axis or grid properties require boolean values", nullptr, 0 );
153
154 bool bOldValue = false;
155 getPropertyValue( xInnerPropertySet ) >>= bOldValue;
156
157 if( bOldValue == bNewValue )
158 return;
159
161 if( bNewValue )
162 {
163 if( m_bAxis )
165 else
167 }
168 else
169 {
170 if( m_bAxis )
172 else
174 }
175}
176
177Any WrappedAxisAndGridExistenceProperty::getPropertyValue( const Reference< beans::XPropertySet >& /* xInnerPropertySet */ ) const
178{
179 Any aRet;
181 if(m_bAxis)
182 {
183 bool bShown = AxisHelper::isAxisShown( m_nDimensionIndex, m_bMain, xDiagram );
184 aRet <<= bShown;
185 }
186 else
187 {
188 bool bShown = AxisHelper::isGridShown( m_nDimensionIndex, 0, m_bMain, xDiagram );
189 aRet <<= bShown;
190 }
191 return aRet;
192}
193
194Any WrappedAxisAndGridExistenceProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
195{
196 Any aRet;
197 aRet <<= false;
198 return aRet;
199}
200
201namespace {
202
203class WrappedAxisTitleExistenceProperty : public WrappedProperty
204{
205public:
206 WrappedAxisTitleExistenceProperty( sal_Int32 nTitleIndex
207 , std::shared_ptr<Chart2ModelContact> spChart2ModelContact );
208
209 virtual void setPropertyValue( const css::uno::Any& rOuterValue, const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
210
211 virtual css::uno::Any getPropertyValue( const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
212
213 virtual css::uno::Any getPropertyDefault( const css::uno::Reference< css::beans::XPropertyState >& xInnerPropertyState ) const override;
214
215private: //member
216 std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
218};
219
220}
221
222void WrappedAxisTitleExistenceProperties::addWrappedProperties( std::vector< std::unique_ptr<WrappedProperty> >& rList
223 , const std::shared_ptr< Chart2ModelContact >& spChart2ModelContact )
224{
225 rList.emplace_back( new WrappedAxisTitleExistenceProperty( 0, spChart2ModelContact ) );//x axis title
226 rList.emplace_back( new WrappedAxisTitleExistenceProperty( 1, spChart2ModelContact ) );//y axis title
227 rList.emplace_back( new WrappedAxisTitleExistenceProperty( 2, spChart2ModelContact ) );//z axis title
228 rList.emplace_back( new WrappedAxisTitleExistenceProperty( 3, spChart2ModelContact ) );//secondary x axis title
229 rList.emplace_back( new WrappedAxisTitleExistenceProperty( 4, spChart2ModelContact ) );//secondary y axis title
230}
231
232WrappedAxisTitleExistenceProperty::WrappedAxisTitleExistenceProperty(sal_Int32 nTitleIndex
233 , std::shared_ptr<Chart2ModelContact> spChart2ModelContact)
234 : WrappedProperty(OUString(),OUString())
235 , m_spChart2ModelContact(std::move( spChart2ModelContact ))
236 , m_eTitleType( TitleHelper::Y_AXIS_TITLE )
237{
238 switch( nTitleIndex )
239 {
240 case 0:
241 m_aOuterName = "HasXAxisTitle";
243 break;
244 case 2:
245 m_aOuterName = "HasZAxisTitle";
247 break;
248 case 3:
249 m_aOuterName = "HasSecondaryXAxisTitle";
251 break;
252 case 4:
253 m_aOuterName = "HasSecondaryYAxisTitle";
255 break;
256 default:
257 m_aOuterName = "HasYAxisTitle";
259 break;
260 }
261}
262
263void WrappedAxisTitleExistenceProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
264{
265 bool bNewValue = false;
266 if( ! (rOuterValue >>= bNewValue) )
267 throw lang::IllegalArgumentException( "Has axis or grid properties require boolean values", nullptr, 0 );
268
269 bool bOldValue = false;
270 getPropertyValue( xInnerPropertySet ) >>= bOldValue;
271
272 if( bOldValue == bNewValue )
273 return;
274
275 if( bNewValue )
276 {
278 , m_spChart2ModelContact->getDocumentModel(), m_spChart2ModelContact->m_xContext );
279 }
280 else
281 {
283 }
284}
285
286Any WrappedAxisTitleExistenceProperty::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
287{
288 bool bHasTitle = false;
289
291 if( xTitle.is() && !TitleHelper::getCompleteString( xTitle ).isEmpty() )
292 bHasTitle = true;
293
294 Any aRet;
295 aRet <<= bHasTitle;
296 return aRet;
297
298}
299
300Any WrappedAxisTitleExistenceProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
301{
302 Any aRet;
303 aRet <<= false;
304 return aRet;
305}
306
307namespace {
308
309class WrappedAxisLabelExistenceProperty : public WrappedProperty
310{
311public:
312 WrappedAxisLabelExistenceProperty( bool bMain, sal_Int32 nDimensionIndex
313 , std::shared_ptr<Chart2ModelContact> spChart2ModelContact );
314
315 virtual void setPropertyValue( const css::uno::Any& rOuterValue, const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
316
317 virtual css::uno::Any getPropertyValue( const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
318
319 virtual css::uno::Any getPropertyDefault( const css::uno::Reference< css::beans::XPropertyState >& xInnerPropertyState ) const override;
320
321private: //member
322 std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
323 bool m_bMain;
324 sal_Int32 m_nDimensionIndex;
325};
326
327}
328
329void WrappedAxisLabelExistenceProperties::addWrappedProperties( std::vector< std::unique_ptr<WrappedProperty> >& rList
330 , const std::shared_ptr< Chart2ModelContact >& spChart2ModelContact )
331{
332 rList.emplace_back( new WrappedAxisLabelExistenceProperty( true, 0, spChart2ModelContact ) );//x axis
333 rList.emplace_back( new WrappedAxisLabelExistenceProperty( true, 1, spChart2ModelContact ) );//y axis
334 rList.emplace_back( new WrappedAxisLabelExistenceProperty( true, 2, spChart2ModelContact ) );//z axis
335 rList.emplace_back( new WrappedAxisLabelExistenceProperty( false, 0, spChart2ModelContact ) );//secondary x axis
336 rList.emplace_back( new WrappedAxisLabelExistenceProperty( false, 1, spChart2ModelContact ) );//secondary y axis
337}
338
339WrappedAxisLabelExistenceProperty::WrappedAxisLabelExistenceProperty(bool bMain, sal_Int32 nDimensionIndex
340 , std::shared_ptr<Chart2ModelContact> spChart2ModelContact)
341 : WrappedProperty(OUString(),OUString())
342 , m_spChart2ModelContact(std::move( spChart2ModelContact ))
343 , m_bMain( bMain )
344 , m_nDimensionIndex( nDimensionIndex )
345{
346 switch( m_nDimensionIndex )
347 {
348 case 0:
349 m_aOuterName = m_bMain ? std::u16string_view(u"HasXAxisDescription") : std::u16string_view(u"HasSecondaryXAxisDescription");
350 break;
351 case 2:
352 OSL_ENSURE(m_bMain,"there is no description available for a secondary z axis");
353 m_aOuterName = "HasZAxisDescription";
354 break;
355 default:
356 m_aOuterName = m_bMain ? std::u16string_view(u"HasYAxisDescription") : std::u16string_view(u"HasSecondaryYAxisDescription");
357 break;
358 }
359}
360
361void WrappedAxisLabelExistenceProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
362{
363 bool bNewValue = false;
364 if( ! (rOuterValue >>= bNewValue) )
365 throw lang::IllegalArgumentException( "Has axis or grid properties require boolean values", nullptr, 0 );
366
367 bool bOldValue = false;
368 getPropertyValue( xInnerPropertySet ) >>= bOldValue;
369
370 if( bOldValue == bNewValue )
371 return;
372
375 if( !xProp.is() && bNewValue )
376 {
377 //create axis if needed
379 if( xProp.is() )
380 xProp->setPropertyValue( "Show", uno::Any( false ) );
381 }
382 if( xProp.is() )
383 xProp->setPropertyValue( "DisplayLabels", rOuterValue );
384}
385
386Any WrappedAxisLabelExistenceProperty::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
387{
388 Any aRet;
391 if( xProp.is() )
392 aRet = xProp->getPropertyValue( "DisplayLabels" );
393 else
394 aRet <<= false;
395 return aRet;
396}
397
398Any WrappedAxisLabelExistenceProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
399{
400 Any aRet;
401 aRet <<= true;
402 return aRet;
403}
404
405} //namespace chart::wrapper
406
407/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact
TitleHelper::eTitleType m_eTitleType
static rtl::Reference< ::chart::Axis > getAxis(sal_Int32 nDimensionIndex, bool bMainAxis, const rtl::Reference< ::chart::Diagram > &xDiagram)
static rtl::Reference< ::chart::Axis > createAxis(sal_Int32 nDimensionIndex, bool bMainAxis, const rtl::Reference< ::chart::Diagram > &xDiagram, const css::uno::Reference< css::uno::XComponentContext > &xContext, ReferenceSizeProvider *pRefSizeProvider=nullptr)
static bool isAxisShown(sal_Int32 nDimensionIndex, bool bMainAxis, const rtl::Reference< ::chart::Diagram > &xDiagram)
Definition: AxisHelper.cxx:635
static void hideAxis(sal_Int32 nDimensionIndex, bool bMainAxis, const rtl::Reference< ::chart::Diagram > &xDiagram)
Definition: AxisHelper.cxx:461
static void hideGrid(sal_Int32 nDimensionIndex, sal_Int32 nCooSysIndex, bool bMainGrid, const rtl::Reference< ::chart::Diagram > &xDiagram)
Definition: AxisHelper.cxx:493
static void showAxis(sal_Int32 nDimensionIndex, bool bMainAxis, const rtl::Reference< ::chart::Diagram > &xDiagram, const css::uno::Reference< css::uno::XComponentContext > &xContext, ReferenceSizeProvider *pRefSizeProvider=nullptr)
Definition: AxisHelper.cxx:392
static bool isGridShown(sal_Int32 nDimensionIndex, sal_Int32 nCooSysIndex, bool bMainGrid, const rtl::Reference< ::chart::Diagram > &xDiagram)
Definition: AxisHelper.cxx:525
static void showGrid(sal_Int32 nDimensionIndex, sal_Int32 nCooSysIndex, bool bMainGrid, const rtl::Reference< ::chart::Diagram > &xDiagram)
Definition: AxisHelper.cxx:414
static void removeTitle(eTitleType nTitleIndex, const rtl::Reference< ::chart::ChartModel > &xModel)
static rtl::Reference< ::chart::Title > getTitle(eTitleType nTitleIndex, ChartModel &rModel)
static rtl::Reference< ::chart::Title > createTitle(eTitleType nTitleIndex, const OUString &rTitleText, const rtl::Reference< ::chart::ChartModel > &xModel, const css::uno::Reference< css::uno::XComponentContext > &xContext, ReferenceSizeProvider *pRefSizeProvider=nullptr)
static OUString getCompleteString(const rtl::Reference< ::chart::Title > &xTitle)
static void addWrappedProperties(std::vector< std::unique_ptr< WrappedProperty > > &rList, const std::shared_ptr< Chart2ModelContact > &spChart2ModelContact)
static void addWrappedProperties(std::vector< std::unique_ptr< WrappedProperty > > &rList, const std::shared_ptr< Chart2ModelContact > &spChart2ModelContact)
static void addWrappedProperties(std::vector< std::unique_ptr< WrappedProperty > > &rList, const std::shared_ptr< Chart2ModelContact > &spChart2ModelContact)
float u
void setPropertyValue(tPropertyValueMap &rOutMap, tPropertyValueMapKey key, const Value &value)
Set a property to a certain value in the given map.
bool getPropertyValue(ValueType &rValue, css::uno::Reference< css::beans::XPropertySet > const &xPropSet, OUString const &propName)