LCOV - code coverage report
Current view: top level - chart2/source/controller/chartapiwrapper - ChartDataWrapper.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 342 0.0 %
Date: 2014-04-14 Functions: 0 89 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 "ChartDataWrapper.hxx"
      21             : #include "macros.hxx"
      22             : #include "DiagramHelper.hxx"
      23             : #include "DataSourceHelper.hxx"
      24             : #include "servicenames_charttypes.hxx"
      25             : #include "ContainerHelper.hxx"
      26             : #include "CommonFunctors.hxx"
      27             : #include "ChartModelHelper.hxx"
      28             : #include "DataSeriesHelper.hxx"
      29             : #include "ControllerLockGuard.hxx"
      30             : #include "Chart2ModelContact.hxx"
      31             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      32             : #include <com/sun/star/chart2/XTitled.hpp>
      33             : #include <com/sun/star/chart2/data/XNumericalDataSequence.hpp>
      34             : #include <com/sun/star/chart2/data/XTextualDataSequence.hpp>
      35             : #include <com/sun/star/chart2/data/XDataSource.hpp>
      36             : #include <com/sun/star/chart2/XDataSeries.hpp>
      37             : #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
      38             : #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
      39             : #include <com/sun/star/chart2/XChartTypeContainer.hpp>
      40             : #include <com/sun/star/chart2/data/XDataReceiver.hpp>
      41             : #include <com/sun/star/chart/ChartDataRowSource.hpp>
      42             : #include <com/sun/star/chart/XChartDocument.hpp>
      43             : 
      44             : #include "CharacterProperties.hxx"
      45             : #include "LineProperties.hxx"
      46             : #include "FillProperties.hxx"
      47             : 
      48             : #include <map>
      49             : #include <algorithm>
      50             : #include <rtl/math.hxx>
      51             : 
      52             : using namespace ::com::sun::star;
      53             : using ::com::sun::star::uno::Reference;
      54             : using ::com::sun::star::uno::Sequence;
      55             : using ::osl::MutexGuard;
      56             : using ::com::sun::star::chart2::XAnyDescriptionAccess;
      57             : using ::com::sun::star::chart::XComplexDescriptionAccess;
      58             : using ::com::sun::star::chart::XChartData;
      59             : using ::com::sun::star::chart::XChartDataArray;
      60             : using ::com::sun::star::chart::XDateCategories;
      61             : 
      62             : namespace
      63             : {
      64           0 : static const OUString lcl_aServiceName( "com.sun.star.comp.chart.ChartData" );
      65             : 
      66           0 : uno::Sequence< uno::Sequence< double > > lcl_getNANInsteadDBL_MIN( const uno::Sequence< uno::Sequence< double > >& rData )
      67             : {
      68           0 :     uno::Sequence< uno::Sequence< double > > aRet;
      69           0 :     const sal_Int32 nOuterSize = rData.getLength();
      70           0 :     aRet.realloc( nOuterSize );
      71           0 :     for( sal_Int32 nOuter=0; nOuter<nOuterSize; ++nOuter )
      72             :     {
      73           0 :         sal_Int32 nInnerSize = rData[nOuter].getLength();
      74           0 :         aRet[nOuter].realloc( nInnerSize );
      75           0 :         for( sal_Int32 nInner=0; nInner<nInnerSize; ++nInner )
      76             :         {
      77           0 :             aRet[nOuter][nInner] = rData[nOuter][nInner];
      78           0 :             double& rValue = aRet[nOuter][nInner];
      79           0 :             if( rValue == DBL_MIN )
      80           0 :                 ::rtl::math::setNan( &rValue );
      81             :         }
      82             :     }
      83           0 :     return aRet;
      84             : }
      85             : 
      86           0 : uno::Sequence< uno::Sequence< double > > lcl_getDBL_MINInsteadNAN( const uno::Sequence< uno::Sequence< double > >& rData )
      87             : {
      88           0 :     uno::Sequence< uno::Sequence< double > > aRet;
      89           0 :     const sal_Int32 nOuterSize = rData.getLength();
      90           0 :     aRet.realloc( nOuterSize );
      91           0 :     for( sal_Int32 nOuter=0; nOuter<nOuterSize; ++nOuter )
      92             :     {
      93           0 :         sal_Int32 nInnerSize = rData[nOuter].getLength();
      94           0 :         aRet[nOuter].realloc( nInnerSize );
      95           0 :         for( sal_Int32 nInner=0; nInner<nInnerSize; ++nInner )
      96             :         {
      97           0 :             aRet[nOuter][nInner] = rData[nOuter][nInner];
      98           0 :             double& rValue = aRet[nOuter][nInner];
      99           0 :             if( ::rtl::math::isNan( rValue ) )
     100           0 :                 rValue = DBL_MIN;
     101             :         }
     102             :     }
     103           0 :     return aRet;
     104             : }
     105             : 
     106             : } // anonymous namespace
     107             : 
     108             : namespace chart
     109             : {
     110             : namespace wrapper
     111             : {
     112             : 
     113             : struct lcl_Operator
     114             : {
     115           0 :     lcl_Operator()
     116           0 :     {
     117           0 :     }
     118           0 :     virtual ~lcl_Operator()
     119           0 :     {
     120           0 :     }
     121             :     virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess ) = 0;
     122             : 
     123           0 :     virtual bool setsCategories( bool /*bDataInColumns*/ )
     124             :     {
     125           0 :         return false;
     126             :     }
     127             : };
     128             : 
     129           0 : struct lcl_AllOperator : public lcl_Operator
     130             : {
     131           0 :     lcl_AllOperator( const Reference< XChartData >& xDataToApply )
     132             :         : lcl_Operator()
     133           0 :         , m_xDataToApply( xDataToApply )
     134             :     {
     135           0 :     }
     136             : 
     137           0 :     virtual bool setsCategories( bool /*bDataInColumns*/ ) SAL_OVERRIDE
     138             :     {
     139           0 :         return true;
     140             :     }
     141             : 
     142           0 :     virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess ) SAL_OVERRIDE
     143             :     {
     144           0 :         if( !xDataAccess.is() )
     145           0 :             return;
     146             : 
     147           0 :         Reference< XAnyDescriptionAccess > xNewAny( m_xDataToApply, uno::UNO_QUERY );
     148           0 :         Reference< XComplexDescriptionAccess > xNewComplex( m_xDataToApply, uno::UNO_QUERY );
     149           0 :         if( xNewAny.is() )
     150             :         {
     151           0 :             xDataAccess->setData( xNewAny->getData() );
     152           0 :             xDataAccess->setComplexRowDescriptions( xNewAny->getComplexRowDescriptions() );
     153           0 :             xDataAccess->setComplexColumnDescriptions( xNewAny->getComplexColumnDescriptions() );
     154             :         }
     155           0 :         else if( xNewComplex.is() )
     156             :         {
     157           0 :             xDataAccess->setData( xNewComplex->getData() );
     158           0 :             xDataAccess->setComplexRowDescriptions( xNewComplex->getComplexRowDescriptions() );
     159           0 :             xDataAccess->setComplexColumnDescriptions( xNewComplex->getComplexColumnDescriptions() );
     160             :         }
     161             :         else
     162             :         {
     163           0 :             Reference< XChartDataArray > xNew( m_xDataToApply, uno::UNO_QUERY );
     164           0 :             if( xNew.is() )
     165             :             {
     166           0 :                 xDataAccess->setData( xNew->getData() );
     167           0 :                 xDataAccess->setRowDescriptions( xNew->getRowDescriptions() );
     168           0 :                 xDataAccess->setColumnDescriptions( xNew->getColumnDescriptions() );
     169           0 :             }
     170           0 :         }
     171             :     }
     172             : 
     173             :     Reference< XChartData > m_xDataToApply;
     174             : };
     175             : 
     176           0 : struct lcl_DataOperator : public lcl_Operator
     177             : {
     178           0 :     lcl_DataOperator( const Sequence< Sequence< double > >& rData )
     179             :         : lcl_Operator()
     180           0 :         , m_rData( rData )
     181             :     {
     182           0 :     }
     183             : 
     184           0 :     virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess ) SAL_OVERRIDE
     185             :     {
     186           0 :         if( xDataAccess.is() )
     187           0 :             xDataAccess->setData( lcl_getNANInsteadDBL_MIN( m_rData ) );
     188           0 :     }
     189             : 
     190             :     const Sequence< Sequence< double > >& m_rData;
     191             : };
     192             : 
     193           0 : struct lcl_RowDescriptionsOperator : public lcl_Operator
     194             : {
     195           0 :     lcl_RowDescriptionsOperator( const Sequence< OUString >& rRowDescriptions
     196             :         , const Reference< chart2::XChartDocument >& xChartDoc )
     197             :         : lcl_Operator()
     198             :         , m_rRowDescriptions( rRowDescriptions )
     199             :         , m_xChartDoc(xChartDoc)
     200           0 :         , m_bDataInColumns(true)
     201             :     {
     202           0 :     }
     203             : 
     204           0 :     virtual bool setsCategories( bool bDataInColumns ) SAL_OVERRIDE
     205             :     {
     206           0 :         m_bDataInColumns = bDataInColumns;
     207           0 :         return bDataInColumns;
     208             :     }
     209             : 
     210           0 :     virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess ) SAL_OVERRIDE
     211             :     {
     212           0 :         if( xDataAccess.is() )
     213             :         {
     214           0 :             xDataAccess->setRowDescriptions( m_rRowDescriptions );
     215           0 :             if( m_bDataInColumns )
     216           0 :                 DiagramHelper::switchToTextCategories( m_xChartDoc );
     217             :         }
     218           0 :     }
     219             : 
     220             :     const Sequence< OUString >& m_rRowDescriptions;
     221             :     Reference< chart2::XChartDocument > m_xChartDoc;
     222             :     bool m_bDataInColumns;
     223             : };
     224             : 
     225           0 : struct lcl_ComplexRowDescriptionsOperator : public lcl_Operator
     226             : {
     227           0 :     lcl_ComplexRowDescriptionsOperator( const Sequence< Sequence< OUString > >& rComplexRowDescriptions
     228             :         , const Reference< chart2::XChartDocument >& xChartDoc )
     229             :         : lcl_Operator()
     230             :         , m_rComplexRowDescriptions( rComplexRowDescriptions )
     231             :         , m_xChartDoc(xChartDoc)
     232           0 :         , m_bDataInColumns(true)
     233             :     {
     234           0 :     }
     235             : 
     236           0 :     virtual bool setsCategories( bool bDataInColumns ) SAL_OVERRIDE
     237             :     {
     238           0 :         m_bDataInColumns = bDataInColumns;
     239           0 :         return bDataInColumns;
     240             :     }
     241             : 
     242           0 :     virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess ) SAL_OVERRIDE
     243             :     {
     244           0 :         if( xDataAccess.is() )
     245             :         {
     246           0 :             xDataAccess->setComplexRowDescriptions( m_rComplexRowDescriptions );
     247           0 :             if( m_bDataInColumns )
     248           0 :                 DiagramHelper::switchToTextCategories( m_xChartDoc );
     249             :         }
     250           0 :     }
     251             : 
     252             :     const Sequence< Sequence< OUString > >& m_rComplexRowDescriptions;
     253             :     Reference< chart2::XChartDocument > m_xChartDoc;
     254             :     bool m_bDataInColumns;
     255             : };
     256             : 
     257           0 : struct lcl_AnyRowDescriptionsOperator : public lcl_Operator
     258             : {
     259           0 :     lcl_AnyRowDescriptionsOperator( const Sequence< Sequence< uno::Any > >& rAnyRowDescriptions )
     260             :         : lcl_Operator()
     261           0 :         , m_rAnyRowDescriptions( rAnyRowDescriptions )
     262             :     {
     263           0 :     }
     264             : 
     265           0 :     virtual bool setsCategories( bool bDataInColumns ) SAL_OVERRIDE
     266             :     {
     267           0 :         return bDataInColumns;
     268             :     }
     269             : 
     270           0 :     virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess ) SAL_OVERRIDE
     271             :     {
     272           0 :         if( xDataAccess.is() )
     273           0 :             xDataAccess->setAnyRowDescriptions( m_rAnyRowDescriptions );
     274           0 :     }
     275             : 
     276             :     const Sequence< Sequence< uno::Any > >& m_rAnyRowDescriptions;
     277             : };
     278             : 
     279           0 : struct lcl_ColumnDescriptionsOperator : public lcl_Operator
     280             : {
     281           0 :     lcl_ColumnDescriptionsOperator( const Sequence< OUString >& rColumnDescriptions
     282             :         , const Reference< chart2::XChartDocument >& xChartDoc )
     283             :         : lcl_Operator()
     284             :         , m_rColumnDescriptions( rColumnDescriptions )
     285             :         , m_xChartDoc(xChartDoc)
     286           0 :         , m_bDataInColumns(true)
     287             :     {
     288           0 :     }
     289             : 
     290           0 :     virtual bool setsCategories( bool bDataInColumns ) SAL_OVERRIDE
     291             :     {
     292           0 :         m_bDataInColumns = bDataInColumns;
     293           0 :         return !bDataInColumns;
     294             :     }
     295             : 
     296           0 :     virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess ) SAL_OVERRIDE
     297             :     {
     298           0 :         if( xDataAccess.is() )
     299             :         {
     300           0 :             xDataAccess->setColumnDescriptions( m_rColumnDescriptions );
     301           0 :             if( !m_bDataInColumns )
     302           0 :                 DiagramHelper::switchToTextCategories( m_xChartDoc );
     303             :         }
     304           0 :     }
     305             : 
     306             :     const Sequence< OUString >& m_rColumnDescriptions;
     307             :     Reference< chart2::XChartDocument > m_xChartDoc;
     308             :     bool m_bDataInColumns;
     309             : };
     310             : 
     311           0 : struct lcl_ComplexColumnDescriptionsOperator : public lcl_Operator
     312             : {
     313           0 :     lcl_ComplexColumnDescriptionsOperator( const Sequence< Sequence< OUString > >& rComplexColumnDescriptions
     314             :         , const Reference< chart2::XChartDocument >& xChartDoc )
     315             :         : lcl_Operator()
     316             :         , m_rComplexColumnDescriptions( rComplexColumnDescriptions )
     317             :         , m_xChartDoc(xChartDoc)
     318           0 :         , m_bDataInColumns(true)
     319             :     {
     320           0 :     }
     321             : 
     322           0 :     virtual bool setsCategories( bool bDataInColumns ) SAL_OVERRIDE
     323             :     {
     324           0 :         m_bDataInColumns = bDataInColumns;
     325           0 :         return !bDataInColumns;
     326             :     }
     327             : 
     328           0 :     virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess ) SAL_OVERRIDE
     329             :     {
     330           0 :         if( xDataAccess.is() )
     331             :         {
     332           0 :             xDataAccess->setComplexColumnDescriptions( m_rComplexColumnDescriptions );
     333           0 :             if( !m_bDataInColumns )
     334           0 :                 DiagramHelper::switchToTextCategories( m_xChartDoc );
     335             :         }
     336           0 :     }
     337             : 
     338             :     const Sequence< Sequence< OUString > >& m_rComplexColumnDescriptions;
     339             :     Reference< chart2::XChartDocument > m_xChartDoc;
     340             :     bool m_bDataInColumns;
     341             : };
     342             : 
     343           0 : struct lcl_AnyColumnDescriptionsOperator : public lcl_Operator
     344             : {
     345           0 :     lcl_AnyColumnDescriptionsOperator( const Sequence< Sequence< uno::Any > >& rAnyColumnDescriptions )
     346             :         : lcl_Operator()
     347           0 :         , m_rAnyColumnDescriptions( rAnyColumnDescriptions )
     348             :     {
     349           0 :     }
     350             : 
     351           0 :     virtual bool setsCategories( bool bDataInColumns ) SAL_OVERRIDE
     352             :     {
     353           0 :         return bDataInColumns;
     354             :     }
     355             : 
     356           0 :     virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess ) SAL_OVERRIDE
     357             :     {
     358           0 :         if( xDataAccess.is() )
     359           0 :             xDataAccess->setAnyColumnDescriptions( m_rAnyColumnDescriptions );
     360           0 :     }
     361             : 
     362             :     const Sequence< Sequence< uno::Any > >& m_rAnyColumnDescriptions;
     363             : };
     364             : 
     365           0 : struct lcl_DateCategoriesOperator : public lcl_Operator
     366             : {
     367           0 :     lcl_DateCategoriesOperator( const Sequence< double >& rDates )
     368             :         : lcl_Operator()
     369           0 :         , m_rDates( rDates )
     370             :     {
     371           0 :     }
     372             : 
     373           0 :     virtual bool setsCategories( bool /*bDataInColumns*/ ) SAL_OVERRIDE
     374             :     {
     375           0 :         return true;
     376             :     }
     377             : 
     378           0 :     virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess ) SAL_OVERRIDE
     379             :     {
     380           0 :         Reference< XDateCategories > xDateCategories( xDataAccess, uno::UNO_QUERY );
     381           0 :         if( xDateCategories.is() )
     382           0 :             xDateCategories->setDateCategories( m_rDates );
     383           0 :     }
     384             : 
     385             :     const Sequence< double >& m_rDates;
     386             : };
     387             : 
     388           0 : ChartDataWrapper::ChartDataWrapper( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) :
     389             :         m_spChart2ModelContact( spChart2ModelContact ),
     390           0 :         m_aEventListenerContainer( m_aMutex )
     391             : {
     392           0 :     osl_atomic_increment( &m_refCount );
     393           0 :     initDataAccess();
     394           0 :     osl_atomic_decrement( &m_refCount );
     395           0 : }
     396             : 
     397           0 : ChartDataWrapper::ChartDataWrapper( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact,
     398             :                                     const Reference< XChartData >& xNewData ) :
     399             :         m_spChart2ModelContact( spChart2ModelContact ),
     400           0 :         m_aEventListenerContainer( m_aMutex )
     401             : {
     402           0 :     osl_atomic_increment( &m_refCount );
     403           0 :     lcl_AllOperator aOperator( xNewData );
     404           0 :     applyData( aOperator );
     405           0 :     osl_atomic_decrement( &m_refCount );
     406           0 : }
     407             : 
     408           0 : ChartDataWrapper::~ChartDataWrapper()
     409             : {
     410             :     // @todo: implement XComponent and call this in dispose().  In the DTOR the
     411             :     // ref-count is 0, thus creating a stack reference to this calls the DTOR at
     412             :     // the end of the block recursively
     413             : //     uno::Reference< uno::XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
     414             : //     m_aEventListenerContainer.disposeAndClear( lang::EventObject( xSource ) );
     415           0 : }
     416             : 
     417             : // ____ XChartDataArray (read)____
     418           0 : Sequence< Sequence< double > > SAL_CALL ChartDataWrapper::getData()
     419             :     throw (uno::RuntimeException, std::exception)
     420             : {
     421           0 :     initDataAccess();
     422           0 :     if( m_xDataAccess.is() )
     423           0 :         return lcl_getDBL_MINInsteadNAN( m_xDataAccess->getData() );
     424           0 :     return Sequence< Sequence< double > >();
     425             : }
     426           0 : Sequence< OUString > SAL_CALL ChartDataWrapper::getRowDescriptions()
     427             :     throw (uno::RuntimeException, std::exception)
     428             : {
     429           0 :     initDataAccess();
     430           0 :     if( m_xDataAccess.is() )
     431           0 :         return m_xDataAccess->getRowDescriptions();
     432           0 :     return Sequence< OUString >();
     433             : }
     434           0 : Sequence< OUString > SAL_CALL ChartDataWrapper::getColumnDescriptions()
     435             :     throw (uno::RuntimeException, std::exception)
     436             : {
     437           0 :     initDataAccess();
     438           0 :     if( m_xDataAccess.is() )
     439           0 :         return m_xDataAccess->getColumnDescriptions();
     440           0 :     return Sequence< OUString > ();
     441             : }
     442             : 
     443             : // ____ XComplexDescriptionAccess (read) ____
     444           0 : Sequence< Sequence< OUString > > SAL_CALL ChartDataWrapper::getComplexRowDescriptions() throw (uno::RuntimeException, std::exception)
     445             : {
     446           0 :     initDataAccess();
     447           0 :     if( m_xDataAccess.is() )
     448           0 :         return m_xDataAccess->getComplexRowDescriptions();
     449           0 :     return Sequence< Sequence< OUString > >();
     450             : }
     451           0 : Sequence< Sequence< OUString > > SAL_CALL ChartDataWrapper::getComplexColumnDescriptions() throw (uno::RuntimeException, std::exception)
     452             : {
     453           0 :     initDataAccess();
     454           0 :     if( m_xDataAccess.is() )
     455           0 :         return m_xDataAccess->getComplexColumnDescriptions();
     456           0 :     return Sequence< Sequence< OUString > >();
     457             : }
     458             : 
     459             : // ____ XAnyDescriptionAccess (read) ____
     460           0 : Sequence< Sequence< uno::Any > > SAL_CALL ChartDataWrapper::getAnyRowDescriptions() throw (uno::RuntimeException, std::exception)
     461             : {
     462           0 :     initDataAccess();
     463           0 :     if( m_xDataAccess.is() )
     464           0 :         return m_xDataAccess->getAnyRowDescriptions();
     465           0 :     return Sequence< Sequence< uno::Any > >();
     466             : }
     467           0 : Sequence< Sequence< uno::Any > > SAL_CALL ChartDataWrapper::getAnyColumnDescriptions() throw (uno::RuntimeException, std::exception)
     468             : {
     469           0 :     initDataAccess();
     470           0 :     if( m_xDataAccess.is() )
     471           0 :         return m_xDataAccess->getAnyColumnDescriptions();
     472           0 :     return Sequence< Sequence< uno::Any > >();
     473             : }
     474             : 
     475             : // ____ XDateCategories (read) ____
     476           0 : Sequence< double > SAL_CALL ChartDataWrapper::getDateCategories() throw (uno::RuntimeException, std::exception)
     477             : {
     478           0 :     initDataAccess();
     479           0 :     Reference< XDateCategories > xDateCategories( m_xDataAccess, uno::UNO_QUERY );
     480           0 :     if( xDateCategories.is() )
     481           0 :         return xDateCategories->getDateCategories();
     482           0 :     return Sequence< double >();
     483             : }
     484             : 
     485             : // ____ XChartDataArray (write)____
     486           0 : void SAL_CALL ChartDataWrapper::setData( const Sequence< Sequence< double > >& rData )
     487             :     throw (uno::RuntimeException, std::exception)
     488             : {
     489           0 :     lcl_DataOperator aOperator( rData );
     490           0 :     applyData( aOperator );
     491           0 : }
     492           0 : void SAL_CALL ChartDataWrapper::setRowDescriptions( const Sequence< OUString >& rRowDescriptions )
     493             :     throw (uno::RuntimeException, std::exception)
     494             : {
     495           0 :     lcl_RowDescriptionsOperator aOperator( rRowDescriptions, m_spChart2ModelContact->getChart2Document() );
     496           0 :     applyData( aOperator );
     497           0 : }
     498           0 : void SAL_CALL ChartDataWrapper::setColumnDescriptions( const Sequence< OUString >& rColumnDescriptions )
     499             :     throw (uno::RuntimeException, std::exception)
     500             : {
     501           0 :     lcl_ColumnDescriptionsOperator aOperator( rColumnDescriptions, m_spChart2ModelContact->getChart2Document() );
     502           0 :     applyData( aOperator );
     503           0 : }
     504             : 
     505             : // ____ XComplexDescriptionAccess (write) ____
     506           0 : void SAL_CALL ChartDataWrapper::setComplexRowDescriptions( const Sequence< Sequence< OUString > >& rRowDescriptions ) throw (uno::RuntimeException, std::exception)
     507             : {
     508           0 :     lcl_ComplexRowDescriptionsOperator aOperator( rRowDescriptions, m_spChart2ModelContact->getChart2Document() );
     509           0 :     applyData( aOperator );
     510           0 : }
     511           0 : void SAL_CALL ChartDataWrapper::setComplexColumnDescriptions( const Sequence< Sequence< OUString > >& rColumnDescriptions ) throw (uno::RuntimeException, std::exception)
     512             : {
     513           0 :     lcl_ComplexColumnDescriptionsOperator aOperator( rColumnDescriptions, m_spChart2ModelContact->getChart2Document() );
     514           0 :     applyData( aOperator );
     515           0 : }
     516             : 
     517             : // ____ XAnyDescriptionAccess (write) ____
     518           0 : void SAL_CALL ChartDataWrapper::setAnyRowDescriptions( const Sequence< Sequence< uno::Any > >& rRowDescriptions ) throw (uno::RuntimeException, std::exception)
     519             : {
     520           0 :     lcl_AnyRowDescriptionsOperator aOperator( rRowDescriptions );
     521           0 :     applyData( aOperator );
     522           0 : }
     523           0 : void SAL_CALL ChartDataWrapper::setAnyColumnDescriptions( const Sequence< Sequence< uno::Any > >& rColumnDescriptions ) throw (uno::RuntimeException, std::exception)
     524             : {
     525           0 :     lcl_AnyColumnDescriptionsOperator aOperator( rColumnDescriptions );
     526           0 :     applyData( aOperator );
     527           0 : }
     528             : 
     529             : // ____ XDateCategories (write) ____
     530           0 : void SAL_CALL ChartDataWrapper::setDateCategories( const Sequence< double >& rDates ) throw (uno::RuntimeException, std::exception)
     531             : {
     532           0 :     Reference< chart2::XChartDocument > xChartDoc( m_spChart2ModelContact->getChart2Document() );
     533           0 :     ControllerLockGuardUNO aCtrlLockGuard( uno::Reference< frame::XModel >( xChartDoc, uno::UNO_QUERY ));
     534           0 :     lcl_DateCategoriesOperator aOperator( rDates );
     535           0 :     applyData( aOperator );
     536           0 :     DiagramHelper::switchToDateCategories( xChartDoc );
     537           0 : }
     538             : 
     539             : // ____ XChartData (base of XChartDataArray) ____
     540           0 : void SAL_CALL ChartDataWrapper::addChartDataChangeEventListener(
     541             :     const uno::Reference<
     542             :         ::com::sun::star::chart::XChartDataChangeEventListener >& aListener )
     543             :     throw (uno::RuntimeException, std::exception)
     544             : {
     545           0 :     m_aEventListenerContainer.addInterface( aListener );
     546           0 : }
     547             : 
     548           0 : void SAL_CALL ChartDataWrapper::removeChartDataChangeEventListener(
     549             :     const uno::Reference<
     550             :         ::com::sun::star::chart::XChartDataChangeEventListener >& aListener )
     551             :     throw (uno::RuntimeException, std::exception)
     552             : {
     553           0 :     m_aEventListenerContainer.removeInterface( aListener );
     554           0 : }
     555             : 
     556           0 : double SAL_CALL ChartDataWrapper::getNotANumber()
     557             :     throw (uno::RuntimeException, std::exception)
     558             : {
     559           0 :     return DBL_MIN;
     560             : }
     561             : 
     562           0 : sal_Bool SAL_CALL ChartDataWrapper::isNotANumber( double nNumber )
     563             :     throw (uno::RuntimeException, std::exception)
     564             : {
     565             :     return DBL_MIN == nNumber
     566           0 :         || ::rtl::math::isNan( nNumber )
     567           0 :         || ::rtl::math::isInf( nNumber );
     568             : }
     569             : 
     570             : // ____ XComponent ____
     571           0 : void SAL_CALL ChartDataWrapper::dispose()
     572             :     throw (uno::RuntimeException, std::exception)
     573             : {
     574           0 :     m_aEventListenerContainer.disposeAndClear( lang::EventObject( static_cast< ::cppu::OWeakObject* >( this )));
     575           0 :     m_xDataAccess=0;
     576           0 : }
     577             : 
     578           0 : void SAL_CALL ChartDataWrapper::addEventListener(
     579             :     const uno::Reference< lang::XEventListener > & xListener )
     580             :     throw (uno::RuntimeException, std::exception)
     581             : {
     582           0 :     m_aEventListenerContainer.addInterface( xListener );
     583           0 : }
     584             : 
     585           0 : void SAL_CALL ChartDataWrapper::removeEventListener(
     586             :     const uno::Reference< lang::XEventListener >& aListener )
     587             :     throw (uno::RuntimeException, std::exception)
     588             : {
     589           0 :     m_aEventListenerContainer.removeInterface( aListener );
     590           0 : }
     591             : 
     592             : // ____ XEventListener ____
     593           0 : void SAL_CALL ChartDataWrapper::disposing( const lang::EventObject& /* Source */ )
     594             :     throw (uno::RuntimeException, std::exception)
     595             : {
     596           0 : }
     597             : 
     598           0 : void ChartDataWrapper::fireChartDataChangeEvent(
     599             :     ::com::sun::star::chart::ChartDataChangeEvent& aEvent )
     600             : {
     601           0 :     if( ! m_aEventListenerContainer.getLength() )
     602           0 :         return;
     603             : 
     604           0 :     uno::Reference< uno::XInterface > xSrc( static_cast< cppu::OWeakObject* >( this ));
     605             :     OSL_ASSERT( xSrc.is());
     606           0 :     if( xSrc.is() )
     607           0 :         aEvent.Source = xSrc;
     608             : 
     609           0 :     ::cppu::OInterfaceIteratorHelper aIter( m_aEventListenerContainer );
     610             : 
     611           0 :     while( aIter.hasMoreElements() )
     612             :     {
     613             :         uno::Reference<
     614             :             ::com::sun::star::chart::XChartDataChangeEventListener > xListener(
     615           0 :                 aIter.next(), uno::UNO_QUERY );
     616           0 :         if( xListener.is() )
     617           0 :             xListener->chartDataChanged( aEvent );
     618           0 :     }
     619             : }
     620             : 
     621           0 : void ChartDataWrapper::switchToInternalDataProvider()
     622             : {
     623             :     //create an internal data provider that is connected to the model
     624           0 :     Reference< chart2::XChartDocument > xChartDoc( m_spChart2ModelContact->getChart2Document() );
     625           0 :     if( xChartDoc.is() )
     626           0 :         xChartDoc->createInternalDataProvider( true /*bCloneExistingData*/ );
     627           0 :     initDataAccess();
     628           0 : }
     629             : 
     630           0 : void ChartDataWrapper::initDataAccess()
     631             : {
     632           0 :     Reference< chart2::XChartDocument > xChartDoc( m_spChart2ModelContact->getChart2Document() );
     633           0 :     if( !xChartDoc.is() )
     634           0 :         return;
     635           0 :     if( xChartDoc->hasInternalDataProvider() )
     636           0 :         m_xDataAccess = Reference< XAnyDescriptionAccess >( xChartDoc->getDataProvider(), uno::UNO_QUERY_THROW );
     637             :     else
     638             :     {
     639             :         //create a separate "internal data provider" that is not connected to the model
     640           0 :         m_xDataAccess = Reference< XAnyDescriptionAccess >( ChartModelHelper::createInternalDataProvider(
     641           0 :             xChartDoc, false /*bConnectToModel*/ ), uno::UNO_QUERY_THROW );
     642           0 :     }
     643             : }
     644             : 
     645           0 : void ChartDataWrapper::applyData( lcl_Operator& rDataOperator )
     646             : {
     647             :     //bool bSetValues, bool bSetRowDescriptions, bool bSetColumnDescriptions
     648           0 :     Reference< chart2::XChartDocument > xChartDoc( m_spChart2ModelContact->getChart2Document() );
     649           0 :     if( !xChartDoc.is() )
     650           0 :         return;
     651             : 
     652             :     // remember some diagram properties to reset later
     653           0 :     sal_Bool bStacked = sal_False;
     654           0 :     sal_Bool bPercent = sal_False;
     655           0 :     sal_Bool bDeep = sal_False;
     656           0 :     uno::Reference< ::com::sun::star::chart::XChartDocument > xOldDoc( xChartDoc, uno::UNO_QUERY );
     657             :     OSL_ASSERT( xOldDoc.is());
     658           0 :     uno::Reference< beans::XPropertySet > xDiaProp( xOldDoc->getDiagram(), uno::UNO_QUERY );
     659           0 :     if( xDiaProp.is())
     660             :     {
     661           0 :         xDiaProp->getPropertyValue("Stacked") >>= bStacked;
     662           0 :         xDiaProp->getPropertyValue("Percent") >>= bPercent;
     663           0 :         xDiaProp->getPropertyValue("Deep") >>= bDeep;
     664             :     }
     665             : 
     666             :     //detect arguments for the new data source
     667           0 :     OUString aRangeString;
     668           0 :     bool bUseColumns = true;
     669           0 :     bool bFirstCellAsLabel = true;
     670           0 :     bool bHasCategories = true;
     671           0 :     uno::Sequence< sal_Int32 > aSequenceMapping;
     672             : 
     673             :     DataSourceHelper::detectRangeSegmentation(
     674             :         uno::Reference< frame::XModel >( xChartDoc, uno::UNO_QUERY ),
     675           0 :         aRangeString, aSequenceMapping, bUseColumns, bFirstCellAsLabel, bHasCategories );
     676             : 
     677           0 :     if( !bHasCategories && rDataOperator.setsCategories( bUseColumns ) )
     678           0 :         bHasCategories = true;
     679             : 
     680           0 :     aRangeString = "all";
     681             :     uno::Sequence< beans::PropertyValue > aArguments( DataSourceHelper::createArguments(
     682           0 :             aRangeString, aSequenceMapping, bUseColumns, bFirstCellAsLabel, bHasCategories ) );
     683             : 
     684             :     // /-- locked controllers
     685           0 :     ControllerLockGuardUNO aCtrlLockGuard( uno::Reference< frame::XModel >( xChartDoc, uno::UNO_QUERY ));
     686             : 
     687             :     // create and attach new data source
     688           0 :     switchToInternalDataProvider();
     689           0 :     rDataOperator.apply(m_xDataAccess);
     690           0 :     uno::Reference< chart2::data::XDataProvider > xDataProvider( xChartDoc->getDataProvider() );
     691             :     OSL_ASSERT( xDataProvider.is() );
     692           0 :     if( !xDataProvider.is() )
     693           0 :         return;
     694           0 :     uno::Reference< chart2::data::XDataSource > xSource( xDataProvider->createDataSource( aArguments ) );
     695             : 
     696           0 :     uno::Reference< chart2::XDiagram > xDia( xChartDoc->getFirstDiagram() );
     697           0 :     if( xDia.is() )
     698           0 :         xDia->setDiagramData( xSource, aArguments );
     699             : 
     700             :     //correct stacking mode
     701           0 :     if( bStacked || bPercent || bDeep )
     702             :     {
     703           0 :         StackMode eStackMode = StackMode_Y_STACKED;
     704           0 :         if( bDeep )
     705           0 :             eStackMode = StackMode_Z_STACKED;
     706           0 :         else if( bPercent )
     707           0 :             eStackMode = StackMode_Y_STACKED_PERCENT;
     708           0 :         DiagramHelper::setStackMode( xDia, eStackMode );
     709             :     }
     710             : 
     711             :     // notify listeners
     712             :     ::com::sun::star::chart::ChartDataChangeEvent aEvent(
     713             :         static_cast< ::cppu::OWeakObject* >( this ),
     714           0 :         ::com::sun::star::chart::ChartDataChangeType_ALL, 0, 0, 0, 0 );
     715           0 :     fireChartDataChangeEvent( aEvent );
     716             :     // \-- locked controllers
     717             : }
     718             : 
     719           0 : uno::Sequence< OUString > ChartDataWrapper::getSupportedServiceNames_Static()
     720             : {
     721           0 :     uno::Sequence< OUString > aServices( 2 );
     722           0 :     aServices[ 0 ] = "com.sun.star.chart.ChartDataArray";
     723           0 :     aServices[ 1 ] = "com.sun.star.chart.ChartData";
     724             : 
     725           0 :     return aServices;
     726             : }
     727             : 
     728             : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     729           0 : APPHELPER_XSERVICEINFO_IMPL( ChartDataWrapper, lcl_aServiceName );
     730             : 
     731             : } //  namespace wrapper
     732           0 : } //  namespace chart
     733             : 
     734             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10