1*cde9e8dcSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*cde9e8dcSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*cde9e8dcSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*cde9e8dcSAndrew Rist * distributed with this work for additional information
6*cde9e8dcSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*cde9e8dcSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*cde9e8dcSAndrew Rist * "License"); you may not use this file except in compliance
9*cde9e8dcSAndrew Rist * with the License. You may obtain a copy of the License at
10*cde9e8dcSAndrew Rist *
11*cde9e8dcSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*cde9e8dcSAndrew Rist *
13*cde9e8dcSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*cde9e8dcSAndrew Rist * software distributed under the License is distributed on an
15*cde9e8dcSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*cde9e8dcSAndrew Rist * KIND, either express or implied. See the License for the
17*cde9e8dcSAndrew Rist * specific language governing permissions and limitations
18*cde9e8dcSAndrew Rist * under the License.
19*cde9e8dcSAndrew Rist *
20*cde9e8dcSAndrew Rist *************************************************************/
21*cde9e8dcSAndrew Rist
22*cde9e8dcSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_chart2.hxx"
26cdf0e10cSrcweir #include "DataSeries.hxx"
27cdf0e10cSrcweir #include "DataSeriesProperties.hxx"
28cdf0e10cSrcweir #include "DataPointProperties.hxx"
29cdf0e10cSrcweir #include "CharacterProperties.hxx"
30cdf0e10cSrcweir #include "UserDefinedProperties.hxx"
31cdf0e10cSrcweir #include "DataPoint.hxx"
32cdf0e10cSrcweir #include "macros.hxx"
33cdf0e10cSrcweir #include "DataSeriesHelper.hxx"
34cdf0e10cSrcweir #include "ContainerHelper.hxx"
35cdf0e10cSrcweir #include "CloneHelper.hxx"
36cdf0e10cSrcweir #include "ModifyListenerHelper.hxx"
37cdf0e10cSrcweir #include "EventListenerHelper.hxx"
38cdf0e10cSrcweir
39cdf0e10cSrcweir #include <algorithm>
40cdf0e10cSrcweir
41cdf0e10cSrcweir using namespace ::com::sun::star;
42cdf0e10cSrcweir
43cdf0e10cSrcweir using ::com::sun::star::beans::Property;
44cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
45cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
46cdf0e10cSrcweir using ::com::sun::star::uno::Any;
47cdf0e10cSrcweir using ::rtl::OUString;
48cdf0e10cSrcweir using ::osl::MutexGuard;
49cdf0e10cSrcweir
50cdf0e10cSrcweir // ----------------------------------------
51cdf0e10cSrcweir
52cdf0e10cSrcweir namespace
53cdf0e10cSrcweir {
54cdf0e10cSrcweir
55cdf0e10cSrcweir struct StaticDataSeriesDefaults_Initializer
56cdf0e10cSrcweir {
operator ()__anon6cb3ece40111::StaticDataSeriesDefaults_Initializer57cdf0e10cSrcweir ::chart::tPropertyValueMap* operator()()
58cdf0e10cSrcweir {
59cdf0e10cSrcweir static ::chart::tPropertyValueMap aStaticDefaults;
60cdf0e10cSrcweir lcl_AddDefaultsToMap( aStaticDefaults );
61cdf0e10cSrcweir return &aStaticDefaults;
62cdf0e10cSrcweir }
63cdf0e10cSrcweir private:
lcl_AddDefaultsToMap__anon6cb3ece40111::StaticDataSeriesDefaults_Initializer64cdf0e10cSrcweir void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
65cdf0e10cSrcweir {
66cdf0e10cSrcweir ::chart::DataSeriesProperties::AddDefaultsToMap( rOutMap );
67cdf0e10cSrcweir ::chart::CharacterProperties::AddDefaultsToMap( rOutMap );
68cdf0e10cSrcweir
69cdf0e10cSrcweir float fDefaultCharHeight = 10.0;
70cdf0e10cSrcweir ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_CHAR_HEIGHT, fDefaultCharHeight );
71cdf0e10cSrcweir ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_ASIAN_CHAR_HEIGHT, fDefaultCharHeight );
72cdf0e10cSrcweir ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_COMPLEX_CHAR_HEIGHT, fDefaultCharHeight );
73cdf0e10cSrcweir }
74cdf0e10cSrcweir };
75cdf0e10cSrcweir
76cdf0e10cSrcweir struct StaticDataSeriesDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticDataSeriesDefaults_Initializer >
77cdf0e10cSrcweir {
78cdf0e10cSrcweir };
79cdf0e10cSrcweir
80cdf0e10cSrcweir struct StaticDataSeriesInfoHelper_Initializer
81cdf0e10cSrcweir {
operator ()__anon6cb3ece40111::StaticDataSeriesInfoHelper_Initializer82cdf0e10cSrcweir ::cppu::OPropertyArrayHelper* operator()()
83cdf0e10cSrcweir {
84cdf0e10cSrcweir static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
85cdf0e10cSrcweir return &aPropHelper;
86cdf0e10cSrcweir }
87cdf0e10cSrcweir
88cdf0e10cSrcweir private:
lcl_GetPropertySequence__anon6cb3ece40111::StaticDataSeriesInfoHelper_Initializer89cdf0e10cSrcweir uno::Sequence< Property > lcl_GetPropertySequence()
90cdf0e10cSrcweir {
91cdf0e10cSrcweir ::std::vector< ::com::sun::star::beans::Property > aProperties;
92cdf0e10cSrcweir ::chart::DataSeriesProperties::AddPropertiesToVector( aProperties );
93cdf0e10cSrcweir ::chart::CharacterProperties::AddPropertiesToVector( aProperties );
94cdf0e10cSrcweir ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
95cdf0e10cSrcweir
96cdf0e10cSrcweir ::std::sort( aProperties.begin(), aProperties.end(),
97cdf0e10cSrcweir ::chart::PropertyNameLess() );
98cdf0e10cSrcweir
99cdf0e10cSrcweir return ::chart::ContainerHelper::ContainerToSequence( aProperties );
100cdf0e10cSrcweir }
101cdf0e10cSrcweir
102cdf0e10cSrcweir };
103cdf0e10cSrcweir
104cdf0e10cSrcweir struct StaticDataSeriesInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticDataSeriesInfoHelper_Initializer >
105cdf0e10cSrcweir {
106cdf0e10cSrcweir };
107cdf0e10cSrcweir
108cdf0e10cSrcweir struct StaticDataSeriesInfo_Initializer
109cdf0e10cSrcweir {
operator ()__anon6cb3ece40111::StaticDataSeriesInfo_Initializer110cdf0e10cSrcweir uno::Reference< beans::XPropertySetInfo >* operator()()
111cdf0e10cSrcweir {
112cdf0e10cSrcweir static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
113cdf0e10cSrcweir ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticDataSeriesInfoHelper::get() ) );
114cdf0e10cSrcweir return &xPropertySetInfo;
115cdf0e10cSrcweir }
116cdf0e10cSrcweir };
117cdf0e10cSrcweir
118cdf0e10cSrcweir struct StaticDataSeriesInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticDataSeriesInfo_Initializer >
119cdf0e10cSrcweir {
120cdf0e10cSrcweir };
121cdf0e10cSrcweir
lcl_SetParent(const uno::Reference<uno::XInterface> & xChildInterface,const uno::Reference<uno::XInterface> & xParentInterface)122cdf0e10cSrcweir void lcl_SetParent(
123cdf0e10cSrcweir const uno::Reference< uno::XInterface > & xChildInterface,
124cdf0e10cSrcweir const uno::Reference< uno::XInterface > & xParentInterface )
125cdf0e10cSrcweir {
126cdf0e10cSrcweir uno::Reference< container::XChild > xChild( xChildInterface, uno::UNO_QUERY );
127cdf0e10cSrcweir if( xChild.is())
128cdf0e10cSrcweir xChild->setParent( xParentInterface );
129cdf0e10cSrcweir }
130cdf0e10cSrcweir
131cdf0e10cSrcweir typedef ::std::map< sal_Int32, ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > >
132cdf0e10cSrcweir lcl_tDataPointMap;
133cdf0e10cSrcweir
lcl_CloneAttributedDataPoints(const lcl_tDataPointMap & rSource,lcl_tDataPointMap & rDestination,const uno::Reference<uno::XInterface> & xSeries)134cdf0e10cSrcweir void lcl_CloneAttributedDataPoints(
135cdf0e10cSrcweir const lcl_tDataPointMap & rSource, lcl_tDataPointMap & rDestination,
136cdf0e10cSrcweir const uno::Reference< uno::XInterface > & xSeries )
137cdf0e10cSrcweir {
138cdf0e10cSrcweir for( lcl_tDataPointMap::const_iterator aIt( rSource.begin());
139cdf0e10cSrcweir aIt != rSource.end(); ++aIt )
140cdf0e10cSrcweir {
141cdf0e10cSrcweir Reference< beans::XPropertySet > xPoint( (*aIt).second );
142cdf0e10cSrcweir if( xPoint.is())
143cdf0e10cSrcweir {
144cdf0e10cSrcweir Reference< util::XCloneable > xCloneable( xPoint, uno::UNO_QUERY );
145cdf0e10cSrcweir if( xCloneable.is())
146cdf0e10cSrcweir {
147cdf0e10cSrcweir xPoint.set( xCloneable->createClone(), uno::UNO_QUERY );
148cdf0e10cSrcweir if( xPoint.is())
149cdf0e10cSrcweir {
150cdf0e10cSrcweir lcl_SetParent( xPoint, xSeries );
151cdf0e10cSrcweir rDestination.insert( lcl_tDataPointMap::value_type( (*aIt).first, xPoint ));
152cdf0e10cSrcweir }
153cdf0e10cSrcweir }
154cdf0e10cSrcweir }
155cdf0e10cSrcweir }
156cdf0e10cSrcweir }
157cdf0e10cSrcweir
158cdf0e10cSrcweir } // anonymous namespace
159cdf0e10cSrcweir
160cdf0e10cSrcweir // ----------------------------------------
161cdf0e10cSrcweir
162cdf0e10cSrcweir namespace chart
163cdf0e10cSrcweir {
164cdf0e10cSrcweir
DataSeries(const uno::Reference<uno::XComponentContext> & xContext)165cdf0e10cSrcweir DataSeries::DataSeries( const uno::Reference< uno::XComponentContext > & xContext ) :
166cdf0e10cSrcweir ::property::OPropertySet( m_aMutex ),
167cdf0e10cSrcweir m_xContext( xContext ),
168cdf0e10cSrcweir m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
169cdf0e10cSrcweir {
170cdf0e10cSrcweir }
171cdf0e10cSrcweir
DataSeries(const DataSeries & rOther)172cdf0e10cSrcweir DataSeries::DataSeries( const DataSeries & rOther ) :
173cdf0e10cSrcweir MutexContainer(),
174cdf0e10cSrcweir impl::DataSeries_Base(),
175cdf0e10cSrcweir ::property::OPropertySet( rOther, m_aMutex ),
176cdf0e10cSrcweir m_xContext( rOther.m_xContext ),
177cdf0e10cSrcweir m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
178cdf0e10cSrcweir {
179cdf0e10cSrcweir if( ! rOther.m_aDataSequences.empty())
180cdf0e10cSrcweir {
181cdf0e10cSrcweir CloneHelper::CloneRefVector< tDataSequenceContainer::value_type >(
182cdf0e10cSrcweir rOther.m_aDataSequences, m_aDataSequences );
183cdf0e10cSrcweir ModifyListenerHelper::addListenerToAllElements( m_aDataSequences, m_xModifyEventForwarder );
184cdf0e10cSrcweir }
185cdf0e10cSrcweir
186cdf0e10cSrcweir CloneHelper::CloneRefVector< Reference< chart2::XRegressionCurve > >( rOther.m_aRegressionCurves, m_aRegressionCurves );
187cdf0e10cSrcweir ModifyListenerHelper::addListenerToAllElements( m_aRegressionCurves, m_xModifyEventForwarder );
188cdf0e10cSrcweir
189cdf0e10cSrcweir // add as listener to XPropertySet properties
190cdf0e10cSrcweir Reference< beans::XPropertySet > xPropertySet;
191cdf0e10cSrcweir uno::Any aValue;
192cdf0e10cSrcweir
193cdf0e10cSrcweir getFastPropertyValue( aValue, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_X );
194cdf0e10cSrcweir if( ( aValue >>= xPropertySet )
195cdf0e10cSrcweir && xPropertySet.is())
196cdf0e10cSrcweir ModifyListenerHelper::addListener( xPropertySet, m_xModifyEventForwarder );
197cdf0e10cSrcweir
198cdf0e10cSrcweir getFastPropertyValue( aValue, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_Y );
199cdf0e10cSrcweir if( ( aValue >>= xPropertySet )
200cdf0e10cSrcweir && xPropertySet.is())
201cdf0e10cSrcweir ModifyListenerHelper::addListener( xPropertySet, m_xModifyEventForwarder );
202cdf0e10cSrcweir }
203cdf0e10cSrcweir
204cdf0e10cSrcweir // late initialization to call after copy-constructing
Init(const DataSeries & rOther)205cdf0e10cSrcweir void DataSeries::Init( const DataSeries & rOther )
206cdf0e10cSrcweir {
207cdf0e10cSrcweir if( ! rOther.m_aDataSequences.empty())
208cdf0e10cSrcweir EventListenerHelper::addListenerToAllElements( m_aDataSequences, this );
209cdf0e10cSrcweir
210cdf0e10cSrcweir Reference< uno::XInterface > xThisInterface( static_cast< ::cppu::OWeakObject * >( this ));
211cdf0e10cSrcweir if( ! rOther.m_aAttributedDataPoints.empty())
212cdf0e10cSrcweir {
213cdf0e10cSrcweir lcl_CloneAttributedDataPoints(
214cdf0e10cSrcweir rOther.m_aAttributedDataPoints, m_aAttributedDataPoints, xThisInterface );
215cdf0e10cSrcweir ModifyListenerHelper::addListenerToAllMapElements( m_aAttributedDataPoints, m_xModifyEventForwarder );
216cdf0e10cSrcweir }
217cdf0e10cSrcweir
218cdf0e10cSrcweir // add as parent to error bars
219cdf0e10cSrcweir Reference< beans::XPropertySet > xPropertySet;
220cdf0e10cSrcweir uno::Any aValue;
221cdf0e10cSrcweir
222cdf0e10cSrcweir getFastPropertyValue( aValue, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_X );
223cdf0e10cSrcweir if( ( aValue >>= xPropertySet )
224cdf0e10cSrcweir && xPropertySet.is())
225cdf0e10cSrcweir lcl_SetParent( xPropertySet, xThisInterface );
226cdf0e10cSrcweir
227cdf0e10cSrcweir getFastPropertyValue( aValue, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_Y );
228cdf0e10cSrcweir if( ( aValue >>= xPropertySet )
229cdf0e10cSrcweir && xPropertySet.is())
230cdf0e10cSrcweir lcl_SetParent( xPropertySet, xThisInterface );
231cdf0e10cSrcweir }
232cdf0e10cSrcweir
~DataSeries()233cdf0e10cSrcweir DataSeries::~DataSeries()
234cdf0e10cSrcweir {
235cdf0e10cSrcweir try
236cdf0e10cSrcweir {
237cdf0e10cSrcweir ModifyListenerHelper::removeListenerFromAllMapElements( m_aAttributedDataPoints, m_xModifyEventForwarder );
238cdf0e10cSrcweir ModifyListenerHelper::removeListenerFromAllElements( m_aRegressionCurves, m_xModifyEventForwarder );
239cdf0e10cSrcweir ModifyListenerHelper::removeListenerFromAllElements( m_aDataSequences, m_xModifyEventForwarder );
240cdf0e10cSrcweir
241cdf0e10cSrcweir // remove listener from XPropertySet properties
242cdf0e10cSrcweir Reference< beans::XPropertySet > xPropertySet;
243cdf0e10cSrcweir uno::Any aValue;
244cdf0e10cSrcweir
245cdf0e10cSrcweir getFastPropertyValue( aValue, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_X );
246cdf0e10cSrcweir if( ( aValue >>= xPropertySet )
247cdf0e10cSrcweir && xPropertySet.is())
248cdf0e10cSrcweir ModifyListenerHelper::removeListener( xPropertySet, m_xModifyEventForwarder );
249cdf0e10cSrcweir
250cdf0e10cSrcweir getFastPropertyValue( aValue, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_Y );
251cdf0e10cSrcweir if( ( aValue >>= xPropertySet )
252cdf0e10cSrcweir && xPropertySet.is())
253cdf0e10cSrcweir ModifyListenerHelper::removeListener( xPropertySet, m_xModifyEventForwarder );
254cdf0e10cSrcweir }
255cdf0e10cSrcweir catch( const uno::Exception & ex )
256cdf0e10cSrcweir {
257cdf0e10cSrcweir ASSERT_EXCEPTION( ex );
258cdf0e10cSrcweir }
259cdf0e10cSrcweir }
260cdf0e10cSrcweir
261cdf0e10cSrcweir // ____ XCloneable ____
createClone()262cdf0e10cSrcweir uno::Reference< util::XCloneable > SAL_CALL DataSeries::createClone()
263cdf0e10cSrcweir throw (uno::RuntimeException)
264cdf0e10cSrcweir {
265cdf0e10cSrcweir DataSeries * pNewSeries( new DataSeries( *this ));
266cdf0e10cSrcweir // hold a reference to the clone
267cdf0e10cSrcweir uno::Reference< util::XCloneable > xResult( pNewSeries );
268cdf0e10cSrcweir // do initialization that uses uno references to the clone
269cdf0e10cSrcweir pNewSeries->Init( *this );
270cdf0e10cSrcweir
271cdf0e10cSrcweir return xResult;
272cdf0e10cSrcweir }
273cdf0e10cSrcweir
getSupportedServiceNames_Static()274cdf0e10cSrcweir Sequence< OUString > DataSeries::getSupportedServiceNames_Static()
275cdf0e10cSrcweir {
276cdf0e10cSrcweir Sequence< OUString > aServices( 3 );
277cdf0e10cSrcweir aServices[ 0 ] = C2U( "com.sun.star.chart2.DataSeries" );
278cdf0e10cSrcweir aServices[ 1 ] = C2U( "com.sun.star.chart2.DataPointProperties" );
279cdf0e10cSrcweir aServices[ 2 ] = C2U( "com.sun.star.beans.PropertySet" );
280cdf0e10cSrcweir return aServices;
281cdf0e10cSrcweir }
282cdf0e10cSrcweir
283cdf0e10cSrcweir // ____ OPropertySet ____
GetDefaultValue(sal_Int32 nHandle) const284cdf0e10cSrcweir uno::Any DataSeries::GetDefaultValue( sal_Int32 nHandle ) const
285cdf0e10cSrcweir throw(beans::UnknownPropertyException)
286cdf0e10cSrcweir {
287cdf0e10cSrcweir const tPropertyValueMap& rStaticDefaults = *StaticDataSeriesDefaults::get();
288cdf0e10cSrcweir tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
289cdf0e10cSrcweir if( aFound == rStaticDefaults.end() )
290cdf0e10cSrcweir return uno::Any();
291cdf0e10cSrcweir return (*aFound).second;
292cdf0e10cSrcweir }
293cdf0e10cSrcweir
294cdf0e10cSrcweir // ____ OPropertySet ____
getInfoHelper()295cdf0e10cSrcweir ::cppu::IPropertyArrayHelper & SAL_CALL DataSeries::getInfoHelper()
296cdf0e10cSrcweir {
297cdf0e10cSrcweir return *StaticDataSeriesInfoHelper::get();
298cdf0e10cSrcweir }
299cdf0e10cSrcweir
300cdf0e10cSrcweir // ____ XPropertySet ____
getPropertySetInfo()301cdf0e10cSrcweir uno::Reference< beans::XPropertySetInfo > SAL_CALL DataSeries::getPropertySetInfo()
302cdf0e10cSrcweir throw (uno::RuntimeException)
303cdf0e10cSrcweir {
304cdf0e10cSrcweir return *StaticDataSeriesInfo::get();
305cdf0e10cSrcweir }
306cdf0e10cSrcweir
getFastPropertyValue(uno::Any & rValue,sal_Int32 nHandle) const307cdf0e10cSrcweir void SAL_CALL DataSeries::getFastPropertyValue
308cdf0e10cSrcweir ( uno::Any& rValue,
309cdf0e10cSrcweir sal_Int32 nHandle ) const
310cdf0e10cSrcweir {
311cdf0e10cSrcweir // special handling for get. set is not possible for this property
312cdf0e10cSrcweir if( nHandle == DataSeriesProperties::PROP_DATASERIES_ATTRIBUTED_DATA_POINTS )
313cdf0e10cSrcweir {
314cdf0e10cSrcweir // ToDo: only add those property sets that are really modified
315cdf0e10cSrcweir uno::Sequence< sal_Int32 > aSeq( m_aAttributedDataPoints.size());
316cdf0e10cSrcweir sal_Int32 * pIndexArray = aSeq.getArray();
317cdf0e10cSrcweir sal_Int32 i = 0;
318cdf0e10cSrcweir
319cdf0e10cSrcweir for( tDataPointAttributeContainer::const_iterator aIt( m_aAttributedDataPoints.begin());
320cdf0e10cSrcweir aIt != m_aAttributedDataPoints.end(); ++aIt )
321cdf0e10cSrcweir {
322cdf0e10cSrcweir pIndexArray[ i ] = (*aIt).first;
323cdf0e10cSrcweir ++i;
324cdf0e10cSrcweir }
325cdf0e10cSrcweir
326cdf0e10cSrcweir rValue <<= aSeq;
327cdf0e10cSrcweir }
328cdf0e10cSrcweir else
329cdf0e10cSrcweir OPropertySet::getFastPropertyValue( rValue, nHandle );
330cdf0e10cSrcweir }
331cdf0e10cSrcweir
setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const uno::Any & rValue)332cdf0e10cSrcweir void SAL_CALL DataSeries::setFastPropertyValue_NoBroadcast(
333cdf0e10cSrcweir sal_Int32 nHandle, const uno::Any& rValue )
334cdf0e10cSrcweir throw (uno::Exception)
335cdf0e10cSrcweir {
336cdf0e10cSrcweir if( nHandle == DataPointProperties::PROP_DATAPOINT_ERROR_BAR_Y
337cdf0e10cSrcweir || nHandle == DataPointProperties::PROP_DATAPOINT_ERROR_BAR_X )
338cdf0e10cSrcweir {
339cdf0e10cSrcweir uno::Any aOldValue;
340cdf0e10cSrcweir Reference< util::XModifyBroadcaster > xBroadcaster;
341cdf0e10cSrcweir this->getFastPropertyValue( aOldValue, nHandle );
342cdf0e10cSrcweir if( aOldValue.hasValue() &&
343cdf0e10cSrcweir (aOldValue >>= xBroadcaster) &&
344cdf0e10cSrcweir xBroadcaster.is())
345cdf0e10cSrcweir {
346cdf0e10cSrcweir ModifyListenerHelper::removeListener( xBroadcaster, m_xModifyEventForwarder );
347cdf0e10cSrcweir }
348cdf0e10cSrcweir
349cdf0e10cSrcweir OSL_ASSERT( rValue.getValueType().getTypeClass() == uno::TypeClass_INTERFACE );
350cdf0e10cSrcweir if( rValue.hasValue() &&
351cdf0e10cSrcweir (rValue >>= xBroadcaster) &&
352cdf0e10cSrcweir xBroadcaster.is())
353cdf0e10cSrcweir {
354cdf0e10cSrcweir ModifyListenerHelper::addListener( xBroadcaster, m_xModifyEventForwarder );
355cdf0e10cSrcweir }
356cdf0e10cSrcweir }
357cdf0e10cSrcweir
358cdf0e10cSrcweir ::property::OPropertySet::setFastPropertyValue_NoBroadcast( nHandle, rValue );
359cdf0e10cSrcweir }
360cdf0e10cSrcweir
361cdf0e10cSrcweir Reference< beans::XPropertySet >
getDataPointByIndex(sal_Int32 nIndex)362cdf0e10cSrcweir SAL_CALL DataSeries::getDataPointByIndex( sal_Int32 nIndex )
363cdf0e10cSrcweir throw (lang::IndexOutOfBoundsException,
364cdf0e10cSrcweir uno::RuntimeException)
365cdf0e10cSrcweir {
366cdf0e10cSrcweir Reference< beans::XPropertySet > xResult;
367cdf0e10cSrcweir
368cdf0e10cSrcweir Sequence< Reference< chart2::data::XLabeledDataSequence > > aSequences;
369cdf0e10cSrcweir {
370cdf0e10cSrcweir MutexGuard aGuard( GetMutex() );
371cdf0e10cSrcweir aSequences = ContainerHelper::ContainerToSequence( m_aDataSequences );
372cdf0e10cSrcweir }
373cdf0e10cSrcweir
374cdf0e10cSrcweir ::std::vector< Reference< chart2::data::XLabeledDataSequence > > aValuesSeries(
375cdf0e10cSrcweir DataSeriesHelper::getAllDataSequencesByRole( aSequences , C2U("values"), true ) );
376cdf0e10cSrcweir if( !aValuesSeries.empty() )
377cdf0e10cSrcweir {
378cdf0e10cSrcweir Reference< chart2::data::XDataSequence > xSeq( aValuesSeries.front()->getValues() );
379cdf0e10cSrcweir if( 0 <= nIndex && nIndex < xSeq->getData().getLength() )
380cdf0e10cSrcweir {
381cdf0e10cSrcweir {
382cdf0e10cSrcweir MutexGuard aGuard( GetMutex() );
383cdf0e10cSrcweir tDataPointAttributeContainer::iterator aIt( m_aAttributedDataPoints.find( nIndex ) );
384cdf0e10cSrcweir if( aIt != m_aAttributedDataPoints.end() )
385cdf0e10cSrcweir xResult = (*aIt).second;
386cdf0e10cSrcweir }
387cdf0e10cSrcweir if( !xResult.is() )
388cdf0e10cSrcweir {
389cdf0e10cSrcweir Reference< beans::XPropertySet > xParentProperties;
390cdf0e10cSrcweir Reference< util::XModifyListener > xModifyEventForwarder;
391cdf0e10cSrcweir {
392cdf0e10cSrcweir MutexGuard aGuard( GetMutex() );
393cdf0e10cSrcweir xParentProperties = this;
394cdf0e10cSrcweir xModifyEventForwarder = m_xModifyEventForwarder;
395cdf0e10cSrcweir }
396cdf0e10cSrcweir
397cdf0e10cSrcweir // create a new XPropertySet for this data point
398cdf0e10cSrcweir xResult.set( new DataPoint( xParentProperties ) );
399cdf0e10cSrcweir {
400cdf0e10cSrcweir MutexGuard aGuard( GetMutex() );
401cdf0e10cSrcweir m_aAttributedDataPoints[ nIndex ] = xResult;
402cdf0e10cSrcweir }
403cdf0e10cSrcweir ModifyListenerHelper::addListener( xResult, xModifyEventForwarder );
404cdf0e10cSrcweir }
405cdf0e10cSrcweir }
406cdf0e10cSrcweir }
407cdf0e10cSrcweir else
408cdf0e10cSrcweir {
409cdf0e10cSrcweir throw lang::IndexOutOfBoundsException();
410cdf0e10cSrcweir }
411cdf0e10cSrcweir
412cdf0e10cSrcweir return xResult;
413cdf0e10cSrcweir }
414cdf0e10cSrcweir
resetDataPoint(sal_Int32 nIndex)415cdf0e10cSrcweir void SAL_CALL DataSeries::resetDataPoint( sal_Int32 nIndex )
416cdf0e10cSrcweir throw (uno::RuntimeException)
417cdf0e10cSrcweir {
418cdf0e10cSrcweir Reference< beans::XPropertySet > xDataPointProp;
419cdf0e10cSrcweir Reference< util::XModifyListener > xModifyEventForwarder;
420cdf0e10cSrcweir {
421cdf0e10cSrcweir MutexGuard aGuard( GetMutex() );
422cdf0e10cSrcweir xModifyEventForwarder = m_xModifyEventForwarder;
423cdf0e10cSrcweir tDataPointAttributeContainer::iterator aIt( m_aAttributedDataPoints.find( nIndex ));
424cdf0e10cSrcweir if( aIt != m_aAttributedDataPoints.end())
425cdf0e10cSrcweir {
426cdf0e10cSrcweir xDataPointProp = (*aIt).second;
427cdf0e10cSrcweir m_aAttributedDataPoints.erase(aIt);
428cdf0e10cSrcweir }
429cdf0e10cSrcweir
430cdf0e10cSrcweir }
431cdf0e10cSrcweir if( xDataPointProp.is() )
432cdf0e10cSrcweir {
433cdf0e10cSrcweir Reference< util::XModifyBroadcaster > xBroadcaster( xDataPointProp, uno::UNO_QUERY );
434cdf0e10cSrcweir if( xBroadcaster.is() && xModifyEventForwarder.is())
435cdf0e10cSrcweir xBroadcaster->removeModifyListener( xModifyEventForwarder );
436cdf0e10cSrcweir fireModifyEvent();
437cdf0e10cSrcweir }
438cdf0e10cSrcweir }
439cdf0e10cSrcweir
resetAllDataPoints()440cdf0e10cSrcweir void SAL_CALL DataSeries::resetAllDataPoints()
441cdf0e10cSrcweir throw (uno::RuntimeException)
442cdf0e10cSrcweir {
443cdf0e10cSrcweir tDataPointAttributeContainer aOldAttributedDataPoints;
444cdf0e10cSrcweir Reference< util::XModifyListener > xModifyEventForwarder;
445cdf0e10cSrcweir {
446cdf0e10cSrcweir MutexGuard aGuard( GetMutex() );
447cdf0e10cSrcweir xModifyEventForwarder = m_xModifyEventForwarder;
448cdf0e10cSrcweir std::swap( aOldAttributedDataPoints, m_aAttributedDataPoints );
449cdf0e10cSrcweir }
450cdf0e10cSrcweir ModifyListenerHelper::removeListenerFromAllMapElements( aOldAttributedDataPoints, xModifyEventForwarder );
451cdf0e10cSrcweir aOldAttributedDataPoints.clear();
452cdf0e10cSrcweir fireModifyEvent();
453cdf0e10cSrcweir }
454cdf0e10cSrcweir
455cdf0e10cSrcweir // ____ XDataSink ____
setData(const uno::Sequence<Reference<chart2::data::XLabeledDataSequence>> & aData)456cdf0e10cSrcweir void SAL_CALL DataSeries::setData( const uno::Sequence< Reference< chart2::data::XLabeledDataSequence > >& aData )
457cdf0e10cSrcweir throw (uno::RuntimeException)
458cdf0e10cSrcweir {
459cdf0e10cSrcweir tDataSequenceContainer aOldDataSequences;
460cdf0e10cSrcweir tDataSequenceContainer aNewDataSequences;
461cdf0e10cSrcweir Reference< util::XModifyListener > xModifyEventForwarder;
462cdf0e10cSrcweir Reference< lang::XEventListener > xListener;
463cdf0e10cSrcweir {
464cdf0e10cSrcweir MutexGuard aGuard( GetMutex() );
465cdf0e10cSrcweir xModifyEventForwarder = m_xModifyEventForwarder;
466cdf0e10cSrcweir xListener = this;
467cdf0e10cSrcweir std::swap( aOldDataSequences, m_aDataSequences );
468cdf0e10cSrcweir aNewDataSequences = ContainerHelper::SequenceToVector( aData );
469cdf0e10cSrcweir m_aDataSequences = aNewDataSequences;
470cdf0e10cSrcweir }
471cdf0e10cSrcweir ModifyListenerHelper::removeListenerFromAllElements( aOldDataSequences, xModifyEventForwarder );
472cdf0e10cSrcweir EventListenerHelper::removeListenerFromAllElements( aOldDataSequences, xListener );
473cdf0e10cSrcweir EventListenerHelper::addListenerToAllElements( aNewDataSequences, xListener );
474cdf0e10cSrcweir ModifyListenerHelper::addListenerToAllElements( aNewDataSequences, xModifyEventForwarder );
475cdf0e10cSrcweir fireModifyEvent();
476cdf0e10cSrcweir }
477cdf0e10cSrcweir
478cdf0e10cSrcweir // ____ XDataSource ____
getDataSequences()479cdf0e10cSrcweir Sequence< Reference< chart2::data::XLabeledDataSequence > > SAL_CALL DataSeries::getDataSequences()
480cdf0e10cSrcweir throw (uno::RuntimeException)
481cdf0e10cSrcweir {
482cdf0e10cSrcweir MutexGuard aGuard( GetMutex() );
483cdf0e10cSrcweir return ContainerHelper::ContainerToSequence( m_aDataSequences );
484cdf0e10cSrcweir }
485cdf0e10cSrcweir
486cdf0e10cSrcweir
487cdf0e10cSrcweir // ____ XRegressionCurveContainer ____
addRegressionCurve(const uno::Reference<chart2::XRegressionCurve> & xRegressionCurve)488cdf0e10cSrcweir void SAL_CALL DataSeries::addRegressionCurve(
489cdf0e10cSrcweir const uno::Reference< chart2::XRegressionCurve >& xRegressionCurve )
490cdf0e10cSrcweir throw (lang::IllegalArgumentException,
491cdf0e10cSrcweir uno::RuntimeException)
492cdf0e10cSrcweir {
493cdf0e10cSrcweir Reference< util::XModifyListener > xModifyEventForwarder;
494cdf0e10cSrcweir {
495cdf0e10cSrcweir MutexGuard aGuard( GetMutex() );
496cdf0e10cSrcweir xModifyEventForwarder = m_xModifyEventForwarder;
497cdf0e10cSrcweir if( ::std::find( m_aRegressionCurves.begin(), m_aRegressionCurves.end(), xRegressionCurve )
498cdf0e10cSrcweir != m_aRegressionCurves.end())
499cdf0e10cSrcweir throw lang::IllegalArgumentException();
500cdf0e10cSrcweir m_aRegressionCurves.push_back( xRegressionCurve );
501cdf0e10cSrcweir }
502cdf0e10cSrcweir ModifyListenerHelper::addListener( xRegressionCurve, xModifyEventForwarder );
503cdf0e10cSrcweir fireModifyEvent();
504cdf0e10cSrcweir }
505cdf0e10cSrcweir
removeRegressionCurve(const uno::Reference<chart2::XRegressionCurve> & xRegressionCurve)506cdf0e10cSrcweir void SAL_CALL DataSeries::removeRegressionCurve(
507cdf0e10cSrcweir const uno::Reference< chart2::XRegressionCurve >& xRegressionCurve )
508cdf0e10cSrcweir throw (container::NoSuchElementException,
509cdf0e10cSrcweir uno::RuntimeException)
510cdf0e10cSrcweir {
511cdf0e10cSrcweir if( !xRegressionCurve.is() )
512cdf0e10cSrcweir throw container::NoSuchElementException();
513cdf0e10cSrcweir
514cdf0e10cSrcweir Reference< util::XModifyListener > xModifyEventForwarder;
515cdf0e10cSrcweir {
516cdf0e10cSrcweir MutexGuard aGuard( GetMutex() );
517cdf0e10cSrcweir xModifyEventForwarder = m_xModifyEventForwarder;
518cdf0e10cSrcweir tRegressionCurveContainerType::iterator aIt(
519cdf0e10cSrcweir ::std::find( m_aRegressionCurves.begin(), m_aRegressionCurves.end(), xRegressionCurve ) );
520cdf0e10cSrcweir if( aIt == m_aRegressionCurves.end())
521cdf0e10cSrcweir throw container::NoSuchElementException(
522cdf0e10cSrcweir C2U( "The given regression curve is no element of this series" ),
523cdf0e10cSrcweir static_cast< uno::XWeak * >( this ));
524cdf0e10cSrcweir m_aRegressionCurves.erase( aIt );
525cdf0e10cSrcweir }
526cdf0e10cSrcweir
527cdf0e10cSrcweir ModifyListenerHelper::removeListener( xRegressionCurve, xModifyEventForwarder );
528cdf0e10cSrcweir fireModifyEvent();
529cdf0e10cSrcweir }
530cdf0e10cSrcweir
getRegressionCurves()531cdf0e10cSrcweir uno::Sequence< uno::Reference< chart2::XRegressionCurve > > SAL_CALL DataSeries::getRegressionCurves()
532cdf0e10cSrcweir throw (uno::RuntimeException)
533cdf0e10cSrcweir {
534cdf0e10cSrcweir MutexGuard aGuard( GetMutex() );
535cdf0e10cSrcweir return ContainerHelper::ContainerToSequence( m_aRegressionCurves );
536cdf0e10cSrcweir }
537cdf0e10cSrcweir
setRegressionCurves(const Sequence<Reference<chart2::XRegressionCurve>> & aRegressionCurves)538cdf0e10cSrcweir void SAL_CALL DataSeries::setRegressionCurves(
539cdf0e10cSrcweir const Sequence< Reference< chart2::XRegressionCurve > >& aRegressionCurves )
540cdf0e10cSrcweir throw (uno::RuntimeException)
541cdf0e10cSrcweir {
542cdf0e10cSrcweir tRegressionCurveContainerType aOldCurves;
543cdf0e10cSrcweir tRegressionCurveContainerType aNewCurves( ContainerHelper::SequenceToVector( aRegressionCurves ) );
544cdf0e10cSrcweir Reference< util::XModifyListener > xModifyEventForwarder;
545cdf0e10cSrcweir {
546cdf0e10cSrcweir MutexGuard aGuard( GetMutex() );
547cdf0e10cSrcweir xModifyEventForwarder = m_xModifyEventForwarder;
548cdf0e10cSrcweir std::swap( aOldCurves, m_aRegressionCurves );
549cdf0e10cSrcweir m_aRegressionCurves = aNewCurves;
550cdf0e10cSrcweir }
551cdf0e10cSrcweir ModifyListenerHelper::removeListenerFromAllElements( aOldCurves, xModifyEventForwarder );
552cdf0e10cSrcweir ModifyListenerHelper::addListenerToAllElements( aNewCurves, xModifyEventForwarder );
553cdf0e10cSrcweir fireModifyEvent();
554cdf0e10cSrcweir }
555cdf0e10cSrcweir
556cdf0e10cSrcweir // ____ XModifyBroadcaster ____
addModifyListener(const Reference<util::XModifyListener> & aListener)557cdf0e10cSrcweir void SAL_CALL DataSeries::addModifyListener( const Reference< util::XModifyListener >& aListener )
558cdf0e10cSrcweir throw (uno::RuntimeException)
559cdf0e10cSrcweir {
560cdf0e10cSrcweir try
561cdf0e10cSrcweir {
562cdf0e10cSrcweir Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
563cdf0e10cSrcweir xBroadcaster->addModifyListener( aListener );
564cdf0e10cSrcweir }
565cdf0e10cSrcweir catch( const uno::Exception & ex )
566cdf0e10cSrcweir {
567cdf0e10cSrcweir ASSERT_EXCEPTION( ex );
568cdf0e10cSrcweir }
569cdf0e10cSrcweir }
570cdf0e10cSrcweir
removeModifyListener(const Reference<util::XModifyListener> & aListener)571cdf0e10cSrcweir void SAL_CALL DataSeries::removeModifyListener( const Reference< util::XModifyListener >& aListener )
572cdf0e10cSrcweir throw (uno::RuntimeException)
573cdf0e10cSrcweir {
574cdf0e10cSrcweir try
575cdf0e10cSrcweir {
576cdf0e10cSrcweir Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
577cdf0e10cSrcweir xBroadcaster->removeModifyListener( aListener );
578cdf0e10cSrcweir }
579cdf0e10cSrcweir catch( const uno::Exception & ex )
580cdf0e10cSrcweir {
581cdf0e10cSrcweir ASSERT_EXCEPTION( ex );
582cdf0e10cSrcweir }
583cdf0e10cSrcweir }
584cdf0e10cSrcweir
585cdf0e10cSrcweir // ____ XModifyListener ____
modified(const lang::EventObject & aEvent)586cdf0e10cSrcweir void SAL_CALL DataSeries::modified( const lang::EventObject& aEvent )
587cdf0e10cSrcweir throw (uno::RuntimeException)
588cdf0e10cSrcweir {
589cdf0e10cSrcweir m_xModifyEventForwarder->modified( aEvent );
590cdf0e10cSrcweir }
591cdf0e10cSrcweir
592cdf0e10cSrcweir // ____ XEventListener (base of XModifyListener) ____
disposing(const lang::EventObject & rEventObject)593cdf0e10cSrcweir void SAL_CALL DataSeries::disposing( const lang::EventObject& rEventObject )
594cdf0e10cSrcweir throw (uno::RuntimeException)
595cdf0e10cSrcweir {
596cdf0e10cSrcweir // forget disposed data sequences
597cdf0e10cSrcweir tDataSequenceContainer::iterator aIt(
598cdf0e10cSrcweir ::std::find( m_aDataSequences.begin(), m_aDataSequences.end(), rEventObject.Source ));
599cdf0e10cSrcweir if( aIt != m_aDataSequences.end())
600cdf0e10cSrcweir m_aDataSequences.erase( aIt );
601cdf0e10cSrcweir }
602cdf0e10cSrcweir
603cdf0e10cSrcweir // ____ OPropertySet ____
firePropertyChangeEvent()604cdf0e10cSrcweir void DataSeries::firePropertyChangeEvent()
605cdf0e10cSrcweir {
606cdf0e10cSrcweir fireModifyEvent();
607cdf0e10cSrcweir }
608cdf0e10cSrcweir
fireModifyEvent()609cdf0e10cSrcweir void DataSeries::fireModifyEvent()
610cdf0e10cSrcweir {
611cdf0e10cSrcweir m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
612cdf0e10cSrcweir }
613cdf0e10cSrcweir
614cdf0e10cSrcweir
615cdf0e10cSrcweir // ================================================================================
616cdf0e10cSrcweir
617cdf0e10cSrcweir using impl::DataSeries_Base;
618cdf0e10cSrcweir using ::property::OPropertySet;
619cdf0e10cSrcweir
620cdf0e10cSrcweir IMPLEMENT_FORWARD_XINTERFACE2( DataSeries, DataSeries_Base, OPropertySet )
621cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER2( DataSeries, DataSeries_Base, OPropertySet )
622cdf0e10cSrcweir
623cdf0e10cSrcweir // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
624cdf0e10cSrcweir APPHELPER_XSERVICEINFO_IMPL( DataSeries,
625cdf0e10cSrcweir C2U( "com.sun.star.comp.chart.DataSeries" ));
626cdf0e10cSrcweir
627cdf0e10cSrcweir } // namespace chart
628