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

Generated by: LCOV version 1.10