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

Generated by: LCOV version 1.10