LCOV - code coverage report
Current view: top level - libreoffice/chart2/source/model/main - DataSeries.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 130 287 45.3 %
Date: 2012-12-27 Functions: 24 43 55.8 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10