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