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

Generated by: LCOV version 1.10