LCOV - code coverage report
Current view: top level - libreoffice/chart2/source/model/main - DataPoint.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 48 106 45.3 %
Date: 2012-12-27 Functions: 15 28 53.6 %
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             : using ::rtl::OUString;
      41             : 
      42             : // ____________________________________________________________
      43             : 
      44             : namespace
      45             : {
      46             : 
      47             : struct StaticDataPointInfoHelper_Initializer
      48             : {
      49           1 :     ::cppu::OPropertyArrayHelper* operator()()
      50             :     {
      51           1 :         static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
      52           1 :         return &aPropHelper;
      53             :     }
      54             : 
      55             : private:
      56           1 :     Sequence< Property > lcl_GetPropertySequence()
      57             :     {
      58           1 :         ::std::vector< ::com::sun::star::beans::Property > aProperties;
      59           1 :         ::chart::DataPointProperties::AddPropertiesToVector( aProperties );
      60           1 :         ::chart::CharacterProperties::AddPropertiesToVector( aProperties );
      61           1 :         ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
      62             : 
      63             :         ::std::sort( aProperties.begin(), aProperties.end(),
      64           1 :                      ::chart::PropertyNameLess() );
      65             : 
      66           1 :         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          57 : DataPoint::DataPoint( const uno::Reference< beans::XPropertySet > & rParentProperties ) :
      96             :         ::property::OPropertySet( m_aMutex ),
      97             :         m_xParentProperties( rParentProperties ),
      98             :         m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
      99          57 :         m_bNoParentPropAllowed( false )
     100             : {
     101          57 :     SetNewValuesExplicitlyEvenIfTheyEqualDefault();
     102          57 : }
     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         171 : DataPoint::~DataPoint()
     134             : {
     135             :     try
     136             :     {
     137             :         // remove listener from XPropertySet properties
     138          57 :         Reference< beans::XPropertySet > xPropertySet;
     139          57 :         uno::Any aValue;
     140             : 
     141          57 :         getFastPropertyValue( aValue, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_X );
     142          57 :         if( ( aValue >>= xPropertySet )
     143           0 :             && xPropertySet.is())
     144           0 :             ModifyListenerHelper::removeListener( xPropertySet, m_xModifyEventForwarder );
     145             : 
     146          57 :         getFastPropertyValue( aValue, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_Y );
     147          57 :         if( ( aValue >>= xPropertySet )
     148           0 :             && xPropertySet.is())
     149           0 :             ModifyListenerHelper::removeListener( xPropertySet, m_xModifyEventForwarder );
     150             :     }
     151           0 :     catch( const uno::Exception & ex )
     152             :     {
     153             :         ASSERT_EXCEPTION( ex );
     154             :     }
     155         114 : }
     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        2523 : 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        2523 :     uno::Reference< beans::XFastPropertySet > xFast( m_xParentProperties.get(), uno::UNO_QUERY );
     185        2523 :     if( !xFast.is())
     186             :     {
     187             :         OSL_ENSURE( m_bNoParentPropAllowed, "data point needs a parent property set to provide values correctly" );
     188         114 :         return uno::Any();
     189             :     }
     190             : 
     191        2409 :     return xFast->getFastPropertyValue( nHandle );
     192             : }
     193             : 
     194        1287 : void SAL_CALL DataPoint::setFastPropertyValue_NoBroadcast(
     195             :     sal_Int32 nHandle, const uno::Any& rValue )
     196             :     throw (uno::Exception)
     197             : {
     198        1287 :     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        1287 :     ::property::OPropertySet::setFastPropertyValue_NoBroadcast( nHandle, rValue );
     221        1287 : }
     222             : 
     223        3362 : ::cppu::IPropertyArrayHelper & SAL_CALL DataPoint::getInfoHelper()
     224             : {
     225        3362 :     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          57 : void SAL_CALL DataPoint::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
     237             :     throw (uno::RuntimeException)
     238             : {
     239             :     try
     240             :     {
     241          57 :         uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     242          57 :         xBroadcaster->addModifyListener( aListener );
     243             :     }
     244           0 :     catch( const uno::Exception & ex )
     245             :     {
     246             :         ASSERT_EXCEPTION( ex );
     247             :     }
     248          57 : }
     249             : 
     250          57 : void SAL_CALL DataPoint::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
     251             :     throw (uno::RuntimeException)
     252             : {
     253             :     try
     254             :     {
     255          57 :         uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     256          57 :         xBroadcaster->removeModifyListener( aListener );
     257             :     }
     258           0 :     catch( const uno::Exception & ex )
     259             :     {
     260             :         ASSERT_EXCEPTION( ex );
     261             :     }
     262          57 : }
     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         511 : void DataPoint::firePropertyChangeEvent()
     280             : {
     281         511 :     fireModifyEvent();
     282         511 : }
     283             : 
     284         511 : void DataPoint::fireModifyEvent()
     285             : {
     286         511 :     m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
     287         511 : }
     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        9692 : 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