LCOV - code coverage report
Current view: top level - libreoffice/chart2/source/tools - ErrorBar.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 3 114 2.6 %
Date: 2012-12-27 Functions: 3 38 7.9 %
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 "ErrorBar.hxx"
      21             : #include "macros.hxx"
      22             : #include "LineProperties.hxx"
      23             : #include "ContainerHelper.hxx"
      24             : #include "EventListenerHelper.hxx"
      25             : #include "PropertyHelper.hxx"
      26             : #include "CloneHelper.hxx"
      27             : 
      28             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      29             : #include <com/sun/star/chart/ErrorBarStyle.hpp>
      30             : 
      31             : #include <rtl/math.hxx>
      32             : #include <rtl/ustrbuf.hxx>
      33             : 
      34             : using namespace ::com::sun::star;
      35             : 
      36             : using ::rtl::OUString;
      37             : using ::rtl::OUStringBuffer;
      38             : using ::com::sun::star::beans::Property;
      39             : using ::osl::MutexGuard;
      40             : 
      41             : namespace
      42             : {
      43           1 : static const OUString lcl_aServiceName(
      44             :     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.ErrorBar" ));
      45             : 
      46             : enum
      47             : {
      48             :     PROP_ERROR_BAR_STYLE,
      49             :     PROP_ERROR_BAR_POS_ERROR,
      50             :     PROP_ERROR_BAR_NEG_ERROR,
      51             :     PROP_ERROR_BAR_WEIGHT,
      52             :     PROP_ERROR_BAR_SHOW_POS_ERROR,
      53             :     PROP_ERROR_BAR_SHOW_NEG_ERROR
      54             : };
      55             : 
      56           0 : void lcl_AddPropertiesToVector(
      57             :     ::std::vector< Property > & rOutProperties )
      58             : {
      59             :     rOutProperties.push_back(
      60             :         Property( C2U( "ErrorBarStyle" ),
      61             :                   PROP_ERROR_BAR_STYLE,
      62           0 :                   ::getCppuType( reinterpret_cast< sal_Int32 * >(0)),
      63             :                   beans::PropertyAttribute::BOUND
      64           0 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
      65             : 
      66             :     rOutProperties.push_back(
      67             :         Property( C2U( "PositiveError" ),
      68             :                   PROP_ERROR_BAR_POS_ERROR,
      69           0 :                   ::getCppuType( reinterpret_cast< const double * >(0)),
      70             :                   beans::PropertyAttribute::BOUND
      71           0 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
      72             :     rOutProperties.push_back(
      73             :         Property( C2U( "NegativeError" ),
      74             :                   PROP_ERROR_BAR_NEG_ERROR,
      75           0 :                   ::getCppuType( reinterpret_cast< const double * >(0)),
      76             :                   beans::PropertyAttribute::BOUND
      77           0 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
      78             : 
      79             :     rOutProperties.push_back(
      80             :         Property( C2U( "Weight" ),
      81             :                   PROP_ERROR_BAR_WEIGHT,
      82           0 :                   ::getCppuType( reinterpret_cast< const double * >(0)),
      83             :                   beans::PropertyAttribute::BOUND
      84           0 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
      85             : 
      86             :     rOutProperties.push_back(
      87             :         Property( C2U( "ShowPositiveError" ),
      88             :                   PROP_ERROR_BAR_SHOW_POS_ERROR,
      89           0 :                   ::getBooleanCppuType(),
      90             :                   beans::PropertyAttribute::BOUND
      91           0 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
      92             :     rOutProperties.push_back(
      93             :         Property( C2U( "ShowNegativeError" ),
      94             :                   PROP_ERROR_BAR_SHOW_NEG_ERROR,
      95           0 :                   ::getBooleanCppuType(),
      96             :                   beans::PropertyAttribute::BOUND
      97           0 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
      98           0 : }
      99             : 
     100             : struct StaticErrorBarDefaults_Initializer
     101             : {
     102           0 :     ::chart::tPropertyValueMap* operator()()
     103             :     {
     104           0 :         static ::chart::tPropertyValueMap aStaticDefaults;
     105           0 :         lcl_AddDefaultsToMap( aStaticDefaults );
     106           0 :         return &aStaticDefaults;
     107             :     }
     108             : private:
     109           0 :     void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
     110             :     {
     111           0 :         ::chart::LineProperties::AddDefaultsToMap( rOutMap );
     112             : 
     113           0 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_ERROR_BAR_STYLE, ::com::sun::star::chart::ErrorBarStyle::NONE );
     114           0 :         ::chart::PropertyHelper::setPropertyValueDefault< double >( rOutMap, PROP_ERROR_BAR_POS_ERROR, 0.0 );
     115           0 :         ::chart::PropertyHelper::setPropertyValueDefault< double >( rOutMap, PROP_ERROR_BAR_NEG_ERROR, 0.0 );
     116           0 :         ::chart::PropertyHelper::setPropertyValueDefault< double >( rOutMap, PROP_ERROR_BAR_WEIGHT, 1.0 );
     117           0 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_ERROR_BAR_SHOW_POS_ERROR, true );
     118           0 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_ERROR_BAR_SHOW_NEG_ERROR, true );
     119           0 :     }
     120             : };
     121             : 
     122             : struct StaticErrorBarDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticErrorBarDefaults_Initializer >
     123             : {
     124             : };
     125             : 
     126             : struct StaticErrorBarInfoHelper_Initializer
     127             : {
     128           0 :     ::cppu::OPropertyArrayHelper* operator()()
     129             :     {
     130           0 :         static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
     131           0 :         return &aPropHelper;
     132             :     }
     133             : 
     134             : private:
     135           0 :     uno::Sequence< Property > lcl_GetPropertySequence()
     136             :     {
     137           0 :         ::std::vector< ::com::sun::star::beans::Property > aProperties;
     138           0 :         lcl_AddPropertiesToVector( aProperties );
     139           0 :         ::chart::LineProperties::AddPropertiesToVector( aProperties );
     140             : 
     141             :         ::std::sort( aProperties.begin(), aProperties.end(),
     142           0 :                      ::chart::PropertyNameLess() );
     143             : 
     144           0 :         return ::chart::ContainerHelper::ContainerToSequence( aProperties );
     145             :     }
     146             : 
     147             : };
     148             : 
     149             : struct StaticErrorBarInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticErrorBarInfoHelper_Initializer >
     150             : {
     151             : };
     152             : 
     153             : struct StaticErrorBarInfo_Initializer
     154             : {
     155           0 :     uno::Reference< beans::XPropertySetInfo >* operator()()
     156             :     {
     157             :         static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
     158           0 :             ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticErrorBarInfoHelper::get() ) );
     159           0 :         return &xPropertySetInfo;
     160             :     }
     161             : };
     162             : 
     163             : struct StaticErrorBarInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticErrorBarInfo_Initializer >
     164             : {
     165             : };
     166             : 
     167           0 : bool lcl_isInternalData( const uno::Reference< chart2::data::XLabeledDataSequence > & xLSeq )
     168             : {
     169           0 :     uno::Reference< lang::XServiceInfo > xServiceInfo( xLSeq, uno::UNO_QUERY );
     170           0 :     return ( xServiceInfo.is() && xServiceInfo->getImplementationName() == "com.sun.star.comp.chart2.LabeledDataSequence" );
     171             : }
     172             : 
     173             : } // anonymous namespace
     174             : 
     175             : namespace chart
     176             : {
     177             : 
     178           0 : uno::Reference< beans::XPropertySet > createErrorBar( const uno::Reference< uno::XComponentContext > & xContext )
     179             : {
     180           0 :     return new ErrorBar( xContext );
     181             : }
     182             : 
     183           0 : ErrorBar::ErrorBar(
     184             :     uno::Reference< uno::XComponentContext > const & xContext ) :
     185             :         ::property::OPropertySet( m_aMutex ),
     186             :     m_xContext( xContext ),
     187           0 :     m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
     188           0 : {}
     189             : 
     190           0 : ErrorBar::ErrorBar( const ErrorBar & rOther ) :
     191             :         MutexContainer(),
     192             :         impl::ErrorBar_Base(),
     193             :         ::property::OPropertySet( rOther, m_aMutex ),
     194             :     m_xContext( rOther.m_xContext ),
     195           0 :     m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
     196             : {
     197           0 :     if( ! rOther.m_aDataSequences.empty())
     198             :     {
     199           0 :         if( lcl_isInternalData( rOther.m_aDataSequences.front()))
     200             :             CloneHelper::CloneRefVector< tDataSequenceContainer::value_type >(
     201           0 :                 rOther.m_aDataSequences, m_aDataSequences );
     202             :         else
     203           0 :             m_aDataSequences = rOther.m_aDataSequences;
     204           0 :         ModifyListenerHelper::addListenerToAllElements( m_aDataSequences, m_xModifyEventForwarder );
     205             :     }
     206           0 : }
     207             : 
     208           0 : ErrorBar::~ErrorBar()
     209           0 : {}
     210             : 
     211           0 : uno::Reference< util::XCloneable > SAL_CALL ErrorBar::createClone()
     212             :     throw (uno::RuntimeException)
     213             : {
     214           0 :     return uno::Reference< util::XCloneable >( new ErrorBar( *this ));
     215             : }
     216             : 
     217             : // ================================================================================
     218             : 
     219             : // ____ OPropertySet ____
     220           0 : uno::Any ErrorBar::GetDefaultValue( sal_Int32 nHandle ) const
     221             :     throw(beans::UnknownPropertyException)
     222             : {
     223           0 :     const tPropertyValueMap& rStaticDefaults = *StaticErrorBarDefaults::get();
     224           0 :     tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
     225           0 :     if( aFound == rStaticDefaults.end() )
     226           0 :         return uno::Any();
     227           0 :     return (*aFound).second;
     228             : }
     229             : 
     230           0 : ::cppu::IPropertyArrayHelper & SAL_CALL ErrorBar::getInfoHelper()
     231             : {
     232           0 :     return *StaticErrorBarInfoHelper::get();
     233             : }
     234             : 
     235             : // ____ XPropertySet ____
     236           0 : uno::Reference< beans::XPropertySetInfo > SAL_CALL ErrorBar::getPropertySetInfo()
     237             :     throw (uno::RuntimeException)
     238             : {
     239           0 :     return *StaticErrorBarInfo::get();
     240             : }
     241             : 
     242             : // ____ XModifyBroadcaster ____
     243           0 : void SAL_CALL ErrorBar::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
     244             :     throw (uno::RuntimeException)
     245             : {
     246             :     try
     247             :     {
     248           0 :         uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     249           0 :         xBroadcaster->addModifyListener( aListener );
     250             :     }
     251           0 :     catch( const uno::Exception & ex )
     252             :     {
     253             :         ASSERT_EXCEPTION( ex );
     254             :     }
     255           0 : }
     256             : 
     257           0 : void SAL_CALL ErrorBar::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
     258             :     throw (uno::RuntimeException)
     259             : {
     260             :     try
     261             :     {
     262           0 :         uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     263           0 :         xBroadcaster->removeModifyListener( aListener );
     264             :     }
     265           0 :     catch( const uno::Exception & ex )
     266             :     {
     267             :         ASSERT_EXCEPTION( ex );
     268             :     }
     269           0 : }
     270             : 
     271             : // ____ XModifyListener ____
     272           0 : void SAL_CALL ErrorBar::modified( const lang::EventObject& aEvent )
     273             :     throw (uno::RuntimeException)
     274             : {
     275           0 :     m_xModifyEventForwarder->modified( aEvent );
     276           0 : }
     277             : 
     278             : // ____ XEventListener (base of XModifyListener) ____
     279           0 : void SAL_CALL ErrorBar::disposing( const lang::EventObject& /* Source */ )
     280             :     throw (uno::RuntimeException)
     281             : {
     282             :     // nothing
     283           0 : }
     284             : 
     285             : // ____ XDataSink ____
     286           0 : void SAL_CALL ErrorBar::setData( const uno::Sequence< uno::Reference< chart2::data::XLabeledDataSequence > >& aData )
     287             :     throw (uno::RuntimeException)
     288             : {
     289           0 :     ModifyListenerHelper::removeListenerFromAllElements( m_aDataSequences, m_xModifyEventForwarder );
     290           0 :     EventListenerHelper::removeListenerFromAllElements( m_aDataSequences, this );
     291           0 :     m_aDataSequences = ContainerHelper::SequenceToVector( aData );
     292           0 :     EventListenerHelper::addListenerToAllElements( m_aDataSequences, this );
     293           0 :     ModifyListenerHelper::addListenerToAllElements( m_aDataSequences, m_xModifyEventForwarder );
     294           0 : }
     295             : 
     296             : // ____ XDataSource ____
     297           0 : uno::Sequence< uno::Reference< chart2::data::XLabeledDataSequence > > SAL_CALL ErrorBar::getDataSequences()
     298             :     throw (uno::RuntimeException)
     299             : {
     300           0 :     return ContainerHelper::ContainerToSequence( m_aDataSequences );
     301             : }
     302             : 
     303             : // ____ XChild ____
     304           0 : uno::Reference< uno::XInterface > SAL_CALL ErrorBar::getParent()
     305             :     throw (uno::RuntimeException)
     306             : {
     307           0 :     return m_xParent;
     308             : }
     309             : 
     310           0 : void SAL_CALL ErrorBar::setParent(
     311             :     const uno::Reference< uno::XInterface >& Parent )
     312             :     throw (lang::NoSupportException,
     313             :            uno::RuntimeException)
     314             : {
     315           0 :     m_xParent.set( Parent );
     316           0 : }
     317             : 
     318             : // ____ OPropertySet ____
     319           0 : void ErrorBar::firePropertyChangeEvent()
     320             : {
     321           0 :     fireModifyEvent();
     322           0 : }
     323             : 
     324           0 : void ErrorBar::fireModifyEvent()
     325             : {
     326           0 :     m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
     327           0 : }
     328             : 
     329             : // ================================================================================
     330             : 
     331           0 : uno::Sequence< ::rtl::OUString > ErrorBar::getSupportedServiceNames_Static()
     332             : {
     333           0 :     uno::Sequence< ::rtl::OUString > aServices( 2 );
     334           0 :     aServices[ 0 ] = lcl_aServiceName;
     335           0 :     aServices[ 1 ] = C2U( "com.sun.star.chart2.ErrorBar" );
     336           0 :     return aServices;
     337             : }
     338             : 
     339             : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     340           3 : APPHELPER_XSERVICEINFO_IMPL( ErrorBar, lcl_aServiceName );
     341             : 
     342             : // needed by MSC compiler
     343             : using impl::ErrorBar_Base;
     344             : 
     345           0 : IMPLEMENT_FORWARD_XINTERFACE2( ErrorBar, ErrorBar_Base, OPropertySet )
     346           0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( ErrorBar, ErrorBar_Base, OPropertySet )
     347             : 
     348           3 : } //  namespace chart
     349             : 
     350             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10