LCOV - code coverage report
Current view: top level - xmloff/source/chart - SchXMLSeriesHelper.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 78 101 77.2 %
Date: 2015-06-13 12:38:46 Functions: 5 6 83.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 <xmloff/SchXMLSeriesHelper.hxx>
      21             : #include <com/sun/star/chart2/XChartDocument.hpp>
      22             : #include <com/sun/star/chart2/XChartTypeContainer.hpp>
      23             : #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
      24             : #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
      25             : #include <com/sun/star/lang/XInitialization.hpp>
      26             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      27             : 
      28             : #include <rtl/ustring.h>
      29             : 
      30             : #include <typeinfo>
      31             : 
      32             : using namespace ::com::sun::star;
      33             : 
      34             : using ::com::sun::star::uno::Reference;
      35             : using ::com::sun::star::uno::Sequence;
      36             : 
      37             : ::std::vector< Reference< chart2::XDataSeries > >
      38         864 :     SchXMLSeriesHelper::getDataSeriesFromDiagram(
      39             :         const Reference< chart2::XDiagram > & xDiagram )
      40             : {
      41         864 :     ::std::vector< Reference< chart2::XDataSeries > > aResult;
      42             : 
      43             :     try
      44             :     {
      45             :         Reference< chart2::XCoordinateSystemContainer > xCooSysCnt(
      46         864 :             xDiagram, uno::UNO_QUERY_THROW );
      47             :         Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq(
      48        1728 :             xCooSysCnt->getCoordinateSystems());
      49        1728 :         for( sal_Int32 i=0; i<aCooSysSeq.getLength(); ++i )
      50             :         {
      51         864 :             Reference< chart2::XChartTypeContainer > xCTCnt( aCooSysSeq[i], uno::UNO_QUERY_THROW );
      52        1728 :             Sequence< Reference< chart2::XChartType > > aChartTypeSeq( xCTCnt->getChartTypes());
      53        1804 :             for( sal_Int32 j=0; j<aChartTypeSeq.getLength(); ++j )
      54             :             {
      55         940 :                 Reference< chart2::XDataSeriesContainer > xDSCnt( aChartTypeSeq[j], uno::UNO_QUERY_THROW );
      56        1880 :                 Sequence< Reference< chart2::XDataSeries > > aSeriesSeq( xDSCnt->getDataSeries() );
      57             :                 ::std::copy( aSeriesSeq.begin(), aSeriesSeq.end(),
      58         940 :                              ::std::back_inserter( aResult ));
      59         940 :             }
      60        1728 :         }
      61             :     }
      62           0 :     catch( const uno::Exception & ex )
      63             :     {
      64             :         SAL_WARN("xmloff.chart", "Exception caught. Type: " << OUString::createFromAscii( typeid( ex ).name() ) << ", Message: " << ex.Message );
      65             :     }
      66             : 
      67         864 :     return aResult;
      68             : }
      69             : 
      70           0 : ::std::map< Reference< chart2::XDataSeries >, sal_Int32 > SchXMLSeriesHelper::getDataSeriesIndexMapFromDiagram(
      71             :         const Reference< chart2::XDiagram > & xDiagram )
      72             : {
      73           0 :     ::std::map< Reference< chart2::XDataSeries >, sal_Int32 > aRet;
      74             : 
      75           0 :     sal_Int32 nIndex=0;
      76             : 
      77           0 :     ::std::vector< Reference< chart2::XDataSeries > > aSeriesVector( SchXMLSeriesHelper::getDataSeriesFromDiagram( xDiagram ));
      78           0 :     const ::std::vector< Reference< chart2::XDataSeries > >::const_iterator aSeriesEnd( aSeriesVector.end() );
      79           0 :     for( ::std::vector< Reference< chart2::XDataSeries > >::const_iterator aSeriesIt( aSeriesVector.begin() )
      80             :         ; aSeriesIt != aSeriesEnd
      81             :         ; ++aSeriesIt, nIndex++ )
      82             :     {
      83           0 :         Reference< chart2::XDataSeries > xSeries( *aSeriesIt );
      84           0 :         if( xSeries.is() )
      85             :         {
      86           0 :             if( aRet.end() == aRet.find(xSeries) )
      87           0 :                 aRet[xSeries]=nIndex;
      88             :         }
      89           0 :     }
      90           0 :     return aRet;
      91             : }
      92             : 
      93             : namespace {
      94           1 : uno::Reference< chart2::XChartType > lcl_getChartTypeOfSeries(
      95             :                                 const uno::Reference< chart2::XDiagram >&   xDiagram
      96             :                               , const Reference< chart2::XDataSeries >& xSeries )
      97             : {
      98           1 :     if(!xDiagram.is())
      99           0 :         return 0;
     100             : 
     101             :     //iterate through the model to find the given xSeries
     102             :     //the found parent indicates the charttype
     103             : 
     104             :     //iterate through all coordinate systems
     105           1 :     uno::Reference< chart2::XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY );
     106           1 :     if( !xCooSysContainer.is())
     107           0 :         return 0;
     108             : 
     109           2 :     uno::Sequence< uno::Reference< chart2::XCoordinateSystem > > aCooSysList( xCooSysContainer->getCoordinateSystems() );
     110           1 :     for( sal_Int32 nCS = 0; nCS < aCooSysList.getLength(); ++nCS )
     111             :     {
     112           1 :         uno::Reference< chart2::XCoordinateSystem > xCooSys( aCooSysList[nCS] );
     113             : 
     114             :         //iterate through all chart types in the current coordinate system
     115           1 :         uno::Reference< chart2::XChartTypeContainer > xChartTypeContainer( xCooSys, uno::UNO_QUERY );
     116             :         SAL_WARN_IF( !xChartTypeContainer.is(), "xmloff.chart", "xChartTypeContainer is NULL");
     117           1 :         if( !xChartTypeContainer.is() )
     118           0 :             continue;
     119           1 :         uno::Sequence< uno::Reference< chart2::XChartType > > aChartTypeList( xChartTypeContainer->getChartTypes() );
     120           1 :         for( sal_Int32 nT = 0; nT < aChartTypeList.getLength(); ++nT )
     121             :         {
     122           1 :             uno::Reference< chart2::XChartType > xChartType( aChartTypeList[nT] );
     123             : 
     124             :             //iterate through all series in this chart type
     125           1 :             uno::Reference< chart2::XDataSeriesContainer > xDataSeriesContainer( xChartType, uno::UNO_QUERY );
     126             :             SAL_WARN_IF( !xDataSeriesContainer.is(), "xmloff.chart", "xDataSeriesContainer is NULL");
     127           1 :             if( !xDataSeriesContainer.is() )
     128           0 :                 continue;
     129             : 
     130           1 :             uno::Sequence< uno::Reference< chart2::XDataSeries > > aSeriesList( xDataSeriesContainer->getDataSeries() );
     131           1 :             for( sal_Int32 nS = 0; nS < aSeriesList.getLength(); ++nS )
     132             :             {
     133           1 :                 Reference< chart2::XDataSeries > xCurrentSeries( aSeriesList[nS] );
     134             : 
     135           1 :                 if( xSeries == xCurrentSeries )
     136           1 :                     return xChartType;
     137           0 :             }
     138           0 :         }
     139           0 :     }
     140           1 :     return 0;
     141             : }
     142             : }
     143             : 
     144           1 : bool SchXMLSeriesHelper::isCandleStickSeries(
     145             :                   const Reference< chart2::XDataSeries >& xSeries
     146             :                 , const Reference< frame::XModel >& xChartModel )
     147             : {
     148           1 :     bool bRet = false;
     149             : 
     150           1 :     uno::Reference< chart2::XChartDocument > xNewDoc( xChartModel, uno::UNO_QUERY );
     151           1 :     if( xNewDoc.is() )
     152             :     {
     153           1 :         uno::Reference< chart2::XDiagram > xNewDiagram( xNewDoc->getFirstDiagram() );
     154           1 :         if( xNewDiagram.is() )
     155             :         {
     156             :             uno::Reference< chart2::XChartType > xChartType( lcl_getChartTypeOfSeries(
     157           1 :                                         xNewDiagram, xSeries ) );
     158           1 :             if( xChartType.is() )
     159             :             {
     160           1 :                 OUString aServiceName( xChartType->getChartType() );
     161           1 :                 if( aServiceName == "com.sun.star.chart2.CandleStickChartType" )
     162           0 :                     bRet = true;
     163           1 :             }
     164           1 :         }
     165             :     }
     166           1 :     return bRet;
     167             : }
     168             : 
     169             : //static
     170        1481 : uno::Reference< beans::XPropertySet > SchXMLSeriesHelper::createOldAPISeriesPropertySet(
     171             :             const uno::Reference< chart2::XDataSeries >& xSeries
     172             :             , const uno::Reference< frame::XModel >& xChartModel )
     173             : {
     174        1481 :     uno::Reference< beans::XPropertySet > xRet;
     175             : 
     176        1481 :     if( xSeries.is() )
     177             :     {
     178             :         try
     179             :         {
     180        1481 :             uno::Reference< lang::XMultiServiceFactory > xFactory( xChartModel, uno::UNO_QUERY );
     181        1481 :             if( xFactory.is() )
     182             :             {
     183        4443 :                 xRet = uno::Reference< beans::XPropertySet >( xFactory->createInstance(
     184        2962 :                     "com.sun.star.comp.chart2.DataSeriesWrapper" ), uno::UNO_QUERY );
     185        1481 :                 Reference< lang::XInitialization > xInit( xRet, uno::UNO_QUERY );
     186        1481 :                 if(xInit.is())
     187             :                 {
     188        1481 :                     Sequence< uno::Any > aArguments(1);
     189        1481 :                     aArguments[0]=uno::makeAny(xSeries);
     190        1481 :                     xInit->initialize(aArguments);
     191        1481 :                 }
     192        1481 :             }
     193             :         }
     194           0 :         catch( const uno::Exception & rEx )
     195             :         {
     196             :             SAL_INFO("xmloff.chart", "Exception caught SchXMLSeriesHelper::createOldAPISeriesPropertySet: " << rEx.Message );
     197             :         }
     198             :     }
     199             : 
     200        1481 :     return xRet;
     201             : }
     202             : 
     203             : //static
     204        1096 : uno::Reference< beans::XPropertySet > SchXMLSeriesHelper::createOldAPIDataPointPropertySet(
     205             :             const uno::Reference< chart2::XDataSeries >& xSeries
     206             :             , sal_Int32 nPointIndex
     207             :             , const uno::Reference< frame::XModel >& xChartModel )
     208             : {
     209        1096 :     uno::Reference< beans::XPropertySet > xRet;
     210             : 
     211        1096 :     if( xSeries.is() )
     212             :     {
     213             :         try
     214             :         {
     215        1096 :             uno::Reference< lang::XMultiServiceFactory > xFactory( xChartModel, uno::UNO_QUERY );
     216        1096 :             if( xFactory.is() )
     217             :             {
     218        3288 :                 xRet = uno::Reference< beans::XPropertySet >( xFactory->createInstance(
     219        2192 :                      "com.sun.star.comp.chart2.DataSeriesWrapper" ), uno::UNO_QUERY );
     220        1096 :                 Reference< lang::XInitialization > xInit( xRet, uno::UNO_QUERY );
     221        1096 :                 if(xInit.is())
     222             :                 {
     223        1096 :                     Sequence< uno::Any > aArguments(2);
     224        1096 :                     aArguments[0]=uno::makeAny(xSeries);
     225        1096 :                     aArguments[1]=uno::makeAny(nPointIndex);
     226        1096 :                     xInit->initialize(aArguments);
     227        1096 :                 }
     228        1096 :             }
     229             :         }
     230           0 :         catch( const uno::Exception & rEx )
     231             :         {
     232             :             SAL_INFO("xmloff.chart", "Exception caught SchXMLSeriesHelper::createOldAPIDataPointPropertySet: " << rEx.Message );
     233             :         }
     234             :     }
     235             : 
     236        1096 :     return xRet;
     237             : }
     238             : 
     239             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11