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

Generated by: LCOV version 1.10