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

Generated by: LCOV version 1.10