LCOV - code coverage report
Current view: top level - chart2/source/model/main - DataPoint.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 49 106 46.2 %
Date: 2012-08-25 Functions: 15 28 53.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 48 210 22.9 %

           Branch data     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 "DataPoint.hxx"
      21                 :            : #include "DataPointProperties.hxx"
      22                 :            : #include "CharacterProperties.hxx"
      23                 :            : #include "UserDefinedProperties.hxx"
      24                 :            : #include "PropertyHelper.hxx"
      25                 :            : #include "macros.hxx"
      26                 :            : #include "ContainerHelper.hxx"
      27                 :            : #include <com/sun/star/beans/PropertyAttribute.hpp>
      28                 :            : #include <com/sun/star/style/XStyle.hpp>
      29                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      30                 :            : #include <com/sun/star/uno/Sequence.hxx>
      31                 :            : 
      32                 :            : #include <algorithm>
      33                 :            : 
      34                 :            : using namespace ::com::sun::star;
      35                 :            : 
      36                 :            : using ::com::sun::star::uno::Reference;
      37                 :            : using ::com::sun::star::uno::Sequence;
      38                 :            : using ::com::sun::star::beans::Property;
      39                 :            : using ::osl::MutexGuard;
      40                 :            : using ::rtl::OUString;
      41                 :            : 
      42                 :            : // ____________________________________________________________
      43                 :            : 
      44                 :            : namespace
      45                 :            : {
      46                 :            : 
      47                 :            : struct StaticDataPointInfoHelper_Initializer
      48                 :            : {
      49                 :          2 :     ::cppu::OPropertyArrayHelper* operator()()
      50                 :            :     {
      51 [ +  - ][ +  - ]:          2 :         static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
         [ +  - ][ +  - ]
         [ +  - ][ #  # ]
      52                 :          2 :         return &aPropHelper;
      53                 :            :     }
      54                 :            : 
      55                 :            : private:
      56                 :          2 :     Sequence< Property > lcl_GetPropertySequence()
      57                 :            :     {
      58         [ +  - ]:          2 :         ::std::vector< ::com::sun::star::beans::Property > aProperties;
      59         [ +  - ]:          2 :         ::chart::DataPointProperties::AddPropertiesToVector( aProperties );
      60         [ +  - ]:          2 :         ::chart::CharacterProperties::AddPropertiesToVector( aProperties );
      61         [ +  - ]:          2 :         ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
      62                 :            : 
      63                 :            :         ::std::sort( aProperties.begin(), aProperties.end(),
      64         [ +  - ]:          2 :                      ::chart::PropertyNameLess() );
      65                 :            : 
      66         [ +  - ]:          2 :         return ::chart::ContainerHelper::ContainerToSequence( aProperties );
      67                 :            :     }
      68                 :            : };
      69                 :            : 
      70                 :            : struct StaticDataPointInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticDataPointInfoHelper_Initializer >
      71                 :            : {
      72                 :            : };
      73                 :            : 
      74                 :            : struct StaticDataPointInfo_Initializer
      75                 :            : {
      76                 :          0 :     uno::Reference< beans::XPropertySetInfo >* operator()()
      77                 :            :     {
      78                 :            :         static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
      79 [ #  # ][ #  # ]:          0 :             ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticDataPointInfoHelper::get() ) );
         [ #  # ][ #  # ]
                 [ #  # ]
      80                 :          0 :         return &xPropertySetInfo;
      81                 :            :     }
      82                 :            : };
      83                 :            : 
      84                 :            : struct StaticDataPointInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticDataPointInfo_Initializer >
      85                 :            : {
      86                 :            : };
      87                 :            : 
      88                 :            : } // anonymous namespace
      89                 :            : 
      90                 :            : // ____________________________________________________________
      91                 :            : 
      92                 :            : namespace chart
      93                 :            : {
      94                 :            : 
      95                 :          2 : DataPoint::DataPoint( const uno::Reference< beans::XPropertySet > & rParentProperties ) :
      96                 :            :         ::property::OPropertySet( m_aMutex ),
      97                 :            :         m_xParentProperties( rParentProperties ),
      98                 :            :         m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
      99 [ +  - ][ +  - ]:          2 :         m_bNoParentPropAllowed( false )
         [ +  - ][ +  - ]
     100                 :            : {
     101         [ +  - ]:          2 :     SetNewValuesExplicitlyEvenIfTheyEqualDefault();
     102                 :          2 : }
     103                 :            : 
     104                 :          0 : DataPoint::DataPoint( const DataPoint & rOther ) :
     105                 :            :         MutexContainer(),
     106                 :            :         impl::DataPoint_Base(),
     107                 :            :         ::property::OPropertySet( rOther, m_aMutex ),
     108                 :            :         m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
     109 [ #  # ][ #  # ]:          0 :         m_bNoParentPropAllowed( true )
         [ #  # ][ #  # ]
     110                 :            : {
     111         [ #  # ]:          0 :     SetNewValuesExplicitlyEvenIfTheyEqualDefault();
     112                 :            : 
     113                 :            :     // m_xParentProperties has to be set from outside, like in the method
     114                 :            :     // DataSeries::createClone
     115                 :            : 
     116                 :            :     // add as listener to XPropertySet properties
     117                 :          0 :     Reference< beans::XPropertySet > xPropertySet;
     118                 :          0 :     uno::Any aValue;
     119                 :            : 
     120         [ #  # ]:          0 :     getFastPropertyValue( aValue, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_X );
     121         [ #  # ]:          0 :     if( ( aValue >>= xPropertySet )
           [ #  #  #  # ]
                 [ #  # ]
     122                 :          0 :         && xPropertySet.is())
     123         [ #  # ]:          0 :         ModifyListenerHelper::addListener( xPropertySet, m_xModifyEventForwarder );
     124                 :            : 
     125         [ #  # ]:          0 :     getFastPropertyValue( aValue, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_Y );
     126         [ #  # ]:          0 :     if( ( aValue >>= xPropertySet )
           [ #  #  #  # ]
                 [ #  # ]
     127                 :          0 :         && xPropertySet.is())
     128         [ #  # ]:          0 :         ModifyListenerHelper::addListener( xPropertySet, m_xModifyEventForwarder );
     129                 :            : 
     130                 :          0 :     m_bNoParentPropAllowed = false;
     131                 :          0 : }
     132                 :            : 
     133 [ +  - ][ +  - ]:          2 : DataPoint::~DataPoint()
                 [ +  - ]
     134                 :            : {
     135                 :            :     try
     136                 :            :     {
     137                 :            :         // remove listener from XPropertySet properties
     138                 :          2 :         Reference< beans::XPropertySet > xPropertySet;
     139                 :          2 :         uno::Any aValue;
     140                 :            : 
     141         [ +  - ]:          2 :         getFastPropertyValue( aValue, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_X );
     142         [ +  - ]:          2 :         if( ( aValue >>= xPropertySet )
           [ -  +  #  # ]
                 [ -  + ]
     143                 :          0 :             && xPropertySet.is())
     144         [ #  # ]:          0 :             ModifyListenerHelper::removeListener( xPropertySet, m_xModifyEventForwarder );
     145                 :            : 
     146         [ +  - ]:          2 :         getFastPropertyValue( aValue, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_Y );
     147         [ +  - ]:          2 :         if( ( aValue >>= xPropertySet )
           [ -  +  #  # ]
                 [ -  + ]
     148                 :          0 :             && xPropertySet.is())
     149 [ #  # ][ #  # ]:          2 :             ModifyListenerHelper::removeListener( xPropertySet, m_xModifyEventForwarder );
     150                 :            :     }
     151         [ #  # ]:          0 :     catch( const uno::Exception & ex )
     152                 :            :     {
     153                 :            :         ASSERT_EXCEPTION( ex );
     154                 :            :     }
     155         [ -  + ]:          4 : }
     156                 :            : 
     157                 :            : // ____ XCloneable ____
     158                 :          0 : uno::Reference< util::XCloneable > SAL_CALL DataPoint::createClone()
     159                 :            :     throw (uno::RuntimeException)
     160                 :            : {
     161 [ #  # ][ #  # ]:          0 :     return uno::Reference< util::XCloneable >( new DataPoint( *this ));
     162                 :            : }
     163                 :            : 
     164                 :            : // ____ XChild ____
     165                 :          0 : Reference< uno::XInterface > SAL_CALL DataPoint::getParent()
     166                 :            :     throw (uno::RuntimeException)
     167                 :            : {
     168         [ #  # ]:          0 :     return Reference< uno::XInterface >( m_xParentProperties.get(), uno::UNO_QUERY );
     169                 :            : }
     170                 :            : 
     171                 :          0 : void SAL_CALL DataPoint::setParent(
     172                 :            :     const Reference< uno::XInterface >& Parent )
     173                 :            :     throw (lang::NoSupportException,
     174                 :            :            uno::RuntimeException)
     175                 :            : {
     176         [ #  # ]:          0 :     m_xParentProperties = Reference< beans::XPropertySet >( Parent, uno::UNO_QUERY );
     177                 :          0 : }
     178                 :            : 
     179                 :            : // ____ OPropertySet ____
     180                 :       7616 : uno::Any DataPoint::GetDefaultValue( sal_Int32 nHandle ) const
     181                 :            :     throw(beans::UnknownPropertyException)
     182                 :            : {
     183                 :            :     // the value set at the data series is the default
     184 [ +  - ][ +  - ]:       7616 :     uno::Reference< beans::XFastPropertySet > xFast( m_xParentProperties.get(), uno::UNO_QUERY );
     185         [ +  + ]:       7616 :     if( !xFast.is())
     186                 :            :     {
     187                 :            :         OSL_ENSURE( m_bNoParentPropAllowed, "data point needs a parent property set to provide values correctly" );
     188                 :          4 :         return uno::Any();
     189                 :            :     }
     190                 :            : 
     191 [ +  - ][ +  - ]:       7616 :     return xFast->getFastPropertyValue( nHandle );
     192                 :            : }
     193                 :            : 
     194                 :        412 : void SAL_CALL DataPoint::setFastPropertyValue_NoBroadcast(
     195                 :            :     sal_Int32 nHandle, const uno::Any& rValue )
     196                 :            :     throw (uno::Exception)
     197                 :            : {
     198 [ +  - ][ -  + ]:        412 :     if(    nHandle == DataPointProperties::PROP_DATAPOINT_ERROR_BAR_Y
     199                 :            :         || nHandle == DataPointProperties::PROP_DATAPOINT_ERROR_BAR_X )
     200                 :            :     {
     201                 :          0 :         uno::Any aOldValue;
     202                 :          0 :         Reference< util::XModifyBroadcaster > xBroadcaster;
     203         [ #  # ]:          0 :         this->getFastPropertyValue( aOldValue, nHandle );
     204         [ #  # ]:          0 :         if( aOldValue.hasValue() &&
           [ #  #  #  # ]
                 [ #  # ]
     205         [ #  # ]:          0 :             (aOldValue >>= xBroadcaster) &&
     206                 :          0 :             xBroadcaster.is())
     207                 :            :         {
     208         [ #  # ]:          0 :             ModifyListenerHelper::removeListener( xBroadcaster, m_xModifyEventForwarder );
     209                 :            :         }
     210                 :            : 
     211                 :            :         OSL_ASSERT( rValue.getValueType().getTypeClass() == uno::TypeClass_INTERFACE );
     212         [ #  # ]:          0 :         if( rValue.hasValue() &&
           [ #  #  #  # ]
                 [ #  # ]
     213         [ #  # ]:          0 :             (rValue >>= xBroadcaster) &&
     214                 :          0 :             xBroadcaster.is())
     215                 :            :         {
     216         [ #  # ]:          0 :             ModifyListenerHelper::addListener( xBroadcaster, m_xModifyEventForwarder );
     217                 :          0 :         }
     218                 :            :     }
     219                 :            : 
     220                 :        412 :     ::property::OPropertySet::setFastPropertyValue_NoBroadcast( nHandle, rValue );
     221                 :        412 : }
     222                 :            : 
     223                 :      40188 : ::cppu::IPropertyArrayHelper & SAL_CALL DataPoint::getInfoHelper()
     224                 :            : {
     225                 :      40188 :     return *StaticDataPointInfoHelper::get();
     226                 :            : }
     227                 :            : 
     228                 :            : // ____ XPropertySet ____
     229                 :          0 : Reference< beans::XPropertySetInfo > SAL_CALL DataPoint::getPropertySetInfo()
     230                 :            :     throw (uno::RuntimeException)
     231                 :            : {
     232                 :          0 :     return *StaticDataPointInfo::get();
     233                 :            : }
     234                 :            : 
     235                 :            : // ____ XModifyBroadcaster ____
     236                 :          2 : void SAL_CALL DataPoint::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
     237                 :            :     throw (uno::RuntimeException)
     238                 :            : {
     239                 :            :     try
     240                 :            :     {
     241         [ +  - ]:          2 :         uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     242 [ +  - ][ +  - ]:          2 :         xBroadcaster->addModifyListener( aListener );
                 [ #  # ]
     243                 :            :     }
     244                 :          0 :     catch( const uno::Exception & ex )
     245                 :            :     {
     246                 :            :         ASSERT_EXCEPTION( ex );
     247                 :            :     }
     248                 :          2 : }
     249                 :            : 
     250                 :          2 : void SAL_CALL DataPoint::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
     251                 :            :     throw (uno::RuntimeException)
     252                 :            : {
     253                 :            :     try
     254                 :            :     {
     255         [ +  - ]:          2 :         uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     256 [ +  - ][ +  - ]:          2 :         xBroadcaster->removeModifyListener( aListener );
                 [ #  # ]
     257                 :            :     }
     258                 :          0 :     catch( const uno::Exception & ex )
     259                 :            :     {
     260                 :            :         ASSERT_EXCEPTION( ex );
     261                 :            :     }
     262                 :          2 : }
     263                 :            : 
     264                 :            : // ____ XModifyListener ____
     265                 :          0 : void SAL_CALL DataPoint::modified( const lang::EventObject& aEvent )
     266                 :            :     throw (uno::RuntimeException)
     267                 :            : {
     268                 :          0 :     m_xModifyEventForwarder->modified( aEvent );
     269                 :          0 : }
     270                 :            : 
     271                 :            : // ____ XEventListener (base of XModifyListener) ____
     272                 :          0 : void SAL_CALL DataPoint::disposing( const lang::EventObject& )
     273                 :            :     throw (uno::RuntimeException)
     274                 :            : {
     275                 :            :     // nothing
     276                 :          0 : }
     277                 :            : 
     278                 :            : // ____ OPropertySet ____
     279                 :        412 : void DataPoint::firePropertyChangeEvent()
     280                 :            : {
     281                 :        412 :     fireModifyEvent();
     282                 :        412 : }
     283                 :            : 
     284                 :        412 : void DataPoint::fireModifyEvent()
     285                 :            : {
     286 [ +  - ][ +  - ]:        412 :     m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
                 [ +  - ]
     287                 :        412 : }
     288                 :            : 
     289                 :          0 : Sequence< OUString > DataPoint::getSupportedServiceNames_Static()
     290                 :            : {
     291                 :          0 :     Sequence< OUString > aServices( 3 );
     292 [ #  # ][ #  # ]:          0 :     aServices[ 0 ] = C2U( "com.sun.star.chart2.DataPoint" );
     293 [ #  # ][ #  # ]:          0 :     aServices[ 1 ] = C2U( "com.sun.star.chart2.DataPointProperties" );
     294 [ #  # ][ #  # ]:          0 :     aServices[ 2 ] = C2U( "com.sun.star.beans.PropertySet" );
     295                 :          0 :     return aServices;
     296                 :            : }
     297                 :            : 
     298                 :            : // needed by MSC compiler
     299                 :            : using impl::DataPoint_Base;
     300                 :            : 
     301 [ +  + ][ +  - ]:      19666 : IMPLEMENT_FORWARD_XINTERFACE2( DataPoint, DataPoint_Base, ::property::OPropertySet )
     302                 :            : 
     303                 :            : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     304 [ #  # ][ #  # ]:          0 : APPHELPER_XSERVICEINFO_IMPL( DataPoint, C2U( "com.sun.star.comp.chart.DataPoint" ));
         [ #  # ][ #  # ]
                 [ #  # ]
     305                 :            : 
     306                 :            : } //  namespace chart
     307                 :            : 
     308                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10