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

Generated by: LCOV version 1.11