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