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

Generated by: LCOV version 1.10