LCOV - code coverage report
Current view: top level - chart2/source/model/template - ChartType.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 77 114 67.5 %
Date: 2014-04-11 Functions: 21 31 67.7 %
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       57909 : ChartType::ChartType(
      44             :     const Reference< uno::XComponentContext > & xContext ) :
      45             :         ::property::OPropertySet( m_aMutex ),
      46             :         m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
      47             :         m_xContext( xContext ),
      48       57909 :         m_bNotifyChanges( true )
      49       57909 : {}
      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      115600 : ChartType::~ChartType()
      64             : {
      65       57800 :     ModifyListenerHelper::removeListenerFromAllElements( m_aDataSeries, m_xModifyEventForwarder );
      66       57800 :     m_aDataSeries.clear();
      67       57800 : }
      68             : 
      69         265 : Reference< uno::XComponentContext > ChartType::GetComponentContext() const
      70             : {
      71         265 :     return m_xContext;
      72             : }
      73             : 
      74             : // ____ XChartType ____
      75             : Reference< chart2::XCoordinateSystem > SAL_CALL
      76         230 :     ChartType::createCoordinateSystem( ::sal_Int32 DimensionCount )
      77             :     throw (lang::IllegalArgumentException,
      78             :            uno::RuntimeException, std::exception)
      79             : {
      80             :     Reference< chart2::XCoordinateSystem > xResult(
      81             :         new CartesianCoordinateSystem(
      82         230 :             GetComponentContext(), DimensionCount, /* bSwapXAndYAxis */ sal_False ));
      83             : 
      84         716 :     for( sal_Int32 i=0; i<DimensionCount; ++i )
      85             :     {
      86         486 :         Reference< chart2::XAxis > xAxis( xResult->getAxisByDimension( i, MAIN_AXIS_INDEX ) );
      87         486 :         if( !xAxis.is() )
      88             :         {
      89             :             OSL_FAIL("a created coordinate system should have an axis for each dimension");
      90           0 :             continue;
      91             :         }
      92             : 
      93         972 :         chart2::ScaleData aScaleData = xAxis->getScaleData();
      94         486 :         aScaleData.Orientation = chart2::AxisOrientation_MATHEMATICAL;
      95         486 :         aScaleData.Scaling = AxisHelper::createLinearScaling();
      96             : 
      97         486 :         switch( i )
      98             :         {
      99         230 :             case 0: aScaleData.AxisType = chart2::AxisType::CATEGORY; break;
     100          26 :             case 2: aScaleData.AxisType = chart2::AxisType::SERIES; break;
     101         230 :             default: aScaleData.AxisType = chart2::AxisType::REALNUMBER; break;
     102             :         }
     103             : 
     104         486 :         xAxis->setScaleData( aScaleData );
     105         486 :     }
     106             : 
     107         230 :     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          39 : Sequence< OUString > SAL_CALL ChartType::getSupportedPropertyRoles()
     126             :     throw (uno::RuntimeException, std::exception)
     127             : {
     128          39 :     return Sequence< OUString >();
     129             : }
     130             : 
     131        4602 : OUString SAL_CALL ChartType::getRoleOfSequenceForSeriesLabel()
     132             :     throw (uno::RuntimeException, std::exception)
     133             : {
     134        4602 :     return OUString("values-y");
     135             : }
     136             : 
     137        1079 : void ChartType::impl_addDataSeriesWithoutNotification(
     138             :         const Reference< chart2::XDataSeries >& xDataSeries )
     139             : {
     140        3237 :     if( ::std::find( m_aDataSeries.begin(), m_aDataSeries.end(), xDataSeries )
     141        3237 :         != m_aDataSeries.end())
     142           0 :         throw lang::IllegalArgumentException();
     143             : 
     144        1079 :     m_aDataSeries.push_back( xDataSeries );
     145        1079 :     ModifyListenerHelper::addListener( xDataSeries, m_xModifyEventForwarder );
     146        1079 : }
     147             : 
     148             : // ____ XDataSeriesContainer ____
     149         380 : void SAL_CALL ChartType::addDataSeries( const Reference< chart2::XDataSeries >& xDataSeries )
     150             :     throw (lang::IllegalArgumentException,
     151             :            uno::RuntimeException, std::exception)
     152             : {
     153         380 :     impl_addDataSeriesWithoutNotification( xDataSeries );
     154         380 :     fireModifyEvent();
     155         380 : }
     156             : 
     157           0 : void SAL_CALL ChartType::removeDataSeries( const Reference< chart2::XDataSeries >& xDataSeries )
     158             :     throw (container::NoSuchElementException,
     159             :            uno::RuntimeException, std::exception)
     160             : {
     161           0 :     if( !xDataSeries.is())
     162           0 :         throw container::NoSuchElementException();
     163             : 
     164             :     tDataSeriesContainerType::iterator aIt(
     165           0 :             ::std::find( m_aDataSeries.begin(), m_aDataSeries.end(), xDataSeries ) );
     166             : 
     167           0 :     if( aIt == m_aDataSeries.end())
     168             :         throw container::NoSuchElementException(
     169             :             "The given series is no element of this charttype",
     170           0 :             static_cast< uno::XWeak * >( this ));
     171             : 
     172           0 :     ModifyListenerHelper::removeListener( xDataSeries, m_xModifyEventForwarder );
     173           0 :     m_aDataSeries.erase( aIt );
     174           0 :     fireModifyEvent();
     175           0 : }
     176             : 
     177       45357 : Sequence< Reference< chart2::XDataSeries > > SAL_CALL ChartType::getDataSeries()
     178             :     throw (uno::RuntimeException, std::exception)
     179             : {
     180       45357 :     return ContainerHelper::ContainerToSequence( m_aDataSeries );
     181             : }
     182             : 
     183         176 : void SAL_CALL ChartType::setDataSeries( const Sequence< Reference< chart2::XDataSeries > >& aDataSeries )
     184             :     throw (lang::IllegalArgumentException,
     185             :            uno::RuntimeException, std::exception)
     186             : {
     187         176 :     m_bNotifyChanges = false;
     188             :     try
     189             :     {
     190         176 :         Sequence< Reference< chart2::XDataSeries > > aOldSeries( this->getDataSeries() );
     191         329 :         for( sal_Int32 nN=0; nN<aOldSeries.getLength(); ++nN )
     192         153 :             ModifyListenerHelper::removeListener( aOldSeries[nN], m_xModifyEventForwarder );
     193         176 :         m_aDataSeries.clear();
     194             : 
     195         875 :         for( sal_Int32 i=0; i<aDataSeries.getLength(); ++i )
     196         875 :             impl_addDataSeriesWithoutNotification( aDataSeries[i] );
     197             :     }
     198           0 :     catch( ... )
     199             :     {
     200           0 :         m_bNotifyChanges = true;
     201           0 :         throw;
     202             :     }
     203         176 :     m_bNotifyChanges = true;
     204         176 :     fireModifyEvent();
     205         176 : }
     206             : 
     207             : // ____ OPropertySet ____
     208           0 : uno::Any ChartType::GetDefaultValue( sal_Int32 /* nHandle */ ) const
     209             :     throw(beans::UnknownPropertyException)
     210             : {
     211           0 :     return uno::Any();
     212             : }
     213             : 
     214             : namespace
     215             : {
     216             : 
     217             : struct StaticChartTypeInfoHelper_Initializer
     218             : {
     219           1 :     ::cppu::OPropertyArrayHelper* operator()()
     220             :     {
     221             :         // using assignment for broken gcc 3.3
     222             :         static ::cppu::OPropertyArrayHelper aPropHelper = ::cppu::OPropertyArrayHelper(
     223           1 :             Sequence< beans::Property >() );
     224           1 :         return &aPropHelper;
     225             :     }
     226             : };
     227             : 
     228             : struct StaticChartTypeInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticChartTypeInfoHelper_Initializer >
     229             : {
     230             : };
     231             : 
     232             : struct StaticChartTypeInfo_Initializer
     233             : {
     234           1 :     uno::Reference< beans::XPropertySetInfo >* operator()()
     235             :     {
     236             :         static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
     237           1 :             ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticChartTypeInfoHelper::get() ) );
     238           1 :         return &xPropertySetInfo;
     239             :     }
     240             : };
     241             : 
     242             : struct StaticChartTypeInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticChartTypeInfo_Initializer >
     243             : {
     244             : };
     245             : 
     246             : }
     247             : 
     248             : // ____ OPropertySet ____
     249         168 : ::cppu::IPropertyArrayHelper & SAL_CALL ChartType::getInfoHelper()
     250             : {
     251         168 :     return *StaticChartTypeInfoHelper::get();
     252             : }
     253             : 
     254             : // ____ XPropertySet ____
     255           2 : uno::Reference< beans::XPropertySetInfo > SAL_CALL ChartType::getPropertySetInfo()
     256             :     throw (uno::RuntimeException, std::exception)
     257             : {
     258           2 :     return *StaticChartTypeInfo::get();
     259             : }
     260             : 
     261             : // ____ XModifyBroadcaster ____
     262         384 : void SAL_CALL ChartType::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
     263             :     throw (uno::RuntimeException, std::exception)
     264             : {
     265             :     try
     266             :     {
     267         384 :         uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     268         384 :         xBroadcaster->addModifyListener( aListener );
     269             :     }
     270           0 :     catch( const uno::Exception & ex )
     271             :     {
     272             :         ASSERT_EXCEPTION( ex );
     273             :     }
     274         384 : }
     275             : 
     276         275 : void SAL_CALL ChartType::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
     277             :     throw (uno::RuntimeException, std::exception)
     278             : {
     279             :     try
     280             :     {
     281         275 :         uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     282         275 :         xBroadcaster->removeModifyListener( aListener );
     283             :     }
     284           0 :     catch( const uno::Exception & ex )
     285             :     {
     286             :         ASSERT_EXCEPTION( ex );
     287             :     }
     288         275 : }
     289             : 
     290             : // ____ XModifyListener ____
     291           0 : void SAL_CALL ChartType::modified( const lang::EventObject& aEvent )
     292             :     throw (uno::RuntimeException, std::exception)
     293             : {
     294           0 :     m_xModifyEventForwarder->modified( aEvent );
     295           0 : }
     296             : 
     297             : // ____ XEventListener (base of XModifyListener) ____
     298           0 : void SAL_CALL ChartType::disposing( const lang::EventObject& /* Source */ )
     299             :     throw (uno::RuntimeException, std::exception)
     300             : {
     301             :     // nothing
     302           0 : }
     303             : 
     304             : // ____ OPropertySet ____
     305       50826 : void ChartType::firePropertyChangeEvent()
     306             : {
     307       50826 :     fireModifyEvent();
     308       50826 : }
     309             : 
     310       51382 : void ChartType::fireModifyEvent()
     311             : {
     312       51382 :     if( m_bNotifyChanges )
     313       51382 :         m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
     314       51382 : }
     315             : 
     316             : using impl::ChartType_Base;
     317             : 
     318     1688941 : IMPLEMENT_FORWARD_XINTERFACE2( ChartType, ChartType_Base, ::property::OPropertySet )
     319           0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( ChartType, ChartType_Base, ::property::OPropertySet )
     320             : 
     321             : } //  namespace chart
     322             : 
     323             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10