LCOV - code coverage report
Current view: top level - chart2/source/model/main - BaseCoordinateSystem.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 118 151 78.1 %
Date: 2014-11-03 Functions: 27 34 79.4 %
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 "BaseCoordinateSystem.hxx"
      21             : #include "macros.hxx"
      22             : #include "PropertyHelper.hxx"
      23             : #include "UserDefinedProperties.hxx"
      24             : #include "ContainerHelper.hxx"
      25             : #include "CloneHelper.hxx"
      26             : #include "Axis.hxx"
      27             : #include "AxisHelper.hxx"
      28             : #include <com/sun/star/chart2/AxisType.hpp>
      29             : 
      30             : #include <algorithm>
      31             : #include <iterator>
      32             : 
      33             : #if OSL_DEBUG_LEVEL > 1
      34             : #include <rtl/math.hxx>
      35             : #endif
      36             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      37             : 
      38             : using namespace ::com::sun::star;
      39             : using ::com::sun::star::uno::Reference;
      40             : using ::com::sun::star::uno::Sequence;
      41             : using ::com::sun::star::beans::Property;
      42             : 
      43             : namespace
      44             : {
      45             : enum
      46             : {
      47             :     PROP_COORDINATESYSTEM_SWAPXANDYAXIS
      48             : };
      49             : 
      50          26 : void lcl_AddPropertiesToVector(
      51             :     ::std::vector< Property > & rOutProperties )
      52             : {
      53             :     rOutProperties.push_back(
      54             :         Property( "SwapXAndYAxis",
      55             :                   PROP_COORDINATESYSTEM_SWAPXANDYAXIS,
      56          26 :                   ::getBooleanCppuType(),
      57             :                   beans::PropertyAttribute::BOUND
      58          52 :                   | beans::PropertyAttribute::MAYBEVOID ));
      59          26 : }
      60             : 
      61             : struct StaticCooSysDefaults_Initializer
      62             : {
      63          30 :     ::chart::tPropertyValueMap* operator()()
      64             :     {
      65          30 :         static ::chart::tPropertyValueMap aStaticDefaults;
      66          30 :         lcl_AddDefaultsToMap( aStaticDefaults );
      67          30 :         return &aStaticDefaults;
      68             :     }
      69             : private:
      70          30 :     void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
      71             :     {
      72          30 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_COORDINATESYSTEM_SWAPXANDYAXIS, false );
      73          30 :     }
      74             : };
      75             : 
      76             : struct StaticCooSysDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticCooSysDefaults_Initializer >
      77             : {
      78             : };
      79             : 
      80             : struct StaticCooSysInfoHelper_Initializer
      81             : {
      82          26 :     ::cppu::OPropertyArrayHelper* operator()()
      83             :     {
      84          26 :         static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
      85          26 :         return &aPropHelper;
      86             :     }
      87             : 
      88             : private:
      89          26 :     Sequence< Property > lcl_GetPropertySequence()
      90             :     {
      91          26 :         ::std::vector< ::com::sun::star::beans::Property > aProperties;
      92          26 :         lcl_AddPropertiesToVector( aProperties );
      93          26 :         ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
      94             : 
      95             :         ::std::sort( aProperties.begin(), aProperties.end(),
      96          26 :                      ::chart::PropertyNameLess() );
      97             : 
      98          26 :         return ::chart::ContainerHelper::ContainerToSequence( aProperties );
      99             :     }
     100             : };
     101             : 
     102             : struct StaticCooSysInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticCooSysInfoHelper_Initializer >
     103             : {
     104             : };
     105             : 
     106             : struct StaticCooSysInfo_Initializer
     107             : {
     108           4 :     uno::Reference< beans::XPropertySetInfo >* operator()()
     109             :     {
     110             :         static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
     111           4 :             ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticCooSysInfoHelper::get() ) );
     112           4 :         return &xPropertySetInfo;
     113             :     }
     114             : };
     115             : 
     116             : struct StaticCooSysInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticCooSysInfo_Initializer >
     117             : {
     118             : };
     119             : 
     120             : } // anonymous namespace
     121             : 
     122             : namespace chart
     123             : {
     124             : 
     125         712 : BaseCoordinateSystem::BaseCoordinateSystem(
     126             :     const Reference< uno::XComponentContext > & xContext,
     127             :     sal_Int32 nDimensionCount /* = 2 */,
     128             :     bool bSwapXAndYAxis /* = sal_False */ ) :
     129             :         ::property::OPropertySet( m_aMutex ),
     130             :         m_xContext( xContext ),
     131             :         m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
     132         712 :         m_nDimensionCount( nDimensionCount )
     133             :  {
     134         712 :     m_aAllAxis.resize( m_nDimensionCount );
     135        2280 :     for( sal_Int32 nN=0; nN<m_nDimensionCount; nN++ )
     136             :     {
     137        1568 :         m_aAllAxis[nN].resize( 1 );
     138        1568 :         Reference< chart2::XAxis > xAxis( new Axis(m_xContext) );
     139        1568 :         m_aAllAxis[nN][0] = xAxis;
     140             : 
     141        1568 :         ModifyListenerHelper::addListenerToAllElements( m_aAllAxis[nN], m_xModifyEventForwarder );
     142        3136 :         chart2::ScaleData aScaleData( xAxis->getScaleData() );
     143        1568 :         if(nN==0)
     144             :         {
     145         712 :             aScaleData.AxisType = chart2::AxisType::CATEGORY;
     146             :         }
     147         856 :         else if( nN==1)
     148             :         {
     149         712 :             aScaleData.AxisType = chart2::AxisType::REALNUMBER;
     150             :         }
     151         144 :         else if( nN==2)
     152             :         {
     153         144 :             aScaleData.AxisType = chart2::AxisType::SERIES;
     154             :         }
     155        1568 :         xAxis->setScaleData( aScaleData );
     156        1568 :     }
     157             : 
     158         712 :     m_aOrigin.realloc( m_nDimensionCount );
     159        2280 :     for( sal_Int32 i = 0; i < m_nDimensionCount; ++i )
     160        1568 :         m_aOrigin[ i ] = uno::makeAny( double( 0.0 ) );
     161             : 
     162         712 :     setFastPropertyValue_NoBroadcast( PROP_COORDINATESYSTEM_SWAPXANDYAXIS, uno::makeAny( bSwapXAndYAxis ));
     163         712 : }
     164             : 
     165             : // explicit
     166           0 : BaseCoordinateSystem::BaseCoordinateSystem(
     167             :     const BaseCoordinateSystem & rSource ) :
     168             :         impl::BaseCoordinateSystem_Base(),
     169             :         MutexContainer(),
     170             :         ::property::OPropertySet( rSource, m_aMutex ),
     171             :     m_xContext( rSource.m_xContext ),
     172             :     m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
     173             :     m_nDimensionCount( rSource.m_nDimensionCount ),
     174           0 :     m_aOrigin( rSource.m_aOrigin )
     175             : {
     176           0 :     m_aAllAxis.resize(rSource.m_aAllAxis.size());
     177           0 :     tAxisVecVecType::size_type nN=0;
     178           0 :     for( nN=0; nN<m_aAllAxis.size(); nN++ )
     179           0 :         CloneHelper::CloneRefVector< Reference< chart2::XAxis > >( rSource.m_aAllAxis[nN], m_aAllAxis[nN] );
     180           0 :     CloneHelper::CloneRefVector< Reference< chart2::XChartType > >( rSource.m_aChartTypes, m_aChartTypes );
     181             : 
     182           0 :     for( nN=0; nN<m_aAllAxis.size(); nN++ )
     183           0 :         ModifyListenerHelper::addListenerToAllElements( m_aAllAxis[nN], m_xModifyEventForwarder );
     184           0 :     ModifyListenerHelper::addListenerToAllElements( m_aChartTypes, m_xModifyEventForwarder );
     185           0 : }
     186             : 
     187        1372 : BaseCoordinateSystem::~BaseCoordinateSystem()
     188             : {
     189             :     try
     190             :     {
     191        2202 :         for( tAxisVecVecType::size_type nN=0; nN<m_aAllAxis.size(); nN++ )
     192        1516 :             ModifyListenerHelper::removeListenerFromAllElements( m_aAllAxis[nN], m_xModifyEventForwarder );
     193         686 :         ModifyListenerHelper::removeListenerFromAllElements( m_aChartTypes, m_xModifyEventForwarder );
     194             :     }
     195           0 :     catch( const uno::Exception & ex )
     196             :     {
     197             :         ASSERT_EXCEPTION( ex );
     198             :     }
     199         686 : }
     200             : 
     201             : // ____ XCoordinateSystem ____
     202     2495756 : sal_Int32 SAL_CALL BaseCoordinateSystem::getDimension()
     203             :     throw (uno::RuntimeException, std::exception)
     204             : {
     205     2495756 :     return m_nDimensionCount;
     206             : }
     207             : 
     208         692 : void SAL_CALL BaseCoordinateSystem::setAxisByDimension(
     209             :     sal_Int32 nDimensionIndex,
     210             :     const Reference< chart2::XAxis >& xAxis,
     211             :     sal_Int32 nIndex )
     212             :     throw (lang::IndexOutOfBoundsException,
     213             :            uno::RuntimeException, std::exception)
     214             : {
     215         692 :     if( nDimensionIndex < 0 || nDimensionIndex >= getDimension() )
     216           0 :         throw lang::IndexOutOfBoundsException();
     217             : 
     218         692 :     if( nIndex < 0 )
     219           0 :         throw lang::IndexOutOfBoundsException();
     220             : 
     221         692 :     if( m_aAllAxis[ nDimensionIndex ].size() < static_cast< tAxisVecVecType::size_type >( nIndex+1 ))
     222             :     {
     223          60 :         m_aAllAxis[ nDimensionIndex ].resize( nIndex+1 );
     224          60 :         m_aAllAxis[ nDimensionIndex ][nIndex] = 0;
     225             :     }
     226             : 
     227         692 :     Reference< chart2::XAxis > xOldAxis( m_aAllAxis[ nDimensionIndex ][nIndex] );
     228         692 :     if( xOldAxis.is())
     229         632 :         ModifyListenerHelper::removeListener( xOldAxis, m_xModifyEventForwarder );
     230         692 :     m_aAllAxis[ nDimensionIndex ][nIndex] = xAxis;
     231         692 :     if( xAxis.is())
     232         692 :         ModifyListenerHelper::addListener( xAxis, m_xModifyEventForwarder );
     233         692 :     fireModifyEvent();
     234         692 : }
     235             : 
     236      594218 : Reference< chart2::XAxis > SAL_CALL BaseCoordinateSystem::getAxisByDimension(
     237             :             sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex )
     238             :     throw (lang::IndexOutOfBoundsException,
     239             :            uno::RuntimeException, std::exception)
     240             : {
     241      594218 :     if( nDimensionIndex < 0 || nDimensionIndex >= getDimension() )
     242         664 :         throw lang::IndexOutOfBoundsException();
     243             : 
     244             :     OSL_ASSERT( m_aAllAxis.size() == static_cast< size_t >( getDimension()));
     245             : 
     246      593554 :     if( nAxisIndex < 0 || nAxisIndex > this->getMaximumAxisIndexByDimension(nDimensionIndex) )
     247        3008 :         throw lang::IndexOutOfBoundsException();
     248             : 
     249      590546 :     return m_aAllAxis[ nDimensionIndex ][nAxisIndex];
     250             : }
     251             : 
     252     1174868 : sal_Int32 SAL_CALL BaseCoordinateSystem::getMaximumAxisIndexByDimension( sal_Int32 nDimensionIndex )
     253             :         throw (lang::IndexOutOfBoundsException,
     254             :            uno::RuntimeException, std::exception)
     255             : {
     256     1174868 :     if( nDimensionIndex < 0 || nDimensionIndex >= getDimension() )
     257           0 :         throw lang::IndexOutOfBoundsException();
     258             : 
     259             :     OSL_ASSERT( m_aAllAxis.size() == static_cast< size_t >( getDimension()));
     260             : 
     261     1174868 :     sal_Int32 nRet = m_aAllAxis[ nDimensionIndex ].size();
     262     1174868 :     if(nRet)
     263     1174868 :         nRet-=1;
     264             : 
     265     1174868 :     return nRet;
     266             : }
     267             : 
     268             : // ____ XChartTypeContainer ____
     269         402 : void SAL_CALL BaseCoordinateSystem::addChartType( const Reference< chart2::XChartType >& aChartType )
     270             :     throw (lang::IllegalArgumentException,
     271             :            uno::RuntimeException, std::exception)
     272             : {
     273        1206 :     if( ::std::find( m_aChartTypes.begin(), m_aChartTypes.end(), aChartType )
     274        1206 :         != m_aChartTypes.end())
     275           0 :         throw lang::IllegalArgumentException();
     276             : 
     277         402 :     m_aChartTypes.push_back( aChartType );
     278         402 :     ModifyListenerHelper::addListener( aChartType, m_xModifyEventForwarder );
     279         402 :     fireModifyEvent();
     280         402 : }
     281             : 
     282           0 : void SAL_CALL BaseCoordinateSystem::removeChartType( const Reference< chart2::XChartType >& aChartType )
     283             :     throw (container::NoSuchElementException,
     284             :            uno::RuntimeException, std::exception)
     285             : {
     286             :     ::std::vector< uno::Reference< chart2::XChartType > >::iterator
     287           0 :           aIt( ::std::find( m_aChartTypes.begin(), m_aChartTypes.end(), aChartType ));
     288           0 :     if( aIt == m_aChartTypes.end())
     289             :         throw container::NoSuchElementException(
     290             :             "The given chart type is no element of the container",
     291           0 :             static_cast< uno::XWeak * >( this ));
     292             : 
     293           0 :     m_aChartTypes.erase( aIt );
     294           0 :     ModifyListenerHelper::removeListener( aChartType, m_xModifyEventForwarder );
     295           0 :     fireModifyEvent();
     296           0 : }
     297             : 
     298      328946 : Sequence< Reference< chart2::XChartType > > SAL_CALL BaseCoordinateSystem::getChartTypes()
     299             :     throw (uno::RuntimeException, std::exception)
     300             : {
     301      328946 :     return ContainerHelper::ContainerToSequence( m_aChartTypes );
     302             : }
     303             : 
     304         366 : void SAL_CALL BaseCoordinateSystem::setChartTypes( const Sequence< Reference< chart2::XChartType > >& aChartTypes )
     305             :     throw (lang::IllegalArgumentException,
     306             :            uno::RuntimeException, std::exception)
     307             : {
     308         366 :     ModifyListenerHelper::removeListenerFromAllElements( m_aChartTypes, m_xModifyEventForwarder );
     309         366 :     m_aChartTypes = ContainerHelper::SequenceToVector( aChartTypes );
     310         366 :     ModifyListenerHelper::addListenerToAllElements( m_aChartTypes, m_xModifyEventForwarder );
     311         366 :     fireModifyEvent();
     312         366 : }
     313             : 
     314             : // ____ XModifyBroadcaster ____
     315         678 : void SAL_CALL BaseCoordinateSystem::addModifyListener( const Reference< util::XModifyListener >& aListener )
     316             :     throw (uno::RuntimeException, std::exception)
     317             : {
     318             :     try
     319             :     {
     320         678 :         Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     321         678 :         xBroadcaster->addModifyListener( aListener );
     322             :     }
     323           0 :     catch( const uno::Exception & ex )
     324             :     {
     325             :         ASSERT_EXCEPTION( ex );
     326             :     }
     327         678 : }
     328             : 
     329         678 : void SAL_CALL BaseCoordinateSystem::removeModifyListener( const Reference< util::XModifyListener >& aListener )
     330             :     throw (uno::RuntimeException, std::exception)
     331             : {
     332             :     try
     333             :     {
     334         678 :         Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     335         678 :         xBroadcaster->removeModifyListener( aListener );
     336             :     }
     337           0 :     catch( const uno::Exception & ex )
     338             :     {
     339             :         ASSERT_EXCEPTION( ex );
     340             :     }
     341         678 : }
     342             : 
     343             : // ____ XModifyListener ____
     344           0 : void SAL_CALL BaseCoordinateSystem::modified( const lang::EventObject& aEvent )
     345             :     throw (uno::RuntimeException, std::exception)
     346             : {
     347           0 :     m_xModifyEventForwarder->modified( aEvent );
     348           0 : }
     349             : 
     350             : // ____ XEventListener (base of XModifyListener) ____
     351           0 : void SAL_CALL BaseCoordinateSystem::disposing( const lang::EventObject& /* Source */ )
     352             :     throw (uno::RuntimeException, std::exception)
     353             : {
     354             :     // nothing
     355           0 : }
     356             : 
     357             : // ____ OPropertySet ____
     358          70 : void BaseCoordinateSystem::firePropertyChangeEvent()
     359             : {
     360          70 :     fireModifyEvent();
     361          70 : }
     362             : 
     363        1530 : void BaseCoordinateSystem::fireModifyEvent()
     364             : {
     365        1530 :     m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
     366        1530 : }
     367             : 
     368             : // ____ OPropertySet ____
     369       11405 : uno::Any BaseCoordinateSystem::GetDefaultValue( sal_Int32 nHandle ) const
     370             :     throw(beans::UnknownPropertyException)
     371             : {
     372       11405 :     const tPropertyValueMap& rStaticDefaults = *StaticCooSysDefaults::get();
     373       11405 :     tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
     374       11405 :     if( aFound == rStaticDefaults.end() )
     375           0 :         return uno::Any();
     376       11405 :     return (*aFound).second;
     377             : }
     378             : 
     379             : // ____ OPropertySet ____
     380       24524 : ::cppu::IPropertyArrayHelper & SAL_CALL BaseCoordinateSystem::getInfoHelper()
     381             : {
     382       24524 :     return *StaticCooSysInfoHelper::get();
     383             : }
     384             : 
     385             : // ____ XPropertySet ____
     386          36 : Reference< beans::XPropertySetInfo > SAL_CALL BaseCoordinateSystem::getPropertySetInfo()
     387             :     throw (uno::RuntimeException, std::exception)
     388             : {
     389          36 :     return *StaticCooSysInfo::get();
     390             : }
     391             : 
     392             : using impl::BaseCoordinateSystem_Base;
     393             : 
     394     4124656 : IMPLEMENT_FORWARD_XINTERFACE2( BaseCoordinateSystem, BaseCoordinateSystem_Base, ::property::OPropertySet )
     395           0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( BaseCoordinateSystem, BaseCoordinateSystem_Base, ::property::OPropertySet )
     396             : 
     397         108 : } //  namespace chart
     398             : 
     399             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10