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 "ChartDataWrapper.hxx"
22 #include "DiagramHelper.hxx"
23 #include "DataSourceHelper.hxx"
24 #include "servicenames_charttypes.hxx"
25 #include "ContainerHelper.hxx"
26 #include "CommonFunctors.hxx"
27 #include "ChartModelHelper.hxx"
28 #include "DataSeriesHelper.hxx"
29 #include "ControllerLockGuard.hxx"
30 #include "Chart2ModelContact.hxx"
31 #include <cppuhelper/supportsservice.hxx>
32 #include <com/sun/star/beans/PropertyAttribute.hpp>
33 #include <com/sun/star/chart2/XTitled.hpp>
34 #include <com/sun/star/chart2/data/XNumericalDataSequence.hpp>
35 #include <com/sun/star/chart2/data/XTextualDataSequence.hpp>
36 #include <com/sun/star/chart2/data/XDataSource.hpp>
37 #include <com/sun/star/chart2/XDataSeries.hpp>
38 #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
39 #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
40 #include <com/sun/star/chart2/XChartTypeContainer.hpp>
41 #include <com/sun/star/chart2/data/XDataReceiver.hpp>
42 #include <com/sun/star/chart/ChartDataRowSource.hpp>
43 #include <com/sun/star/chart/XChartDocument.hpp>
45 #include "CharacterProperties.hxx"
46 #include "LineProperties.hxx"
47 #include "FillProperties.hxx"
51 #include <rtl/math.hxx>
53 using namespace ::com::sun::star
;
54 using ::com::sun::star::uno::Reference
;
55 using ::com::sun::star::uno::Sequence
;
56 using ::osl::MutexGuard
;
57 using ::com::sun::star::chart2::XAnyDescriptionAccess
;
58 using ::com::sun::star::chart::XComplexDescriptionAccess
;
59 using ::com::sun::star::chart::XChartData
;
60 using ::com::sun::star::chart::XChartDataArray
;
61 using ::com::sun::star::chart::XDateCategories
;
65 static const char lcl_aServiceName
[] = "com.sun.star.comp.chart.ChartData";
67 uno::Sequence
< uno::Sequence
< double > > lcl_getNANInsteadDBL_MIN( const uno::Sequence
< uno::Sequence
< double > >& rData
)
69 uno::Sequence
< uno::Sequence
< double > > aRet
;
70 const sal_Int32 nOuterSize
= rData
.getLength();
71 aRet
.realloc( nOuterSize
);
72 for( sal_Int32 nOuter
=0; nOuter
<nOuterSize
; ++nOuter
)
74 sal_Int32 nInnerSize
= rData
[nOuter
].getLength();
75 aRet
[nOuter
].realloc( nInnerSize
);
76 for( sal_Int32 nInner
=0; nInner
<nInnerSize
; ++nInner
)
78 aRet
[nOuter
][nInner
] = rData
[nOuter
][nInner
];
79 double& rValue
= aRet
[nOuter
][nInner
];
80 if( rValue
== DBL_MIN
)
81 ::rtl::math::setNan( &rValue
);
87 uno::Sequence
< uno::Sequence
< double > > lcl_getDBL_MINInsteadNAN( const uno::Sequence
< uno::Sequence
< double > >& rData
)
89 uno::Sequence
< uno::Sequence
< double > > aRet
;
90 const sal_Int32 nOuterSize
= rData
.getLength();
91 aRet
.realloc( nOuterSize
);
92 for( sal_Int32 nOuter
=0; nOuter
<nOuterSize
; ++nOuter
)
94 sal_Int32 nInnerSize
= rData
[nOuter
].getLength();
95 aRet
[nOuter
].realloc( nInnerSize
);
96 for( sal_Int32 nInner
=0; nInner
<nInnerSize
; ++nInner
)
98 aRet
[nOuter
][nInner
] = rData
[nOuter
][nInner
];
99 double& rValue
= aRet
[nOuter
][nInner
];
100 if( ::rtl::math::isNan( rValue
) )
107 } // anonymous namespace
119 virtual ~lcl_Operator()
122 virtual void apply( const Reference
< XAnyDescriptionAccess
>& xDataAccess
) = 0;
124 virtual bool setsCategories( bool /*bDataInColumns*/ )
130 struct lcl_AllOperator
: public lcl_Operator
132 lcl_AllOperator( const Reference
< XChartData
>& xDataToApply
)
134 , m_xDataToApply( xDataToApply
)
138 virtual bool setsCategories( bool /*bDataInColumns*/ ) SAL_OVERRIDE
143 virtual void apply( const Reference
< XAnyDescriptionAccess
>& xDataAccess
) SAL_OVERRIDE
145 if( !xDataAccess
.is() )
148 Reference
< XAnyDescriptionAccess
> xNewAny( m_xDataToApply
, uno::UNO_QUERY
);
149 Reference
< XComplexDescriptionAccess
> xNewComplex( m_xDataToApply
, uno::UNO_QUERY
);
152 xDataAccess
->setData( xNewAny
->getData() );
153 xDataAccess
->setComplexRowDescriptions( xNewAny
->getComplexRowDescriptions() );
154 xDataAccess
->setComplexColumnDescriptions( xNewAny
->getComplexColumnDescriptions() );
156 else if( xNewComplex
.is() )
158 xDataAccess
->setData( xNewComplex
->getData() );
159 xDataAccess
->setComplexRowDescriptions( xNewComplex
->getComplexRowDescriptions() );
160 xDataAccess
->setComplexColumnDescriptions( xNewComplex
->getComplexColumnDescriptions() );
164 Reference
< XChartDataArray
> xNew( m_xDataToApply
, uno::UNO_QUERY
);
167 xDataAccess
->setData( xNew
->getData() );
168 xDataAccess
->setRowDescriptions( xNew
->getRowDescriptions() );
169 xDataAccess
->setColumnDescriptions( xNew
->getColumnDescriptions() );
174 Reference
< XChartData
> m_xDataToApply
;
177 struct lcl_DataOperator
: public lcl_Operator
179 lcl_DataOperator( const Sequence
< Sequence
< double > >& rData
)
185 virtual void apply( const Reference
< XAnyDescriptionAccess
>& xDataAccess
) SAL_OVERRIDE
187 if( xDataAccess
.is() )
188 xDataAccess
->setData( lcl_getNANInsteadDBL_MIN( m_rData
) );
191 const Sequence
< Sequence
< double > >& m_rData
;
194 struct lcl_RowDescriptionsOperator
: public lcl_Operator
196 lcl_RowDescriptionsOperator( const Sequence
< OUString
>& rRowDescriptions
197 , const Reference
< chart2::XChartDocument
>& xChartDoc
)
199 , m_rRowDescriptions( rRowDescriptions
)
200 , m_xChartDoc(xChartDoc
)
201 , m_bDataInColumns(true)
205 virtual bool setsCategories( bool bDataInColumns
) SAL_OVERRIDE
207 m_bDataInColumns
= bDataInColumns
;
208 return bDataInColumns
;
211 virtual void apply( const Reference
< XAnyDescriptionAccess
>& xDataAccess
) SAL_OVERRIDE
213 if( xDataAccess
.is() )
215 xDataAccess
->setRowDescriptions( m_rRowDescriptions
);
216 if( m_bDataInColumns
)
217 DiagramHelper::switchToTextCategories( m_xChartDoc
);
221 const Sequence
< OUString
>& m_rRowDescriptions
;
222 Reference
< chart2::XChartDocument
> m_xChartDoc
;
223 bool m_bDataInColumns
;
226 struct lcl_ComplexRowDescriptionsOperator
: public lcl_Operator
228 lcl_ComplexRowDescriptionsOperator( const Sequence
< Sequence
< OUString
> >& rComplexRowDescriptions
229 , const Reference
< chart2::XChartDocument
>& xChartDoc
)
231 , m_rComplexRowDescriptions( rComplexRowDescriptions
)
232 , m_xChartDoc(xChartDoc
)
233 , m_bDataInColumns(true)
237 virtual bool setsCategories( bool bDataInColumns
) SAL_OVERRIDE
239 m_bDataInColumns
= bDataInColumns
;
240 return bDataInColumns
;
243 virtual void apply( const Reference
< XAnyDescriptionAccess
>& xDataAccess
) SAL_OVERRIDE
245 if( xDataAccess
.is() )
247 xDataAccess
->setComplexRowDescriptions( m_rComplexRowDescriptions
);
248 if( m_bDataInColumns
)
249 DiagramHelper::switchToTextCategories( m_xChartDoc
);
253 const Sequence
< Sequence
< OUString
> >& m_rComplexRowDescriptions
;
254 Reference
< chart2::XChartDocument
> m_xChartDoc
;
255 bool m_bDataInColumns
;
258 struct lcl_AnyRowDescriptionsOperator
: public lcl_Operator
260 lcl_AnyRowDescriptionsOperator( const Sequence
< Sequence
< uno::Any
> >& rAnyRowDescriptions
)
262 , m_rAnyRowDescriptions( rAnyRowDescriptions
)
266 virtual bool setsCategories( bool bDataInColumns
) SAL_OVERRIDE
268 return bDataInColumns
;
271 virtual void apply( const Reference
< XAnyDescriptionAccess
>& xDataAccess
) SAL_OVERRIDE
273 if( xDataAccess
.is() )
274 xDataAccess
->setAnyRowDescriptions( m_rAnyRowDescriptions
);
277 const Sequence
< Sequence
< uno::Any
> >& m_rAnyRowDescriptions
;
280 struct lcl_ColumnDescriptionsOperator
: public lcl_Operator
282 lcl_ColumnDescriptionsOperator( const Sequence
< OUString
>& rColumnDescriptions
283 , const Reference
< chart2::XChartDocument
>& xChartDoc
)
285 , m_rColumnDescriptions( rColumnDescriptions
)
286 , m_xChartDoc(xChartDoc
)
287 , m_bDataInColumns(true)
291 virtual bool setsCategories( bool bDataInColumns
) SAL_OVERRIDE
293 m_bDataInColumns
= bDataInColumns
;
294 return !bDataInColumns
;
297 virtual void apply( const Reference
< XAnyDescriptionAccess
>& xDataAccess
) SAL_OVERRIDE
299 if( xDataAccess
.is() )
301 xDataAccess
->setColumnDescriptions( m_rColumnDescriptions
);
302 if( !m_bDataInColumns
)
303 DiagramHelper::switchToTextCategories( m_xChartDoc
);
307 const Sequence
< OUString
>& m_rColumnDescriptions
;
308 Reference
< chart2::XChartDocument
> m_xChartDoc
;
309 bool m_bDataInColumns
;
312 struct lcl_ComplexColumnDescriptionsOperator
: public lcl_Operator
314 lcl_ComplexColumnDescriptionsOperator( const Sequence
< Sequence
< OUString
> >& rComplexColumnDescriptions
315 , const Reference
< chart2::XChartDocument
>& xChartDoc
)
317 , m_rComplexColumnDescriptions( rComplexColumnDescriptions
)
318 , m_xChartDoc(xChartDoc
)
319 , m_bDataInColumns(true)
323 virtual bool setsCategories( bool bDataInColumns
) SAL_OVERRIDE
325 m_bDataInColumns
= bDataInColumns
;
326 return !bDataInColumns
;
329 virtual void apply( const Reference
< XAnyDescriptionAccess
>& xDataAccess
) SAL_OVERRIDE
331 if( xDataAccess
.is() )
333 xDataAccess
->setComplexColumnDescriptions( m_rComplexColumnDescriptions
);
334 if( !m_bDataInColumns
)
335 DiagramHelper::switchToTextCategories( m_xChartDoc
);
339 const Sequence
< Sequence
< OUString
> >& m_rComplexColumnDescriptions
;
340 Reference
< chart2::XChartDocument
> m_xChartDoc
;
341 bool m_bDataInColumns
;
344 struct lcl_AnyColumnDescriptionsOperator
: public lcl_Operator
346 lcl_AnyColumnDescriptionsOperator( const Sequence
< Sequence
< uno::Any
> >& rAnyColumnDescriptions
)
348 , m_rAnyColumnDescriptions( rAnyColumnDescriptions
)
352 virtual bool setsCategories( bool bDataInColumns
) SAL_OVERRIDE
354 return bDataInColumns
;
357 virtual void apply( const Reference
< XAnyDescriptionAccess
>& xDataAccess
) SAL_OVERRIDE
359 if( xDataAccess
.is() )
360 xDataAccess
->setAnyColumnDescriptions( m_rAnyColumnDescriptions
);
363 const Sequence
< Sequence
< uno::Any
> >& m_rAnyColumnDescriptions
;
366 struct lcl_DateCategoriesOperator
: public lcl_Operator
368 lcl_DateCategoriesOperator( const Sequence
< double >& rDates
)
374 virtual bool setsCategories( bool /*bDataInColumns*/ ) SAL_OVERRIDE
379 virtual void apply( const Reference
< XAnyDescriptionAccess
>& xDataAccess
) SAL_OVERRIDE
381 Reference
< XDateCategories
> xDateCategories( xDataAccess
, uno::UNO_QUERY
);
382 if( xDateCategories
.is() )
383 xDateCategories
->setDateCategories( m_rDates
);
386 const Sequence
< double >& m_rDates
;
389 ChartDataWrapper::ChartDataWrapper( ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
) :
390 m_spChart2ModelContact( spChart2ModelContact
),
391 m_aEventListenerContainer( m_aMutex
)
393 osl_atomic_increment( &m_refCount
);
395 osl_atomic_decrement( &m_refCount
);
398 ChartDataWrapper::ChartDataWrapper( ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
,
399 const Reference
< XChartData
>& xNewData
) :
400 m_spChart2ModelContact( spChart2ModelContact
),
401 m_aEventListenerContainer( m_aMutex
)
403 osl_atomic_increment( &m_refCount
);
404 lcl_AllOperator
aOperator( xNewData
);
405 applyData( aOperator
);
406 osl_atomic_decrement( &m_refCount
);
409 ChartDataWrapper::~ChartDataWrapper()
411 // @todo: implement XComponent and call this in dispose(). In the DTOR the
412 // ref-count is 0, thus creating a stack reference to this calls the DTOR at
413 // the end of the block recursively
414 // uno::Reference< uno::XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
415 // m_aEventListenerContainer.disposeAndClear( lang::EventObject( xSource ) );
418 // ____ XChartDataArray (read)____
419 Sequence
< Sequence
< double > > SAL_CALL
ChartDataWrapper::getData()
420 throw (uno::RuntimeException
, std::exception
)
423 if( m_xDataAccess
.is() )
424 return lcl_getDBL_MINInsteadNAN( m_xDataAccess
->getData() );
425 return Sequence
< Sequence
< double > >();
427 Sequence
< OUString
> SAL_CALL
ChartDataWrapper::getRowDescriptions()
428 throw (uno::RuntimeException
, std::exception
)
431 if( m_xDataAccess
.is() )
432 return m_xDataAccess
->getRowDescriptions();
433 return Sequence
< OUString
>();
435 Sequence
< OUString
> SAL_CALL
ChartDataWrapper::getColumnDescriptions()
436 throw (uno::RuntimeException
, std::exception
)
439 if( m_xDataAccess
.is() )
440 return m_xDataAccess
->getColumnDescriptions();
441 return Sequence
< OUString
> ();
444 // ____ XComplexDescriptionAccess (read) ____
445 Sequence
< Sequence
< OUString
> > SAL_CALL
ChartDataWrapper::getComplexRowDescriptions() throw (uno::RuntimeException
, std::exception
)
448 if( m_xDataAccess
.is() )
449 return m_xDataAccess
->getComplexRowDescriptions();
450 return Sequence
< Sequence
< OUString
> >();
452 Sequence
< Sequence
< OUString
> > SAL_CALL
ChartDataWrapper::getComplexColumnDescriptions() throw (uno::RuntimeException
, std::exception
)
455 if( m_xDataAccess
.is() )
456 return m_xDataAccess
->getComplexColumnDescriptions();
457 return Sequence
< Sequence
< OUString
> >();
460 // ____ XAnyDescriptionAccess (read) ____
461 Sequence
< Sequence
< uno::Any
> > SAL_CALL
ChartDataWrapper::getAnyRowDescriptions() throw (uno::RuntimeException
, std::exception
)
464 if( m_xDataAccess
.is() )
465 return m_xDataAccess
->getAnyRowDescriptions();
466 return Sequence
< Sequence
< uno::Any
> >();
468 Sequence
< Sequence
< uno::Any
> > SAL_CALL
ChartDataWrapper::getAnyColumnDescriptions() throw (uno::RuntimeException
, std::exception
)
471 if( m_xDataAccess
.is() )
472 return m_xDataAccess
->getAnyColumnDescriptions();
473 return Sequence
< Sequence
< uno::Any
> >();
476 // ____ XDateCategories (read) ____
477 Sequence
< double > SAL_CALL
ChartDataWrapper::getDateCategories() throw (uno::RuntimeException
, std::exception
)
480 Reference
< XDateCategories
> xDateCategories( m_xDataAccess
, uno::UNO_QUERY
);
481 if( xDateCategories
.is() )
482 return xDateCategories
->getDateCategories();
483 return Sequence
< double >();
486 // ____ XChartDataArray (write)____
487 void SAL_CALL
ChartDataWrapper::setData( const Sequence
< Sequence
< double > >& rData
)
488 throw (uno::RuntimeException
, std::exception
)
490 lcl_DataOperator
aOperator( rData
);
491 applyData( aOperator
);
493 void SAL_CALL
ChartDataWrapper::setRowDescriptions( const Sequence
< OUString
>& rRowDescriptions
)
494 throw (uno::RuntimeException
, std::exception
)
496 lcl_RowDescriptionsOperator
aOperator( rRowDescriptions
, m_spChart2ModelContact
->getChart2Document() );
497 applyData( aOperator
);
499 void SAL_CALL
ChartDataWrapper::setColumnDescriptions( const Sequence
< OUString
>& rColumnDescriptions
)
500 throw (uno::RuntimeException
, std::exception
)
502 lcl_ColumnDescriptionsOperator
aOperator( rColumnDescriptions
, m_spChart2ModelContact
->getChart2Document() );
503 applyData( aOperator
);
506 // ____ XComplexDescriptionAccess (write) ____
507 void SAL_CALL
ChartDataWrapper::setComplexRowDescriptions( const Sequence
< Sequence
< OUString
> >& rRowDescriptions
) throw (uno::RuntimeException
, std::exception
)
509 lcl_ComplexRowDescriptionsOperator
aOperator( rRowDescriptions
, m_spChart2ModelContact
->getChart2Document() );
510 applyData( aOperator
);
512 void SAL_CALL
ChartDataWrapper::setComplexColumnDescriptions( const Sequence
< Sequence
< OUString
> >& rColumnDescriptions
) throw (uno::RuntimeException
, std::exception
)
514 lcl_ComplexColumnDescriptionsOperator
aOperator( rColumnDescriptions
, m_spChart2ModelContact
->getChart2Document() );
515 applyData( aOperator
);
518 // ____ XAnyDescriptionAccess (write) ____
519 void SAL_CALL
ChartDataWrapper::setAnyRowDescriptions( const Sequence
< Sequence
< uno::Any
> >& rRowDescriptions
) throw (uno::RuntimeException
, std::exception
)
521 lcl_AnyRowDescriptionsOperator
aOperator( rRowDescriptions
);
522 applyData( aOperator
);
524 void SAL_CALL
ChartDataWrapper::setAnyColumnDescriptions( const Sequence
< Sequence
< uno::Any
> >& rColumnDescriptions
) throw (uno::RuntimeException
, std::exception
)
526 lcl_AnyColumnDescriptionsOperator
aOperator( rColumnDescriptions
);
527 applyData( aOperator
);
530 // ____ XDateCategories (write) ____
531 void SAL_CALL
ChartDataWrapper::setDateCategories( const Sequence
< double >& rDates
) throw (uno::RuntimeException
, std::exception
)
533 Reference
< chart2::XChartDocument
> xChartDoc( m_spChart2ModelContact
->getChart2Document() );
534 ControllerLockGuardUNO
aCtrlLockGuard( uno::Reference
< frame::XModel
>( xChartDoc
, uno::UNO_QUERY
));
535 lcl_DateCategoriesOperator
aOperator( rDates
);
536 applyData( aOperator
);
537 DiagramHelper::switchToDateCategories( xChartDoc
);
540 // ____ XChartData (base of XChartDataArray) ____
541 void SAL_CALL
ChartDataWrapper::addChartDataChangeEventListener(
542 const uno::Reference
<
543 ::com::sun::star::chart::XChartDataChangeEventListener
>& aListener
)
544 throw (uno::RuntimeException
, std::exception
)
546 m_aEventListenerContainer
.addInterface( aListener
);
549 void SAL_CALL
ChartDataWrapper::removeChartDataChangeEventListener(
550 const uno::Reference
<
551 ::com::sun::star::chart::XChartDataChangeEventListener
>& aListener
)
552 throw (uno::RuntimeException
, std::exception
)
554 m_aEventListenerContainer
.removeInterface( aListener
);
557 double SAL_CALL
ChartDataWrapper::getNotANumber()
558 throw (uno::RuntimeException
, std::exception
)
563 sal_Bool SAL_CALL
ChartDataWrapper::isNotANumber( double nNumber
)
564 throw (uno::RuntimeException
, std::exception
)
566 return DBL_MIN
== nNumber
567 || ::rtl::math::isNan( nNumber
)
568 || ::rtl::math::isInf( nNumber
);
571 // ____ XComponent ____
572 void SAL_CALL
ChartDataWrapper::dispose()
573 throw (uno::RuntimeException
, std::exception
)
575 m_aEventListenerContainer
.disposeAndClear( lang::EventObject( static_cast< ::cppu::OWeakObject
* >( this )));
579 void SAL_CALL
ChartDataWrapper::addEventListener(
580 const uno::Reference
< lang::XEventListener
> & xListener
)
581 throw (uno::RuntimeException
, std::exception
)
583 m_aEventListenerContainer
.addInterface( xListener
);
586 void SAL_CALL
ChartDataWrapper::removeEventListener(
587 const uno::Reference
< lang::XEventListener
>& aListener
)
588 throw (uno::RuntimeException
, std::exception
)
590 m_aEventListenerContainer
.removeInterface( aListener
);
593 // ____ XEventListener ____
594 void SAL_CALL
ChartDataWrapper::disposing( const lang::EventObject
& /* Source */ )
595 throw (uno::RuntimeException
, std::exception
)
599 void ChartDataWrapper::fireChartDataChangeEvent(
600 ::com::sun::star::chart::ChartDataChangeEvent
& aEvent
)
602 if( ! m_aEventListenerContainer
.getLength() )
605 uno::Reference
< uno::XInterface
> xSrc( static_cast< cppu::OWeakObject
* >( this ));
606 OSL_ASSERT( xSrc
.is());
608 aEvent
.Source
= xSrc
;
610 ::cppu::OInterfaceIteratorHelper
aIter( m_aEventListenerContainer
);
612 while( aIter
.hasMoreElements() )
615 ::com::sun::star::chart::XChartDataChangeEventListener
> xListener(
616 aIter
.next(), uno::UNO_QUERY
);
618 xListener
->chartDataChanged( aEvent
);
622 void ChartDataWrapper::switchToInternalDataProvider()
624 //create an internal data provider that is connected to the model
625 Reference
< chart2::XChartDocument
> xChartDoc( m_spChart2ModelContact
->getChart2Document() );
627 xChartDoc
->createInternalDataProvider( true /*bCloneExistingData*/ );
631 void ChartDataWrapper::initDataAccess()
633 Reference
< chart2::XChartDocument
> xChartDoc( m_spChart2ModelContact
->getChart2Document() );
634 if( !xChartDoc
.is() )
636 if( xChartDoc
->hasInternalDataProvider() )
637 m_xDataAccess
= Reference
< XAnyDescriptionAccess
>( xChartDoc
->getDataProvider(), uno::UNO_QUERY_THROW
);
640 //create a separate "internal data provider" that is not connected to the model
641 m_xDataAccess
= Reference
< XAnyDescriptionAccess
>( ChartModelHelper::createInternalDataProvider(
642 xChartDoc
, false /*bConnectToModel*/ ), uno::UNO_QUERY_THROW
);
646 void ChartDataWrapper::applyData( lcl_Operator
& rDataOperator
)
648 //bool bSetValues, bool bSetRowDescriptions, bool bSetColumnDescriptions
649 Reference
< chart2::XChartDocument
> xChartDoc( m_spChart2ModelContact
->getChart2Document() );
650 if( !xChartDoc
.is() )
653 // remember some diagram properties to reset later
654 bool bStacked
= false;
655 bool bPercent
= false;
657 uno::Reference
< ::com::sun::star::chart::XChartDocument
> xOldDoc( xChartDoc
, uno::UNO_QUERY
);
658 OSL_ASSERT( xOldDoc
.is());
659 uno::Reference
< beans::XPropertySet
> xDiaProp( xOldDoc
->getDiagram(), uno::UNO_QUERY
);
662 xDiaProp
->getPropertyValue("Stacked") >>= bStacked
;
663 xDiaProp
->getPropertyValue("Percent") >>= bPercent
;
664 xDiaProp
->getPropertyValue("Deep") >>= bDeep
;
667 //detect arguments for the new data source
668 OUString aRangeString
;
669 bool bUseColumns
= true;
670 bool bFirstCellAsLabel
= true;
671 bool bHasCategories
= true;
672 uno::Sequence
< sal_Int32
> aSequenceMapping
;
674 DataSourceHelper::detectRangeSegmentation(
675 uno::Reference
< frame::XModel
>( xChartDoc
, uno::UNO_QUERY
),
676 aRangeString
, aSequenceMapping
, bUseColumns
, bFirstCellAsLabel
, bHasCategories
);
678 if( !bHasCategories
&& rDataOperator
.setsCategories( bUseColumns
) )
679 bHasCategories
= true;
681 aRangeString
= "all";
682 uno::Sequence
< beans::PropertyValue
> aArguments( DataSourceHelper::createArguments(
683 aRangeString
, aSequenceMapping
, bUseColumns
, bFirstCellAsLabel
, bHasCategories
) );
685 // /-- locked controllers
686 ControllerLockGuardUNO
aCtrlLockGuard( uno::Reference
< frame::XModel
>( xChartDoc
, uno::UNO_QUERY
));
688 // create and attach new data source
689 switchToInternalDataProvider();
690 rDataOperator
.apply(m_xDataAccess
);
691 uno::Reference
< chart2::data::XDataProvider
> xDataProvider( xChartDoc
->getDataProvider() );
692 OSL_ASSERT( xDataProvider
.is() );
693 if( !xDataProvider
.is() )
695 uno::Reference
< chart2::data::XDataSource
> xSource( xDataProvider
->createDataSource( aArguments
) );
697 uno::Reference
< chart2::XDiagram
> xDia( xChartDoc
->getFirstDiagram() );
699 xDia
->setDiagramData( xSource
, aArguments
);
701 //correct stacking mode
702 if( bStacked
|| bPercent
|| bDeep
)
704 StackMode eStackMode
= StackMode_Y_STACKED
;
706 eStackMode
= StackMode_Z_STACKED
;
708 eStackMode
= StackMode_Y_STACKED_PERCENT
;
709 DiagramHelper::setStackMode( xDia
, eStackMode
);
713 ::com::sun::star::chart::ChartDataChangeEvent
aEvent(
714 static_cast< ::cppu::OWeakObject
* >( this ),
715 ::com::sun::star::chart::ChartDataChangeType_ALL
, 0, 0, 0, 0 );
716 fireChartDataChangeEvent( aEvent
);
717 // \-- locked controllers
720 uno::Sequence
< OUString
> ChartDataWrapper::getSupportedServiceNames_Static()
722 uno::Sequence
< OUString
> aServices( 2 );
723 aServices
[ 0 ] = "com.sun.star.chart.ChartDataArray";
724 aServices
[ 1 ] = "com.sun.star.chart.ChartData";
729 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
730 OUString SAL_CALL
ChartDataWrapper::getImplementationName()
731 throw( css::uno::RuntimeException
, std::exception
)
733 return getImplementationName_Static();
736 OUString
ChartDataWrapper::getImplementationName_Static()
738 return OUString(lcl_aServiceName
);
741 sal_Bool SAL_CALL
ChartDataWrapper::supportsService( const OUString
& rServiceName
)
742 throw( css::uno::RuntimeException
, std::exception
)
744 return cppu::supportsService(this, rServiceName
);
747 css::uno::Sequence
< OUString
> SAL_CALL
ChartDataWrapper::getSupportedServiceNames()
748 throw( css::uno::RuntimeException
, std::exception
)
750 return getSupportedServiceNames_Static();
753 } // namespace wrapper
756 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */