LCOV - code coverage report
Current view: top level - chart2/source/model/template - ChartType.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 65 112 58.0 %
Date: 2012-08-25 Functions: 16 30 53.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 52 169 30.8 %

           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 "ChartType.hxx"
      21                 :            : #include "PropertyHelper.hxx"
      22                 :            : #include "CommonFunctors.hxx"
      23                 :            : #include "macros.hxx"
      24                 :            : #include "CartesianCoordinateSystem.hxx"
      25                 :            : #include "AxisHelper.hxx"
      26                 :            : #include "CloneHelper.hxx"
      27                 :            : #include "AxisIndexDefines.hxx"
      28                 :            : #include "ContainerHelper.hxx"
      29                 :            : #include <com/sun/star/chart2/AxisType.hpp>
      30                 :            : #include <com/sun/star/beans/PropertyAttribute.hpp>
      31                 :            : 
      32                 :            : using namespace ::com::sun::star;
      33                 :            : 
      34                 :            : using ::rtl::OUString;
      35                 :            : using ::com::sun::star::beans::Property;
      36                 :            : using ::com::sun::star::uno::Sequence;
      37                 :            : using ::com::sun::star::uno::Reference;
      38                 :            : using ::com::sun::star::uno::Any;
      39                 :            : using ::osl::MutexGuard;
      40                 :            : 
      41                 :            : namespace chart
      42                 :            : {
      43                 :            : 
      44                 :       1971 : ChartType::ChartType(
      45                 :            :     const Reference< uno::XComponentContext > & xContext ) :
      46                 :            :         ::property::OPropertySet( m_aMutex ),
      47                 :            :         m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
      48                 :            :         m_xContext( xContext ),
      49 [ +  - ][ +  - ]:       1971 :         m_bNotifyChanges( true )
         [ +  - ][ +  - ]
      50                 :       1971 : {}
      51                 :            : 
      52                 :          0 : ChartType::ChartType( const ChartType & rOther ) :
      53                 :            :         MutexContainer(),
      54                 :            :         impl::ChartType_Base(),
      55                 :            :         ::property::OPropertySet( rOther, m_aMutex ),
      56                 :            :     m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
      57                 :            :     m_xContext( rOther.m_xContext ),
      58 [ #  # ][ #  # ]:          0 :     m_bNotifyChanges( true )
         [ #  # ][ #  # ]
      59                 :            : {
      60         [ #  # ]:          0 :     CloneHelper::CloneRefVector< Reference< chart2::XDataSeries > >( rOther.m_aDataSeries, m_aDataSeries );
      61         [ #  # ]:          0 :     ModifyListenerHelper::addListenerToAllElements( m_aDataSeries, m_xModifyEventForwarder );
      62                 :          0 : }
      63                 :            : 
      64 [ +  - ][ +  - ]:       1971 : ChartType::~ChartType()
      65                 :            : {
      66         [ +  - ]:       1971 :     ModifyListenerHelper::removeListenerFromAllElements( m_aDataSeries, m_xModifyEventForwarder );
      67                 :       1971 :     m_aDataSeries.clear();
      68         [ -  + ]:       1971 : }
      69                 :            : 
      70                 :         94 : Reference< uno::XComponentContext > ChartType::GetComponentContext() const
      71                 :            : {
      72                 :         94 :     return m_xContext;
      73                 :            : }
      74                 :            : 
      75                 :            : // ____ XChartType ____
      76                 :            : Reference< chart2::XCoordinateSystem > SAL_CALL
      77                 :         84 :     ChartType::createCoordinateSystem( ::sal_Int32 DimensionCount )
      78                 :            :     throw (lang::IllegalArgumentException,
      79                 :            :            uno::RuntimeException)
      80                 :            : {
      81                 :            :     Reference< chart2::XCoordinateSystem > xResult(
      82                 :            :         new CartesianCoordinateSystem(
      83 [ +  - ][ +  - ]:         84 :             GetComponentContext(), DimensionCount, /* bSwapXAndYAxis */ sal_False ));
                 [ +  - ]
      84                 :            : 
      85         [ +  + ]:        258 :     for( sal_Int32 i=0; i<DimensionCount; ++i )
      86                 :            :     {
      87 [ +  - ][ +  - ]:        174 :         Reference< chart2::XAxis > xAxis( xResult->getAxisByDimension( i, MAIN_AXIS_INDEX ) );
      88         [ -  + ]:        174 :         if( !xAxis.is() )
      89                 :            :         {
      90                 :            :             OSL_FAIL("a created coordinate system should have an axis for each dimension");
      91                 :          0 :             continue;
      92                 :            :         }
      93                 :            : 
      94 [ +  - ][ +  - ]:        174 :         chart2::ScaleData aScaleData = xAxis->getScaleData();
      95                 :        174 :         aScaleData.Orientation = chart2::AxisOrientation_MATHEMATICAL;
      96 [ +  - ][ +  - ]:        174 :         aScaleData.Scaling = AxisHelper::createLinearScaling();
      97                 :            : 
      98      [ +  +  + ]:        174 :         switch( i )
      99                 :            :         {
     100                 :         84 :             case 0: aScaleData.AxisType = chart2::AxisType::CATEGORY; break;
     101                 :          6 :             case 2: aScaleData.AxisType = chart2::AxisType::SERIES; break;
     102                 :         84 :             default: aScaleData.AxisType = chart2::AxisType::REALNUMBER; break;
     103                 :            :         }
     104                 :            : 
     105 [ +  - ][ +  - ]:        174 :         xAxis->setScaleData( aScaleData );
     106 [ +  - ][ +  - ]:        174 :     }
     107                 :            : 
     108                 :         84 :     return xResult;
     109                 :            : }
     110                 :            : 
     111                 :          0 : Sequence< OUString > SAL_CALL ChartType::getSupportedMandatoryRoles()
     112                 :            :     throw (uno::RuntimeException)
     113                 :            : {
     114                 :          0 :     Sequence< OUString > aDefaultSeq(2);
     115 [ #  # ][ #  # ]:          0 :     aDefaultSeq[0] = C2U( "label" );
     116 [ #  # ][ #  # ]:          0 :     aDefaultSeq[1] = C2U( "values-y" );
     117                 :          0 :     return aDefaultSeq;
     118                 :            : }
     119                 :            : 
     120                 :          0 : Sequence< OUString > SAL_CALL ChartType::getSupportedOptionalRoles()
     121                 :            :     throw (uno::RuntimeException)
     122                 :            : {
     123                 :          0 :     return Sequence< OUString >();
     124                 :            : }
     125                 :            : 
     126                 :       9792 : OUString SAL_CALL ChartType::getRoleOfSequenceForSeriesLabel()
     127                 :            :     throw (uno::RuntimeException)
     128                 :            : {
     129                 :       9792 :     return C2U( "values-y" );
     130                 :            : }
     131                 :            : 
     132                 :        629 : void ChartType::impl_addDataSeriesWithoutNotification(
     133                 :            :         const Reference< chart2::XDataSeries >& xDataSeries )
     134                 :            : {
     135 [ +  - ][ -  + ]:       1258 :     if( ::std::find( m_aDataSeries.begin(), m_aDataSeries.end(), xDataSeries )
     136         [ +  - ]:       1258 :         != m_aDataSeries.end())
     137         [ #  # ]:          0 :         throw lang::IllegalArgumentException();
     138                 :            : 
     139                 :        629 :     m_aDataSeries.push_back( xDataSeries );
     140                 :        629 :     ModifyListenerHelper::addListener( xDataSeries, m_xModifyEventForwarder );
     141                 :        629 : }
     142                 :            : 
     143                 :            : // ____ XDataSeriesContainer ____
     144                 :         24 : void SAL_CALL ChartType::addDataSeries( const Reference< chart2::XDataSeries >& xDataSeries )
     145                 :            :     throw (lang::IllegalArgumentException,
     146                 :            :            uno::RuntimeException)
     147                 :            : {
     148                 :         24 :     impl_addDataSeriesWithoutNotification( xDataSeries );
     149                 :         24 :     fireModifyEvent();
     150                 :         24 : }
     151                 :            : 
     152                 :          0 : void SAL_CALL ChartType::removeDataSeries( const Reference< chart2::XDataSeries >& xDataSeries )
     153                 :            :     throw (container::NoSuchElementException,
     154                 :            :            uno::RuntimeException)
     155                 :            : {
     156         [ #  # ]:          0 :     if( !xDataSeries.is())
     157         [ #  # ]:          0 :         throw container::NoSuchElementException();
     158                 :            : 
     159                 :            :     tDataSeriesContainerType::iterator aIt(
     160         [ #  # ]:          0 :             ::std::find( m_aDataSeries.begin(), m_aDataSeries.end(), xDataSeries ) );
     161                 :            : 
     162 [ #  # ][ #  # ]:          0 :     if( aIt == m_aDataSeries.end())
     163                 :            :         throw container::NoSuchElementException(
     164                 :            :             C2U( "The given series is no element of this charttype" ),
     165 [ #  # ][ #  # ]:          0 :             static_cast< uno::XWeak * >( this ));
                 [ #  # ]
     166                 :            : 
     167         [ #  # ]:          0 :     ModifyListenerHelper::removeListener( xDataSeries, m_xModifyEventForwarder );
     168         [ #  # ]:          0 :     m_aDataSeries.erase( aIt );
     169         [ #  # ]:          0 :     fireModifyEvent();
     170                 :          0 : }
     171                 :            : 
     172                 :      26153 : Sequence< Reference< chart2::XDataSeries > > SAL_CALL ChartType::getDataSeries()
     173                 :            :     throw (uno::RuntimeException)
     174                 :            : {
     175                 :      26153 :     return ContainerHelper::ContainerToSequence( m_aDataSeries );
     176                 :            : }
     177                 :            : 
     178                 :        114 : void SAL_CALL ChartType::setDataSeries( const Sequence< Reference< chart2::XDataSeries > >& aDataSeries )
     179                 :            :     throw (lang::IllegalArgumentException,
     180                 :            :            uno::RuntimeException)
     181                 :            : {
     182                 :        114 :     m_bNotifyChanges = false;
     183                 :            :     try
     184                 :            :     {
     185         [ +  - ]:        114 :         Sequence< Reference< chart2::XDataSeries > > aOldSeries( this->getDataSeries() );
     186         [ +  + ]:        309 :         for( sal_Int32 nN=0; nN<aOldSeries.getLength(); ++nN )
     187 [ +  - ][ +  - ]:        195 :             ModifyListenerHelper::removeListener( aOldSeries[nN], m_xModifyEventForwarder );
     188                 :        114 :         m_aDataSeries.clear();
     189                 :            : 
     190         [ +  + ]:        719 :         for( sal_Int32 i=0; i<aDataSeries.getLength(); ++i )
     191 [ +  - ][ +  - ]:        719 :             impl_addDataSeriesWithoutNotification( aDataSeries[i] );
     192                 :            :     }
     193                 :          0 :     catch( ... )
     194                 :            :     {
     195                 :          0 :         m_bNotifyChanges = true;
     196                 :          0 :         throw;
     197                 :            :     }
     198                 :        114 :     m_bNotifyChanges = true;
     199                 :        114 :     fireModifyEvent();
     200                 :        114 : }
     201                 :            : 
     202                 :            : // ____ OPropertySet ____
     203                 :          0 : uno::Any ChartType::GetDefaultValue( sal_Int32 /* nHandle */ ) const
     204                 :            :     throw(beans::UnknownPropertyException)
     205                 :            : {
     206                 :          0 :     return uno::Any();
     207                 :            : }
     208                 :            : 
     209                 :            : namespace
     210                 :            : {
     211                 :            : 
     212                 :            : struct StaticChartTypeInfoHelper_Initializer
     213                 :            : {
     214                 :          0 :     ::cppu::OPropertyArrayHelper* operator()()
     215                 :            :     {
     216                 :            :         // using assignment for broken gcc 3.3
     217                 :            :         static ::cppu::OPropertyArrayHelper aPropHelper = ::cppu::OPropertyArrayHelper(
     218 [ #  # ][ #  # ]:          0 :             Sequence< beans::Property >() );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     219                 :          0 :         return &aPropHelper;
     220                 :            :     }
     221                 :            : };
     222                 :            : 
     223                 :            : struct StaticChartTypeInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticChartTypeInfoHelper_Initializer >
     224                 :            : {
     225                 :            : };
     226                 :            : 
     227                 :            : struct StaticChartTypeInfo_Initializer
     228                 :            : {
     229                 :          0 :     uno::Reference< beans::XPropertySetInfo >* operator()()
     230                 :            :     {
     231                 :            :         static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
     232 [ #  # ][ #  # ]:          0 :             ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticChartTypeInfoHelper::get() ) );
         [ #  # ][ #  # ]
                 [ #  # ]
     233                 :          0 :         return &xPropertySetInfo;
     234                 :            :     }
     235                 :            : };
     236                 :            : 
     237                 :            : struct StaticChartTypeInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticChartTypeInfo_Initializer >
     238                 :            : {
     239                 :            : };
     240                 :            : 
     241                 :            : }
     242                 :            : 
     243                 :            : // ____ OPropertySet ____
     244                 :          0 : ::cppu::IPropertyArrayHelper & SAL_CALL ChartType::getInfoHelper()
     245                 :            : {
     246                 :          0 :     return *StaticChartTypeInfoHelper::get();
     247                 :            : }
     248                 :            : 
     249                 :            : // ____ XPropertySet ____
     250                 :          0 : uno::Reference< beans::XPropertySetInfo > SAL_CALL ChartType::getPropertySetInfo()
     251                 :            :     throw (uno::RuntimeException)
     252                 :            : {
     253                 :          0 :     return *StaticChartTypeInfo::get();
     254                 :            : }
     255                 :            : 
     256                 :            : // ____ XModifyBroadcaster ____
     257                 :        100 : void SAL_CALL ChartType::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
     258                 :            :     throw (uno::RuntimeException)
     259                 :            : {
     260                 :            :     try
     261                 :            :     {
     262         [ +  - ]:        100 :         uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     263 [ +  - ][ +  - ]:        100 :         xBroadcaster->addModifyListener( aListener );
                 [ #  # ]
     264                 :            :     }
     265                 :          0 :     catch( const uno::Exception & ex )
     266                 :            :     {
     267                 :            :         ASSERT_EXCEPTION( ex );
     268                 :            :     }
     269                 :        100 : }
     270                 :            : 
     271                 :        100 : void SAL_CALL ChartType::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
     272                 :            :     throw (uno::RuntimeException)
     273                 :            : {
     274                 :            :     try
     275                 :            :     {
     276         [ +  - ]:        100 :         uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     277 [ +  - ][ +  - ]:        100 :         xBroadcaster->removeModifyListener( aListener );
                 [ #  # ]
     278                 :            :     }
     279                 :          0 :     catch( const uno::Exception & ex )
     280                 :            :     {
     281                 :            :         ASSERT_EXCEPTION( ex );
     282                 :            :     }
     283                 :        100 : }
     284                 :            : 
     285                 :            : // ____ XModifyListener ____
     286                 :          0 : void SAL_CALL ChartType::modified( const lang::EventObject& aEvent )
     287                 :            :     throw (uno::RuntimeException)
     288                 :            : {
     289                 :          0 :     m_xModifyEventForwarder->modified( aEvent );
     290                 :          0 : }
     291                 :            : 
     292                 :            : // ____ XEventListener (base of XModifyListener) ____
     293                 :          0 : void SAL_CALL ChartType::disposing( const lang::EventObject& /* Source */ )
     294                 :            :     throw (uno::RuntimeException)
     295                 :            : {
     296                 :            :     // nothing
     297                 :          0 : }
     298                 :            : 
     299                 :            : // ____ OPropertySet ____
     300                 :       1060 : void ChartType::firePropertyChangeEvent()
     301                 :            : {
     302                 :       1060 :     fireModifyEvent();
     303                 :       1060 : }
     304                 :            : 
     305                 :       1198 : void ChartType::fireModifyEvent()
     306                 :            : {
     307         [ +  - ]:       1198 :     if( m_bNotifyChanges )
     308 [ +  - ][ +  - ]:       1198 :         m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
                 [ +  - ]
     309                 :       1198 : }
     310                 :            : 
     311                 :            : // ================================================================================
     312                 :            : 
     313                 :            : using impl::ChartType_Base;
     314                 :            : 
     315 [ +  + ][ +  - ]:     335278 : IMPLEMENT_FORWARD_XINTERFACE2( ChartType, ChartType_Base, ::property::OPropertySet )
     316 [ #  # ][ #  # ]:          0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( ChartType, ChartType_Base, ::property::OPropertySet )
                 [ #  # ]
     317                 :            : 
     318                 :            : } //  namespace chart
     319                 :            : 
     320                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10