LCOV - code coverage report
Current view: top level - chart2/source/model/main - BaseCoordinateSystem.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 117 150 78.0 %
Date: 2015-06-13 12:38:46 Functions: 25 32 78.1 %
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          14 : void lcl_AddPropertiesToVector(
      51             :     ::std::vector< Property > & rOutProperties )
      52             : {
      53             :     rOutProperties.push_back(
      54             :         Property( "SwapXAndYAxis",
      55             :                   PROP_COORDINATESYSTEM_SWAPXANDYAXIS,
      56          14 :                   cppu::UnoType<bool>::get(),
      57             :                   beans::PropertyAttribute::BOUND
      58          28 :                   | beans::PropertyAttribute::MAYBEVOID ));
      59          14 : }
      60             : 
      61             : struct StaticCooSysDefaults_Initializer
      62             : {
      63          17 :     ::chart::tPropertyValueMap* operator()()
      64             :     {
      65          17 :         static ::chart::tPropertyValueMap aStaticDefaults;
      66          17 :         lcl_AddDefaultsToMap( aStaticDefaults );
      67          17 :         return &aStaticDefaults;
      68             :     }
      69             : private:
      70          17 :     static void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
      71             :     {
      72          17 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_COORDINATESYSTEM_SWAPXANDYAXIS, false );
      73          17 :     }
      74             : };
      75             : 
      76             : struct StaticCooSysDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticCooSysDefaults_Initializer >
      77             : {
      78             : };
      79             : 
      80             : struct StaticCooSysInfoHelper_Initializer
      81             : {
      82          14 :     ::cppu::OPropertyArrayHelper* operator()()
      83             :     {
      84          14 :         static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
      85          14 :         return &aPropHelper;
      86             :     }
      87             : 
      88             : private:
      89          14 :     static Sequence< Property > lcl_GetPropertySequence()
      90             :     {
      91          14 :         ::std::vector< ::com::sun::star::beans::Property > aProperties;
      92          14 :         lcl_AddPropertiesToVector( aProperties );
      93          14 :         ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
      94             : 
      95             :         ::std::sort( aProperties.begin(), aProperties.end(),
      96          14 :                      ::chart::PropertyNameLess() );
      97             : 
      98          14 :         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           2 :     uno::Reference< beans::XPropertySetInfo >* operator()()
     109             :     {
     110             :         static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
     111           2 :             ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticCooSysInfoHelper::get() ) );
     112           2 :         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         356 : 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         356 :         m_nDimensionCount( nDimensionCount )
     133             :  {
     134         356 :     m_aAllAxis.resize( m_nDimensionCount );
     135        1123 :     for( sal_Int32 nN=0; nN<m_nDimensionCount; nN++ )
     136             :     {
     137         767 :         m_aAllAxis[nN].resize( 1 );
     138         767 :         Reference< chart2::XAxis > xAxis( new Axis(m_xContext) );
     139         767 :         m_aAllAxis[nN][0] = xAxis;
     140             : 
     141         767 :         ModifyListenerHelper::addListenerToAllElements( m_aAllAxis[nN], m_xModifyEventForwarder );
     142        1534 :         chart2::ScaleData aScaleData( xAxis->getScaleData() );
     143         767 :         if(nN==0)
     144             :         {
     145         356 :             aScaleData.AxisType = chart2::AxisType::CATEGORY;
     146             :         }
     147         411 :         else if( nN==1)
     148             :         {
     149         356 :             aScaleData.AxisType = chart2::AxisType::REALNUMBER;
     150             :         }
     151          55 :         else if( nN==2)
     152             :         {
     153          55 :             aScaleData.AxisType = chart2::AxisType::SERIES;
     154             :         }
     155         767 :         xAxis->setScaleData( aScaleData );
     156         767 :     }
     157             : 
     158         356 :     m_aOrigin.realloc( m_nDimensionCount );
     159        1123 :     for( sal_Int32 i = 0; i < m_nDimensionCount; ++i )
     160         767 :         m_aOrigin[ i ] = uno::makeAny( double( 0.0 ) );
     161             : 
     162         356 :     setFastPropertyValue_NoBroadcast( PROP_COORDINATESYSTEM_SWAPXANDYAXIS, uno::makeAny( bSwapXAndYAxis ));
     163         356 : }
     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         680 : BaseCoordinateSystem::~BaseCoordinateSystem()
     188             : {
     189             :     try
     190             :     {
     191        1075 :         for( tAxisVecVecType::size_type nN=0; nN<m_aAllAxis.size(); nN++ )
     192         735 :             ModifyListenerHelper::removeListenerFromAllElements( m_aAllAxis[nN], m_xModifyEventForwarder );
     193         340 :         ModifyListenerHelper::removeListenerFromAllElements( m_aChartTypes, m_xModifyEventForwarder );
     194             :     }
     195           0 :     catch( const uno::Exception & ex )
     196             :     {
     197             :         ASSERT_EXCEPTION( ex );
     198             :     }
     199         340 : }
     200             : 
     201             : // ____ XCoordinateSystem ____
     202     1460026 : sal_Int32 SAL_CALL BaseCoordinateSystem::getDimension()
     203             :     throw (uno::RuntimeException, std::exception)
     204             : {
     205     1460026 :     return m_nDimensionCount;
     206             : }
     207             : 
     208         461 : 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         461 :     if( nDimensionIndex < 0 || nDimensionIndex >= getDimension() )
     216           0 :         throw lang::IndexOutOfBoundsException();
     217             : 
     218         461 :     if( nIndex < 0 )
     219           0 :         throw lang::IndexOutOfBoundsException();
     220             : 
     221         461 :     if( m_aAllAxis[ nDimensionIndex ].size() < static_cast< tAxisVecVecType::size_type >( nIndex+1 ))
     222             :     {
     223          35 :         m_aAllAxis[ nDimensionIndex ].resize( nIndex+1 );
     224          35 :         m_aAllAxis[ nDimensionIndex ][nIndex] = 0;
     225             :     }
     226             : 
     227         461 :     Reference< chart2::XAxis > xOldAxis( m_aAllAxis[ nDimensionIndex ][nIndex] );
     228         461 :     if( xOldAxis.is())
     229         426 :         ModifyListenerHelper::removeListener( xOldAxis, m_xModifyEventForwarder );
     230         461 :     m_aAllAxis[ nDimensionIndex ][nIndex] = xAxis;
     231         461 :     if( xAxis.is())
     232         461 :         ModifyListenerHelper::addListener( xAxis, m_xModifyEventForwarder );
     233         461 :     fireModifyEvent();
     234         461 : }
     235             : 
     236      355523 : 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      355523 :     if( nDimensionIndex < 0 || nDimensionIndex >= getDimension() )
     242         332 :         throw lang::IndexOutOfBoundsException();
     243             : 
     244             :     OSL_ASSERT( m_aAllAxis.size() == static_cast< size_t >( getDimension()));
     245             : 
     246      355191 :     if( nAxisIndex < 0 || nAxisIndex > this->getMaximumAxisIndexByDimension(nDimensionIndex) )
     247        1541 :         throw lang::IndexOutOfBoundsException();
     248             : 
     249      353650 :     return m_aAllAxis[ nDimensionIndex ][nAxisIndex];
     250             : }
     251             : 
     252      696410 : sal_Int32 SAL_CALL BaseCoordinateSystem::getMaximumAxisIndexByDimension( sal_Int32 nDimensionIndex )
     253             :         throw (lang::IndexOutOfBoundsException,
     254             :            uno::RuntimeException, std::exception)
     255             : {
     256      696410 :     if( nDimensionIndex < 0 || nDimensionIndex >= getDimension() )
     257           0 :         throw lang::IndexOutOfBoundsException();
     258             : 
     259             :     OSL_ASSERT( m_aAllAxis.size() == static_cast< size_t >( getDimension()));
     260             : 
     261      696410 :     sal_Int32 nRet = m_aAllAxis[ nDimensionIndex ].size();
     262      696410 :     if(nRet)
     263      696410 :         nRet-=1;
     264             : 
     265      696410 :     return nRet;
     266             : }
     267             : 
     268             : // ____ XChartTypeContainer ____
     269         259 : void SAL_CALL BaseCoordinateSystem::addChartType( const Reference< chart2::XChartType >& aChartType )
     270             :     throw (lang::IllegalArgumentException,
     271             :            uno::RuntimeException, std::exception)
     272             : {
     273         777 :     if( ::std::find( m_aChartTypes.begin(), m_aChartTypes.end(), aChartType )
     274         777 :         != m_aChartTypes.end())
     275           0 :         throw lang::IllegalArgumentException();
     276             : 
     277         259 :     m_aChartTypes.push_back( aChartType );
     278         259 :     ModifyListenerHelper::addListener( aChartType, m_xModifyEventForwarder );
     279         259 :     fireModifyEvent();
     280         259 : }
     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      176507 : Sequence< Reference< chart2::XChartType > > SAL_CALL BaseCoordinateSystem::getChartTypes()
     299             :     throw (uno::RuntimeException, std::exception)
     300             : {
     301      176507 :     return ContainerHelper::ContainerToSequence( m_aChartTypes );
     302             : }
     303             : 
     304         126 : void SAL_CALL BaseCoordinateSystem::setChartTypes( const Sequence< Reference< chart2::XChartType > >& aChartTypes )
     305             :     throw (lang::IllegalArgumentException,
     306             :            uno::RuntimeException, std::exception)
     307             : {
     308         126 :     ModifyListenerHelper::removeListenerFromAllElements( m_aChartTypes, m_xModifyEventForwarder );
     309         126 :     m_aChartTypes = ContainerHelper::SequenceToVector( aChartTypes );
     310         126 :     ModifyListenerHelper::addListenerToAllElements( m_aChartTypes, m_xModifyEventForwarder );
     311         126 :     fireModifyEvent();
     312         126 : }
     313             : 
     314             : // ____ XModifyBroadcaster ____
     315         340 : void SAL_CALL BaseCoordinateSystem::addModifyListener( const Reference< util::XModifyListener >& aListener )
     316             :     throw (uno::RuntimeException, std::exception)
     317             : {
     318             :     try
     319             :     {
     320         340 :         Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     321         340 :         xBroadcaster->addModifyListener( aListener );
     322             :     }
     323           0 :     catch( const uno::Exception & ex )
     324             :     {
     325             :         ASSERT_EXCEPTION( ex );
     326             :     }
     327         340 : }
     328             : 
     329         340 : void SAL_CALL BaseCoordinateSystem::removeModifyListener( const Reference< util::XModifyListener >& aListener )
     330             :     throw (uno::RuntimeException, std::exception)
     331             : {
     332             :     try
     333             :     {
     334         340 :         Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     335         340 :         xBroadcaster->removeModifyListener( aListener );
     336             :     }
     337           0 :     catch( const uno::Exception & ex )
     338             :     {
     339             :         ASSERT_EXCEPTION( ex );
     340             :     }
     341         340 : }
     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          32 : void BaseCoordinateSystem::firePropertyChangeEvent()
     359             : {
     360          32 :     fireModifyEvent();
     361          32 : }
     362             : 
     363         878 : void BaseCoordinateSystem::fireModifyEvent()
     364             : {
     365         878 :     m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
     366         878 : }
     367             : 
     368             : // ____ OPropertySet ____
     369       13969 : uno::Any BaseCoordinateSystem::GetDefaultValue( sal_Int32 nHandle ) const
     370             :     throw(beans::UnknownPropertyException)
     371             : {
     372       13969 :     const tPropertyValueMap& rStaticDefaults = *StaticCooSysDefaults::get();
     373       13969 :     tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
     374       13969 :     if( aFound == rStaticDefaults.end() )
     375           0 :         return uno::Any();
     376       13969 :     return (*aFound).second;
     377             : }
     378             : 
     379             : // ____ OPropertySet ____
     380       29318 : ::cppu::IPropertyArrayHelper & SAL_CALL BaseCoordinateSystem::getInfoHelper()
     381             : {
     382       29318 :     return *StaticCooSysInfoHelper::get();
     383             : }
     384             : 
     385             : // ____ XPropertySet ____
     386          20 : Reference< beans::XPropertySetInfo > SAL_CALL BaseCoordinateSystem::getPropertySetInfo()
     387             :     throw (uno::RuntimeException, std::exception)
     388             : {
     389          20 :     return *StaticCooSysInfo::get();
     390             : }
     391             : 
     392             : using impl::BaseCoordinateSystem_Base;
     393             : 
     394     2272934 : IMPLEMENT_FORWARD_XINTERFACE2( BaseCoordinateSystem, BaseCoordinateSystem_Base, ::property::OPropertySet )
     395           0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( BaseCoordinateSystem, BaseCoordinateSystem_Base, ::property::OPropertySet )
     396             : 
     397             : } //  namespace chart
     398             : 
     399             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11