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

Generated by: LCOV version 1.11