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

Generated by: LCOV version 1.10