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

Generated by: LCOV version 1.10