/src/libreoffice/chart2/source/controller/chartapiwrapper/ChartDataWrapper.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 "ChartDataWrapper.hxx" |
21 | | #include <DiagramHelper.hxx> |
22 | | #include <DataSourceHelper.hxx> |
23 | | #include <InternalDataProvider.hxx> |
24 | | #include <ControllerLockGuard.hxx> |
25 | | #include "Chart2ModelContact.hxx" |
26 | | #include <cppuhelper/supportsservice.hxx> |
27 | | #include <com/sun/star/chart/XChartDocument.hpp> |
28 | | |
29 | | #include <float.h> |
30 | | #include <cmath> |
31 | | #include <limits> |
32 | | #include <utility> |
33 | | #include <osl/diagnose.h> |
34 | | |
35 | | using namespace ::com::sun::star; |
36 | | using ::com::sun::star::uno::Reference; |
37 | | using ::com::sun::star::uno::Sequence; |
38 | | using ::com::sun::star::chart2::XAnyDescriptionAccess; |
39 | | using ::com::sun::star::chart::XComplexDescriptionAccess; |
40 | | using ::com::sun::star::chart::XChartData; |
41 | | using ::com::sun::star::chart::XChartDataArray; |
42 | | using ::com::sun::star::chart::XDateCategories; |
43 | | |
44 | | namespace |
45 | | { |
46 | | |
47 | | uno::Sequence< uno::Sequence< double > > lcl_getNANInsteadDBL_MIN( const uno::Sequence< uno::Sequence< double > >& rData ) |
48 | 0 | { |
49 | 0 | uno::Sequence< uno::Sequence< double > > aRet; |
50 | 0 | const sal_Int32 nOuterSize = rData.getLength(); |
51 | 0 | aRet.realloc( nOuterSize ); |
52 | 0 | auto pRet = aRet.getArray(); |
53 | 0 | for( sal_Int32 nOuter=0; nOuter<nOuterSize; ++nOuter ) |
54 | 0 | { |
55 | 0 | sal_Int32 nInnerSize = rData[nOuter].getLength(); |
56 | 0 | pRet[nOuter].realloc( nInnerSize ); |
57 | 0 | auto pRet_nOuter = pRet[nOuter].getArray(); |
58 | 0 | for( sal_Int32 nInner=0; nInner<nInnerSize; ++nInner ) |
59 | 0 | { |
60 | 0 | pRet_nOuter[nInner] = rData[nOuter][nInner]; |
61 | 0 | double& rValue = pRet_nOuter[nInner]; |
62 | 0 | if( rValue == DBL_MIN ) |
63 | 0 | rValue = std::numeric_limits<double>::quiet_NaN(); |
64 | 0 | } |
65 | 0 | } |
66 | 0 | return aRet; |
67 | 0 | } |
68 | | |
69 | | uno::Sequence< uno::Sequence< double > > lcl_getDBL_MINInsteadNAN( const uno::Sequence< uno::Sequence< double > >& rData ) |
70 | 0 | { |
71 | 0 | uno::Sequence< uno::Sequence< double > > aRet; |
72 | 0 | const sal_Int32 nOuterSize = rData.getLength(); |
73 | 0 | aRet.realloc( nOuterSize ); |
74 | 0 | auto pRet = aRet.getArray(); |
75 | 0 | for( sal_Int32 nOuter=0; nOuter<nOuterSize; ++nOuter ) |
76 | 0 | { |
77 | 0 | sal_Int32 nInnerSize = rData[nOuter].getLength(); |
78 | 0 | pRet[nOuter].realloc( nInnerSize ); |
79 | 0 | auto pRet_nOuter = pRet[nOuter].getArray(); |
80 | 0 | for( sal_Int32 nInner=0; nInner<nInnerSize; ++nInner ) |
81 | 0 | { |
82 | 0 | pRet_nOuter[nInner] = rData[nOuter][nInner]; |
83 | 0 | double& rValue = pRet_nOuter[nInner]; |
84 | 0 | if( std::isnan( rValue ) ) |
85 | 0 | rValue = DBL_MIN; |
86 | 0 | } |
87 | 0 | } |
88 | 0 | return aRet; |
89 | 0 | } |
90 | | |
91 | | } // anonymous namespace |
92 | | |
93 | | namespace chart::wrapper |
94 | | { |
95 | | |
96 | | struct lcl_Operator |
97 | | { |
98 | | lcl_Operator() |
99 | 0 | { |
100 | 0 | } |
101 | | virtual ~lcl_Operator() |
102 | 0 | { |
103 | 0 | } |
104 | | virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess ) = 0; |
105 | | |
106 | | virtual bool setsCategories( bool /*bDataInColumns*/ ) |
107 | 0 | { |
108 | 0 | return false; |
109 | 0 | } |
110 | | }; |
111 | | |
112 | | namespace { |
113 | | |
114 | | struct lcl_AllOperator : public lcl_Operator |
115 | | { |
116 | | explicit lcl_AllOperator( const Reference< XChartData >& xDataToApply ) |
117 | 0 | : m_xDataToApply( xDataToApply ) |
118 | 0 | { |
119 | 0 | } |
120 | | |
121 | | virtual bool setsCategories( bool /*bDataInColumns*/ ) override |
122 | 0 | { |
123 | | // Do not force creation of categories, when original has no categories |
124 | 0 | if (auto pDataWrapper = dynamic_cast<const ChartDataWrapper*>(m_xDataToApply.get())) |
125 | 0 | if (auto xChartModel = pDataWrapper->getChartModel()) |
126 | 0 | if (auto xDiagram = xChartModel->getFirstChartDiagram()) |
127 | 0 | return xDiagram->getCategories().is(); |
128 | 0 | return true; |
129 | 0 | } |
130 | | |
131 | | virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess ) override |
132 | 0 | { |
133 | 0 | if( !xDataAccess.is() ) |
134 | 0 | return; |
135 | | |
136 | 0 | Reference< XAnyDescriptionAccess > xNewAny( m_xDataToApply, uno::UNO_QUERY ); |
137 | 0 | Reference< XComplexDescriptionAccess > xNewComplex( m_xDataToApply, uno::UNO_QUERY ); |
138 | 0 | if( xNewAny.is() ) |
139 | 0 | { |
140 | 0 | xDataAccess->setData( xNewAny->getData() ); |
141 | 0 | xDataAccess->setComplexRowDescriptions( xNewAny->getComplexRowDescriptions() ); |
142 | 0 | xDataAccess->setComplexColumnDescriptions( xNewAny->getComplexColumnDescriptions() ); |
143 | 0 | } |
144 | 0 | else if( xNewComplex.is() ) |
145 | 0 | { |
146 | 0 | xDataAccess->setData( xNewComplex->getData() ); |
147 | 0 | xDataAccess->setComplexRowDescriptions( xNewComplex->getComplexRowDescriptions() ); |
148 | 0 | xDataAccess->setComplexColumnDescriptions( xNewComplex->getComplexColumnDescriptions() ); |
149 | 0 | } |
150 | 0 | else |
151 | 0 | { |
152 | 0 | Reference< XChartDataArray > xNew( m_xDataToApply, uno::UNO_QUERY ); |
153 | 0 | if( xNew.is() ) |
154 | 0 | { |
155 | 0 | xDataAccess->setData( xNew->getData() ); |
156 | 0 | xDataAccess->setRowDescriptions( xNew->getRowDescriptions() ); |
157 | 0 | xDataAccess->setColumnDescriptions( xNew->getColumnDescriptions() ); |
158 | 0 | } |
159 | 0 | } |
160 | 0 | } |
161 | | |
162 | | Reference< XChartData > m_xDataToApply; |
163 | | }; |
164 | | |
165 | | struct lcl_DataOperator : public lcl_Operator |
166 | | { |
167 | | explicit lcl_DataOperator( const Sequence< Sequence< double > >& rData ) |
168 | 0 | : m_rData( rData ) |
169 | 0 | { |
170 | 0 | } |
171 | | |
172 | | virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess ) override |
173 | 0 | { |
174 | 0 | if( xDataAccess.is() ) |
175 | 0 | xDataAccess->setData( lcl_getNANInsteadDBL_MIN( m_rData ) ); |
176 | 0 | } |
177 | | |
178 | | const Sequence< Sequence< double > >& m_rData; |
179 | | }; |
180 | | |
181 | | struct lcl_RowDescriptionsOperator : public lcl_Operator |
182 | | { |
183 | | lcl_RowDescriptionsOperator( const Sequence< OUString >& rRowDescriptions |
184 | | , rtl::Reference<::chart::ChartModel> xChartDoc ) |
185 | 0 | : m_rRowDescriptions( rRowDescriptions ) |
186 | 0 | , m_xChartDoc(std::move(xChartDoc)) |
187 | 0 | , m_bDataInColumns(true) |
188 | 0 | { |
189 | 0 | } |
190 | | |
191 | | virtual bool setsCategories( bool bDataInColumns ) override |
192 | 0 | { |
193 | 0 | m_bDataInColumns = bDataInColumns; |
194 | 0 | return bDataInColumns; |
195 | 0 | } |
196 | | |
197 | | virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess ) override |
198 | 0 | { |
199 | 0 | if( xDataAccess.is() ) |
200 | 0 | { |
201 | 0 | xDataAccess->setRowDescriptions( m_rRowDescriptions ); |
202 | 0 | if( m_bDataInColumns ) |
203 | 0 | DiagramHelper::switchToTextCategories( m_xChartDoc ); |
204 | 0 | } |
205 | 0 | } |
206 | | |
207 | | const Sequence< OUString >& m_rRowDescriptions; |
208 | | rtl::Reference<::chart::ChartModel> m_xChartDoc; |
209 | | bool m_bDataInColumns; |
210 | | }; |
211 | | |
212 | | struct lcl_ComplexRowDescriptionsOperator : public lcl_Operator |
213 | | { |
214 | | lcl_ComplexRowDescriptionsOperator( const Sequence< Sequence< OUString > >& rComplexRowDescriptions |
215 | | , rtl::Reference<::chart::ChartModel> xChartDoc ) |
216 | 0 | : m_rComplexRowDescriptions( rComplexRowDescriptions ) |
217 | 0 | , m_xChartDoc(std::move(xChartDoc)) |
218 | 0 | , m_bDataInColumns(true) |
219 | 0 | { |
220 | 0 | } |
221 | | |
222 | | virtual bool setsCategories( bool bDataInColumns ) override |
223 | 0 | { |
224 | 0 | m_bDataInColumns = bDataInColumns; |
225 | 0 | return bDataInColumns; |
226 | 0 | } |
227 | | |
228 | | virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess ) override |
229 | 0 | { |
230 | 0 | if( xDataAccess.is() ) |
231 | 0 | { |
232 | 0 | xDataAccess->setComplexRowDescriptions( m_rComplexRowDescriptions ); |
233 | 0 | if( m_bDataInColumns ) |
234 | 0 | DiagramHelper::switchToTextCategories( m_xChartDoc ); |
235 | 0 | } |
236 | 0 | } |
237 | | |
238 | | const Sequence< Sequence< OUString > >& m_rComplexRowDescriptions; |
239 | | rtl::Reference<::chart::ChartModel> m_xChartDoc; |
240 | | bool m_bDataInColumns; |
241 | | }; |
242 | | |
243 | | struct lcl_AnyRowDescriptionsOperator : public lcl_Operator |
244 | | { |
245 | | explicit lcl_AnyRowDescriptionsOperator( const Sequence< Sequence< uno::Any > >& rAnyRowDescriptions ) |
246 | 0 | : m_rAnyRowDescriptions( rAnyRowDescriptions ) |
247 | 0 | { |
248 | 0 | } |
249 | | |
250 | | virtual bool setsCategories( bool bDataInColumns ) override |
251 | 0 | { |
252 | 0 | return bDataInColumns; |
253 | 0 | } |
254 | | |
255 | | virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess ) override |
256 | 0 | { |
257 | 0 | if( xDataAccess.is() ) |
258 | 0 | xDataAccess->setAnyRowDescriptions( m_rAnyRowDescriptions ); |
259 | 0 | } |
260 | | |
261 | | const Sequence< Sequence< uno::Any > >& m_rAnyRowDescriptions; |
262 | | }; |
263 | | |
264 | | struct lcl_ColumnDescriptionsOperator : public lcl_Operator |
265 | | { |
266 | | lcl_ColumnDescriptionsOperator( const Sequence< OUString >& rColumnDescriptions |
267 | | , rtl::Reference<::chart::ChartModel> xChartDoc ) |
268 | 0 | : m_rColumnDescriptions( rColumnDescriptions ) |
269 | 0 | , m_xChartDoc(std::move(xChartDoc)) |
270 | 0 | , m_bDataInColumns(true) |
271 | 0 | { |
272 | 0 | } |
273 | | |
274 | | virtual bool setsCategories( bool bDataInColumns ) override |
275 | 0 | { |
276 | 0 | m_bDataInColumns = bDataInColumns; |
277 | 0 | return !bDataInColumns; |
278 | 0 | } |
279 | | |
280 | | virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess ) override |
281 | 0 | { |
282 | 0 | if( xDataAccess.is() ) |
283 | 0 | { |
284 | 0 | xDataAccess->setColumnDescriptions( m_rColumnDescriptions ); |
285 | 0 | if( !m_bDataInColumns ) |
286 | 0 | DiagramHelper::switchToTextCategories( m_xChartDoc ); |
287 | 0 | } |
288 | 0 | } |
289 | | |
290 | | const Sequence< OUString >& m_rColumnDescriptions; |
291 | | rtl::Reference<::chart::ChartModel> m_xChartDoc; |
292 | | bool m_bDataInColumns; |
293 | | }; |
294 | | |
295 | | struct lcl_ComplexColumnDescriptionsOperator : public lcl_Operator |
296 | | { |
297 | | lcl_ComplexColumnDescriptionsOperator( const Sequence< Sequence< OUString > >& rComplexColumnDescriptions |
298 | | , rtl::Reference<::chart::ChartModel> xChartDoc ) |
299 | 0 | : m_rComplexColumnDescriptions( rComplexColumnDescriptions ) |
300 | 0 | , m_xChartDoc(std::move(xChartDoc)) |
301 | 0 | , m_bDataInColumns(true) |
302 | 0 | { |
303 | 0 | } |
304 | | |
305 | | virtual bool setsCategories( bool bDataInColumns ) override |
306 | 0 | { |
307 | 0 | m_bDataInColumns = bDataInColumns; |
308 | 0 | return !bDataInColumns; |
309 | 0 | } |
310 | | |
311 | | virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess ) override |
312 | 0 | { |
313 | 0 | if( xDataAccess.is() ) |
314 | 0 | { |
315 | 0 | xDataAccess->setComplexColumnDescriptions( m_rComplexColumnDescriptions ); |
316 | 0 | if( !m_bDataInColumns ) |
317 | 0 | DiagramHelper::switchToTextCategories( m_xChartDoc ); |
318 | 0 | } |
319 | 0 | } |
320 | | |
321 | | const Sequence< Sequence< OUString > >& m_rComplexColumnDescriptions; |
322 | | rtl::Reference<::chart::ChartModel> m_xChartDoc; |
323 | | bool m_bDataInColumns; |
324 | | }; |
325 | | |
326 | | struct lcl_AnyColumnDescriptionsOperator : public lcl_Operator |
327 | | { |
328 | | explicit lcl_AnyColumnDescriptionsOperator( const Sequence< Sequence< uno::Any > >& rAnyColumnDescriptions ) |
329 | 0 | : m_rAnyColumnDescriptions( rAnyColumnDescriptions ) |
330 | 0 | { |
331 | 0 | } |
332 | | |
333 | | virtual bool setsCategories( bool bDataInColumns ) override |
334 | 0 | { |
335 | 0 | return bDataInColumns; |
336 | 0 | } |
337 | | |
338 | | virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess ) override |
339 | 0 | { |
340 | 0 | if( xDataAccess.is() ) |
341 | 0 | xDataAccess->setAnyColumnDescriptions( m_rAnyColumnDescriptions ); |
342 | 0 | } |
343 | | |
344 | | const Sequence< Sequence< uno::Any > >& m_rAnyColumnDescriptions; |
345 | | }; |
346 | | |
347 | | struct lcl_DateCategoriesOperator : public lcl_Operator |
348 | | { |
349 | | explicit lcl_DateCategoriesOperator( const Sequence< double >& rDates ) |
350 | 0 | : m_rDates( rDates ) |
351 | 0 | { |
352 | 0 | } |
353 | | |
354 | | virtual bool setsCategories( bool /*bDataInColumns*/ ) override |
355 | 0 | { |
356 | 0 | return true; |
357 | 0 | } |
358 | | |
359 | | virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess ) override |
360 | 0 | { |
361 | 0 | Reference< XDateCategories > xDateCategories( xDataAccess, uno::UNO_QUERY ); |
362 | 0 | if( xDateCategories.is() ) |
363 | 0 | xDateCategories->setDateCategories( m_rDates ); |
364 | 0 | } |
365 | | |
366 | | const Sequence< double >& m_rDates; |
367 | | }; |
368 | | |
369 | | } |
370 | | |
371 | | ChartDataWrapper::ChartDataWrapper(std::shared_ptr<Chart2ModelContact> spChart2ModelContact) |
372 | 0 | : m_spChart2ModelContact(std::move(spChart2ModelContact)) |
373 | 0 | { |
374 | 0 | osl_atomic_increment( &m_refCount ); |
375 | 0 | initDataAccess(); |
376 | 0 | osl_atomic_decrement( &m_refCount ); |
377 | 0 | } |
378 | | |
379 | | ChartDataWrapper::ChartDataWrapper( std::shared_ptr<Chart2ModelContact> spChart2ModelContact, |
380 | | const Reference< XChartData >& xNewData ) : |
381 | 0 | m_spChart2ModelContact(std::move( spChart2ModelContact )) |
382 | 0 | { |
383 | 0 | osl_atomic_increment( &m_refCount ); |
384 | 0 | lcl_AllOperator aOperator( xNewData ); |
385 | 0 | applyData( aOperator ); |
386 | 0 | osl_atomic_decrement( &m_refCount ); |
387 | 0 | } |
388 | | |
389 | | ChartDataWrapper::~ChartDataWrapper() |
390 | 0 | { |
391 | | // @todo: implement XComponent and call this in dispose(). In the DTOR the |
392 | | // ref-count is 0, thus creating a stack reference to this calls the DTOR at |
393 | | // the end of the block recursively |
394 | | // uno::Reference< uno::XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) ); |
395 | | // m_aEventListenerContainer.disposeAndClear( lang::EventObject( xSource ) ); |
396 | 0 | } |
397 | | |
398 | | // ____ XChartDataArray (read)____ |
399 | | Sequence< Sequence< double > > SAL_CALL ChartDataWrapper::getData() |
400 | 0 | { |
401 | 0 | initDataAccess(); |
402 | 0 | if( m_xDataAccess.is() ) |
403 | 0 | return lcl_getDBL_MINInsteadNAN( m_xDataAccess->getData() ); |
404 | 0 | return Sequence< Sequence< double > >(); |
405 | 0 | } |
406 | | Sequence< OUString > SAL_CALL ChartDataWrapper::getRowDescriptions() |
407 | 0 | { |
408 | 0 | initDataAccess(); |
409 | 0 | if( m_xDataAccess.is() ) |
410 | 0 | return m_xDataAccess->getRowDescriptions(); |
411 | 0 | return Sequence< OUString >(); |
412 | 0 | } |
413 | | Sequence< OUString > SAL_CALL ChartDataWrapper::getColumnDescriptions() |
414 | 0 | { |
415 | 0 | initDataAccess(); |
416 | 0 | if( m_xDataAccess.is() ) |
417 | 0 | return m_xDataAccess->getColumnDescriptions(); |
418 | 0 | return Sequence< OUString > (); |
419 | 0 | } |
420 | | |
421 | | // ____ XComplexDescriptionAccess (read) ____ |
422 | | Sequence< Sequence< OUString > > SAL_CALL ChartDataWrapper::getComplexRowDescriptions() |
423 | 0 | { |
424 | 0 | initDataAccess(); |
425 | 0 | if( m_xDataAccess.is() ) |
426 | 0 | return m_xDataAccess->getComplexRowDescriptions(); |
427 | 0 | return Sequence< Sequence< OUString > >(); |
428 | 0 | } |
429 | | Sequence< Sequence< OUString > > SAL_CALL ChartDataWrapper::getComplexColumnDescriptions() |
430 | 0 | { |
431 | 0 | initDataAccess(); |
432 | 0 | if( m_xDataAccess.is() ) |
433 | 0 | return m_xDataAccess->getComplexColumnDescriptions(); |
434 | 0 | return Sequence< Sequence< OUString > >(); |
435 | 0 | } |
436 | | |
437 | | // ____ XAnyDescriptionAccess (read) ____ |
438 | | Sequence< Sequence< uno::Any > > SAL_CALL ChartDataWrapper::getAnyRowDescriptions() |
439 | 0 | { |
440 | 0 | initDataAccess(); |
441 | 0 | if( m_xDataAccess.is() ) |
442 | 0 | return m_xDataAccess->getAnyRowDescriptions(); |
443 | 0 | return Sequence< Sequence< uno::Any > >(); |
444 | 0 | } |
445 | | Sequence< Sequence< uno::Any > > SAL_CALL ChartDataWrapper::getAnyColumnDescriptions() |
446 | 0 | { |
447 | 0 | initDataAccess(); |
448 | 0 | if( m_xDataAccess.is() ) |
449 | 0 | return m_xDataAccess->getAnyColumnDescriptions(); |
450 | 0 | return Sequence< Sequence< uno::Any > >(); |
451 | 0 | } |
452 | | |
453 | | // ____ XDateCategories (read) ____ |
454 | | Sequence< double > SAL_CALL ChartDataWrapper::getDateCategories() |
455 | 0 | { |
456 | 0 | initDataAccess(); |
457 | 0 | Reference< XDateCategories > xDateCategories( m_xDataAccess, uno::UNO_QUERY ); |
458 | 0 | if( xDateCategories.is() ) |
459 | 0 | return xDateCategories->getDateCategories(); |
460 | 0 | return Sequence< double >(); |
461 | 0 | } |
462 | | |
463 | | // ____ XChartDataArray (write)____ |
464 | | void SAL_CALL ChartDataWrapper::setData( const Sequence< Sequence< double > >& rData ) |
465 | 0 | { |
466 | 0 | lcl_DataOperator aOperator( rData ); |
467 | 0 | applyData( aOperator ); |
468 | 0 | } |
469 | | void SAL_CALL ChartDataWrapper::setRowDescriptions( const Sequence< OUString >& rRowDescriptions ) |
470 | 0 | { |
471 | 0 | lcl_RowDescriptionsOperator aOperator( rRowDescriptions, m_spChart2ModelContact->getDocumentModel() ); |
472 | 0 | applyData( aOperator ); |
473 | 0 | } |
474 | | void SAL_CALL ChartDataWrapper::setColumnDescriptions( const Sequence< OUString >& rColumnDescriptions ) |
475 | 0 | { |
476 | 0 | lcl_ColumnDescriptionsOperator aOperator( rColumnDescriptions, m_spChart2ModelContact->getDocumentModel() ); |
477 | 0 | applyData( aOperator ); |
478 | 0 | } |
479 | | |
480 | | // ____ XComplexDescriptionAccess (write) ____ |
481 | | void SAL_CALL ChartDataWrapper::setComplexRowDescriptions( const Sequence< Sequence< OUString > >& rRowDescriptions ) |
482 | 0 | { |
483 | 0 | lcl_ComplexRowDescriptionsOperator aOperator( rRowDescriptions, m_spChart2ModelContact->getDocumentModel() ); |
484 | 0 | applyData( aOperator ); |
485 | 0 | } |
486 | | void SAL_CALL ChartDataWrapper::setComplexColumnDescriptions( const Sequence< Sequence< OUString > >& rColumnDescriptions ) |
487 | 0 | { |
488 | 0 | lcl_ComplexColumnDescriptionsOperator aOperator( rColumnDescriptions, m_spChart2ModelContact->getDocumentModel() ); |
489 | 0 | applyData( aOperator ); |
490 | 0 | } |
491 | | |
492 | | // ____ XAnyDescriptionAccess (write) ____ |
493 | | void SAL_CALL ChartDataWrapper::setAnyRowDescriptions( const Sequence< Sequence< uno::Any > >& rRowDescriptions ) |
494 | 0 | { |
495 | 0 | lcl_AnyRowDescriptionsOperator aOperator( rRowDescriptions ); |
496 | 0 | applyData( aOperator ); |
497 | 0 | } |
498 | | void SAL_CALL ChartDataWrapper::setAnyColumnDescriptions( const Sequence< Sequence< uno::Any > >& rColumnDescriptions ) |
499 | 0 | { |
500 | 0 | lcl_AnyColumnDescriptionsOperator aOperator( rColumnDescriptions ); |
501 | 0 | applyData( aOperator ); |
502 | 0 | } |
503 | | |
504 | | // ____ XDateCategories (write) ____ |
505 | | void SAL_CALL ChartDataWrapper::setDateCategories( const Sequence< double >& rDates ) |
506 | 0 | { |
507 | 0 | rtl::Reference< ChartModel > xChartDoc( m_spChart2ModelContact->getDocumentModel() ); |
508 | 0 | ControllerLockGuardUNO aCtrlLockGuard( xChartDoc ); |
509 | 0 | lcl_DateCategoriesOperator aOperator( rDates ); |
510 | 0 | applyData( aOperator ); |
511 | 0 | DiagramHelper::switchToDateCategories( xChartDoc ); |
512 | 0 | } |
513 | | |
514 | | // ____ XChartData (base of XChartDataArray) ____ |
515 | | void SAL_CALL ChartDataWrapper::addChartDataChangeEventListener( |
516 | | const uno::Reference< css::chart::XChartDataChangeEventListener >& aListener ) |
517 | 0 | { |
518 | 0 | std::unique_lock g(m_aMutex); |
519 | 0 | m_aEventListenerContainer.addInterface( g, aListener ); |
520 | 0 | } |
521 | | |
522 | | void SAL_CALL ChartDataWrapper::removeChartDataChangeEventListener( |
523 | | const uno::Reference< css::chart::XChartDataChangeEventListener >& aListener ) |
524 | 0 | { |
525 | 0 | std::unique_lock g(m_aMutex); |
526 | 0 | m_aEventListenerContainer.removeInterface( g, aListener ); |
527 | 0 | } |
528 | | |
529 | | double SAL_CALL ChartDataWrapper::getNotANumber() |
530 | 0 | { |
531 | 0 | return DBL_MIN; |
532 | 0 | } |
533 | | |
534 | | sal_Bool SAL_CALL ChartDataWrapper::isNotANumber( double nNumber ) |
535 | 0 | { |
536 | 0 | return nNumber == DBL_MIN |
537 | 0 | || std::isnan( nNumber ) |
538 | 0 | || std::isinf( nNumber ); |
539 | 0 | } |
540 | | |
541 | | // ____ XComponent ____ |
542 | | void SAL_CALL ChartDataWrapper::dispose() |
543 | 0 | { |
544 | 0 | std::unique_lock g(m_aMutex); |
545 | 0 | m_aEventListenerContainer.disposeAndClear( g, lang::EventObject( static_cast< ::cppu::OWeakObject* >( this ))); |
546 | 0 | m_xDataAccess=nullptr; |
547 | 0 | } |
548 | | |
549 | | void SAL_CALL ChartDataWrapper::addEventListener( |
550 | | const uno::Reference< lang::XEventListener > & xListener ) |
551 | 0 | { |
552 | 0 | std::unique_lock g(m_aMutex); |
553 | 0 | m_aEventListenerContainer.addInterface( g, xListener ); |
554 | 0 | } |
555 | | |
556 | | void SAL_CALL ChartDataWrapper::removeEventListener( |
557 | | const uno::Reference< lang::XEventListener >& aListener ) |
558 | 0 | { |
559 | 0 | std::unique_lock g(m_aMutex); |
560 | 0 | m_aEventListenerContainer.removeInterface( g, aListener ); |
561 | 0 | } |
562 | | |
563 | | // ____ XEventListener ____ |
564 | | void SAL_CALL ChartDataWrapper::disposing( const lang::EventObject& /* Source */ ) |
565 | 0 | { |
566 | 0 | } |
567 | | |
568 | | void ChartDataWrapper::fireChartDataChangeEvent( css::chart::ChartDataChangeEvent& aEvent ) |
569 | 0 | { |
570 | 0 | std::unique_lock g(m_aMutex); |
571 | 0 | if( ! m_aEventListenerContainer.getLength(g) ) |
572 | 0 | return; |
573 | | |
574 | 0 | uno::Reference< uno::XInterface > xSrc( static_cast< cppu::OWeakObject* >( this )); |
575 | 0 | OSL_ASSERT( xSrc.is()); |
576 | 0 | if( xSrc.is() ) |
577 | 0 | aEvent.Source = std::move(xSrc); |
578 | |
|
579 | 0 | m_aEventListenerContainer.forEach( g, |
580 | 0 | [&aEvent](const uno::Reference<css::lang::XEventListener>& l) |
581 | 0 | { |
582 | 0 | uno::Reference<css::chart::XChartDataChangeEventListener> cl(l, uno::UNO_QUERY); |
583 | 0 | if (cl) |
584 | 0 | cl->chartDataChanged(aEvent); |
585 | 0 | }); |
586 | 0 | } |
587 | | |
588 | | void ChartDataWrapper::switchToInternalDataProvider() |
589 | 0 | { |
590 | | //create an internal data provider that is connected to the model |
591 | 0 | rtl::Reference< ChartModel > xChartDoc( m_spChart2ModelContact->getDocumentModel() ); |
592 | 0 | if( xChartDoc.is() ) |
593 | 0 | xChartDoc->createInternalDataProvider( true /*bCloneExistingData*/ ); |
594 | 0 | initDataAccess(); |
595 | 0 | } |
596 | | |
597 | | void ChartDataWrapper::initDataAccess() |
598 | 0 | { |
599 | 0 | rtl::Reference< ChartModel > xChartDoc( m_spChart2ModelContact->getDocumentModel() ); |
600 | 0 | if( !xChartDoc.is() ) |
601 | 0 | return; |
602 | 0 | if( xChartDoc->hasInternalDataProvider() ) |
603 | 0 | m_xDataAccess.set( xChartDoc->getDataProvider(), uno::UNO_QUERY_THROW ); |
604 | 0 | else |
605 | 0 | { |
606 | | //create a separate "internal data provider" that is not connected to the model |
607 | 0 | rtl::Reference<InternalDataProvider> xInternal |
608 | 0 | = new InternalDataProvider( xChartDoc, /*bConnectToModel*/false, /*bDefaultDataInColumns*/ true ); |
609 | 0 | m_xDataAccess = xInternal; |
610 | 0 | } |
611 | 0 | } |
612 | | |
613 | | void ChartDataWrapper::applyData( lcl_Operator& rDataOperator ) |
614 | 0 | { |
615 | | //bool bSetValues, bool bSetRowDescriptions, bool bSetColumnDescriptions |
616 | 0 | rtl::Reference< ChartModel > xChartDoc( m_spChart2ModelContact->getDocumentModel() ); |
617 | 0 | if( !xChartDoc.is() ) |
618 | 0 | return; |
619 | | |
620 | | // remember some diagram properties to reset later |
621 | 0 | bool bStacked = false; |
622 | 0 | bool bPercent = false; |
623 | 0 | bool bDeep = false; |
624 | 0 | uno::Reference< css::chart::XChartDocument > xOldDoc( static_cast<cppu::OWeakObject*>(xChartDoc.get()), uno::UNO_QUERY ); |
625 | 0 | OSL_ASSERT( xOldDoc.is()); |
626 | 0 | uno::Reference< beans::XPropertySet > xDiaProp( xOldDoc->getDiagram(), uno::UNO_QUERY ); |
627 | 0 | if( xDiaProp.is()) |
628 | 0 | { |
629 | 0 | xDiaProp->getPropertyValue(u"Stacked"_ustr) >>= bStacked; |
630 | 0 | xDiaProp->getPropertyValue(u"Percent"_ustr) >>= bPercent; |
631 | 0 | xDiaProp->getPropertyValue(u"Deep"_ustr) >>= bDeep; |
632 | 0 | } |
633 | | |
634 | | //detect arguments for the new data source |
635 | 0 | OUString aRangeString; |
636 | 0 | bool bUseColumns = true; |
637 | 0 | bool bFirstCellAsLabel = true; |
638 | 0 | bool bHasCategories = true; |
639 | 0 | uno::Sequence< sal_Int32 > aSequenceMapping; |
640 | |
|
641 | 0 | (void)DataSourceHelper::detectRangeSegmentation( |
642 | 0 | xChartDoc, |
643 | 0 | aRangeString, aSequenceMapping, bUseColumns, bFirstCellAsLabel, bHasCategories ); |
644 | |
|
645 | 0 | if( !bHasCategories && rDataOperator.setsCategories( bUseColumns ) ) |
646 | 0 | bHasCategories = true; |
647 | |
|
648 | 0 | aRangeString = "all"; |
649 | 0 | uno::Sequence< beans::PropertyValue > aArguments( DataSourceHelper::createArguments( |
650 | 0 | aRangeString, aSequenceMapping, bUseColumns, bFirstCellAsLabel, bHasCategories ) ); |
651 | | |
652 | | // -- locked controllers |
653 | 0 | ControllerLockGuardUNO aCtrlLockGuard( xChartDoc ); |
654 | | |
655 | | // create and attach new data source |
656 | 0 | switchToInternalDataProvider(); |
657 | 0 | rDataOperator.apply(m_xDataAccess); |
658 | 0 | uno::Reference< chart2::data::XDataProvider > xDataProvider( xChartDoc->getDataProvider() ); |
659 | 0 | OSL_ASSERT( xDataProvider.is() ); |
660 | 0 | if( !xDataProvider.is() ) |
661 | 0 | return; |
662 | 0 | uno::Reference< chart2::data::XDataSource > xSource( xDataProvider->createDataSource( aArguments ) ); |
663 | |
|
664 | 0 | rtl::Reference< Diagram > xDia( xChartDoc->getFirstChartDiagram() ); |
665 | 0 | if( xDia.is() ) |
666 | 0 | xDia->setDiagramData( xSource, aArguments ); |
667 | | |
668 | | //correct stacking mode |
669 | 0 | if( bStacked || bPercent || bDeep ) |
670 | 0 | { |
671 | 0 | StackMode eStackMode = StackMode::YStacked; |
672 | 0 | if( bDeep ) |
673 | 0 | eStackMode = StackMode::ZStacked; |
674 | 0 | else if( bPercent ) |
675 | 0 | eStackMode = StackMode::YStackedPercent; |
676 | 0 | xDia->setStackMode( eStackMode ); |
677 | 0 | } |
678 | | |
679 | | // notify listeners |
680 | 0 | css::chart::ChartDataChangeEvent aEvent( |
681 | 0 | static_cast< ::cppu::OWeakObject* >( this ), |
682 | 0 | css::chart::ChartDataChangeType_ALL, 0, 0, 0, 0 ); |
683 | 0 | fireChartDataChangeEvent( aEvent ); |
684 | | // \-- locked controllers |
685 | 0 | } |
686 | | |
687 | | OUString SAL_CALL ChartDataWrapper::getImplementationName() |
688 | 0 | { |
689 | 0 | return u"com.sun.star.comp.chart.ChartData"_ustr; |
690 | 0 | } |
691 | | |
692 | | sal_Bool SAL_CALL ChartDataWrapper::supportsService( const OUString& rServiceName ) |
693 | 0 | { |
694 | 0 | return cppu::supportsService(this, rServiceName); |
695 | 0 | } |
696 | | |
697 | | css::uno::Sequence< OUString > SAL_CALL ChartDataWrapper::getSupportedServiceNames() |
698 | 0 | { |
699 | 0 | return { |
700 | 0 | u"com.sun.star.chart.ChartDataArray"_ustr, |
701 | 0 | u"com.sun.star.chart.ChartData"_ustr |
702 | 0 | }; |
703 | 0 | } |
704 | | |
705 | | rtl::Reference<ChartModel> ChartDataWrapper::getChartModel() const |
706 | 0 | { |
707 | 0 | return m_spChart2ModelContact->getDocumentModel(); |
708 | 0 | } |
709 | | |
710 | | } // namespace chart |
711 | | |
712 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |