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

Generated by: LCOV version 1.10