LCOV - code coverage report
Current view: top level - sc/source/filter/oox - excelchartconverter.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 6 36 16.7 %
Date: 2012-08-25 Functions: 5 7 71.4 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 4 74 5.4 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "excelchartconverter.hxx"
      30                 :            : 
      31                 :            : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      32                 :            : #include <com/sun/star/chart2/data/XDataProvider.hpp>
      33                 :            : #include <com/sun/star/chart2/data/XDataReceiver.hpp>
      34                 :            : #include <com/sun/star/chart2/data/XSheetDataProvider.hpp>
      35                 :            : 
      36                 :            : #include "oox/core/filterbase.hxx"
      37                 :            : #include "oox/drawingml/chart/datasourcemodel.hxx"
      38                 :            : #include "oox/helper/containerhelper.hxx"
      39                 :            : #include "formulaparser.hxx"
      40                 :            : 
      41                 :            : namespace oox {
      42                 :            : namespace xls {
      43                 :            : 
      44                 :            : // ============================================================================
      45                 :            : 
      46                 :            : using namespace ::com::sun::star::chart2;
      47                 :            : using namespace ::com::sun::star::chart2::data;
      48                 :            : using namespace ::com::sun::star::lang;
      49                 :            : using namespace ::com::sun::star::table;
      50                 :            : using namespace ::com::sun::star::uno;
      51                 :            : 
      52                 :            : using ::oox::drawingml::chart::DataSequenceModel;
      53                 :            : using ::rtl::OUString;
      54                 :            : 
      55                 :            : // ============================================================================
      56                 :            : 
      57                 :         24 : ExcelChartConverter::ExcelChartConverter( const WorkbookHelper& rHelper ) :
      58                 :         24 :     WorkbookHelper( rHelper )
      59                 :            : {
      60                 :         24 : }
      61                 :            : 
      62         [ +  - ]:         24 : ExcelChartConverter::~ExcelChartConverter()
      63                 :            : {
      64         [ -  + ]:         48 : }
      65                 :            : 
      66                 :          0 : void ExcelChartConverter::createDataProvider( const Reference< XChartDocument >& rxChartDoc )
      67                 :            : {
      68                 :            :     try
      69                 :            :     {
      70         [ #  # ]:          0 :         Reference< XDataReceiver > xDataRec( rxChartDoc, UNO_QUERY_THROW );
      71 [ #  # ][ #  # ]:          0 :         Reference< XDataProvider > xDataProv( getBaseFilter().getModelFactory()->createInstance(
                 [ #  # ]
      72 [ #  # ][ #  # ]:          0 :             CREATE_OUSTRING( "com.sun.star.chart2.data.DataProvider" ) ), UNO_QUERY_THROW );
                 [ #  # ]
      73 [ #  # ][ #  # ]:          0 :         xDataRec->attachDataProvider( xDataProv );
                 [ #  # ]
      74                 :            :     }
      75                 :          0 :     catch( Exception& )
      76                 :            :     {
      77                 :            :     }
      78                 :          0 : }
      79                 :            : 
      80                 :          0 : Reference< XDataSequence > ExcelChartConverter::createDataSequence(
      81                 :            :         const Reference< XDataProvider >& rxDataProvider, const DataSequenceModel& rDataSeq )
      82                 :            : {
      83                 :          0 :     Reference< XDataSequence > xDataSeq;
      84         [ #  # ]:          0 :     if (!rxDataProvider.is())
      85                 :            :         return xDataSeq;
      86                 :            : 
      87         [ #  # ]:          0 :     Reference<XSheetDataProvider> xSheetProvider(rxDataProvider, UNO_QUERY);
      88         [ #  # ]:          0 :     if (!xSheetProvider.is())
      89                 :            :         return xDataSeq;
      90                 :            : 
      91         [ #  # ]:          0 :     if (!rDataSeq.maFormula.isEmpty())
      92                 :            :     {
      93                 :            :         // parse the formula string, create a token sequence
      94         [ #  # ]:          0 :         FormulaParser& rParser = getFormulaParser();
      95         [ #  # ]:          0 :         CellAddress aBaseAddr( getCurrentSheetIndex(), 0, 0 );
      96         [ #  # ]:          0 :         ApiTokenSequence aTokens = rParser.importFormula( aBaseAddr, rDataSeq.maFormula );
      97                 :            : 
      98                 :            :         try
      99                 :            :         {
     100                 :            :             // create the data sequence
     101 [ #  # ][ #  # ]:          0 :             xDataSeq = xSheetProvider->createDataSequenceByFormulaTokens(aTokens);
         [ #  # ][ #  # ]
     102                 :            :         }
     103         [ #  # ]:          0 :         catch (Exception&)
     104                 :            :         {
     105                 :            :             OSL_FAIL( "ExcelChartConverter::createDataSequence - cannot create data sequence" );
     106         [ #  # ]:          0 :         }
     107                 :            :     }
     108         [ #  # ]:          0 :     else if (!rDataSeq.maData.empty())
     109                 :            :     {
     110                 :            :         // create a single-row array from constant source data
     111         [ #  # ]:          0 :         Matrix< Any > aMatrix( rDataSeq.maData.size(), 1 );
     112                 :          0 :         Matrix< Any >::iterator aMIt = aMatrix.begin();
     113                 :            :         // TODO: how to handle missing values in the map?
     114         [ #  # ]:          0 :         for( DataSequenceModel::AnyMap::const_iterator aDIt = rDataSeq.maData.begin(), aDEnd = rDataSeq.maData.end(); aDIt != aDEnd; ++aDIt, ++aMIt )
     115                 :          0 :             *aMIt = aDIt->second;
     116         [ #  # ]:          0 :         OUString aRangeRep = FormulaProcessorBase::generateApiArray( aMatrix );
     117                 :            : 
     118         [ #  # ]:          0 :         if (!aRangeRep.isEmpty())
     119                 :            :         {
     120                 :            :             try
     121                 :            :             {
     122                 :            :                 // create the data sequence
     123 [ #  # ][ #  # ]:          0 :                 xDataSeq = rxDataProvider->createDataSequenceByRangeRepresentation( aRangeRep );
         [ #  # ][ #  # ]
     124                 :            :             }
     125         [ #  # ]:          0 :             catch (Exception&)
     126                 :            :             {
     127                 :            :                 OSL_FAIL( "ExcelChartConverter::createDataSequence - cannot create data sequence" );
     128                 :            :             }
     129                 :          0 :         }
     130                 :            :     }
     131                 :          0 :     return xDataSeq;
     132                 :            : }
     133                 :            : 
     134                 :            : // ============================================================================
     135                 :            : 
     136                 :            : } // namespace xls
     137 [ +  - ][ +  - ]:         24 : } // namespace oox
     138                 :            : 
     139                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10