LCOV - code coverage report
Current view: top level - sc/source/filter/oox - excelchartconverter.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 33 38 86.8 %
Date: 2014-04-11 Functions: 7 7 100.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 "excelchartconverter.hxx"
      21             : 
      22             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      23             : #include <com/sun/star/chart2/data/XDataProvider.hpp>
      24             : #include <com/sun/star/chart2/data/XDataReceiver.hpp>
      25             : #include <com/sun/star/chart2/data/XSheetDataProvider.hpp>
      26             : 
      27             : #include "oox/core/filterbase.hxx"
      28             : #include "oox/drawingml/chart/datasourcemodel.hxx"
      29             : #include "oox/helper/containerhelper.hxx"
      30             : #include "formulaparser.hxx"
      31             : 
      32             : namespace oox {
      33             : namespace xls {
      34             : 
      35             : using namespace ::com::sun::star::chart2;
      36             : using namespace ::com::sun::star::chart2::data;
      37             : using namespace ::com::sun::star::lang;
      38             : using namespace ::com::sun::star::table;
      39             : using namespace ::com::sun::star::uno;
      40             : 
      41             : using ::oox::drawingml::chart::DataSequenceModel;
      42             : 
      43          44 : ExcelChartConverter::ExcelChartConverter( const WorkbookHelper& rHelper ) :
      44          44 :     WorkbookHelper( rHelper )
      45             : {
      46          44 : }
      47             : 
      48          88 : ExcelChartConverter::~ExcelChartConverter()
      49             : {
      50          88 : }
      51             : 
      52          10 : void ExcelChartConverter::createDataProvider( const Reference< XChartDocument >& rxChartDoc )
      53             : {
      54             :     try
      55             :     {
      56          10 :         Reference< XDataReceiver > xDataRec( rxChartDoc, UNO_QUERY_THROW );
      57          10 :         Reference< XDataProvider > xDataProv( getBaseFilter().getModelFactory()->createInstance(
      58          20 :             "com.sun.star.chart2.data.DataProvider" ), UNO_QUERY_THROW );
      59          20 :         xDataRec->attachDataProvider( xDataProv );
      60             :     }
      61           0 :     catch( Exception& )
      62             :     {
      63             :     }
      64          10 : }
      65             : 
      66          46 : Reference< XDataSequence > ExcelChartConverter::createDataSequence(
      67             :         const Reference< XDataProvider >& rxDataProvider, const DataSequenceModel& rDataSeq )
      68             : {
      69          46 :     Reference< XDataSequence > xDataSeq;
      70          46 :     if (!rxDataProvider.is())
      71           0 :         return xDataSeq;
      72             : 
      73          92 :     Reference<XSheetDataProvider> xSheetProvider(rxDataProvider, UNO_QUERY);
      74          46 :     if (!xSheetProvider.is())
      75           0 :         return xDataSeq;
      76             : 
      77          46 :     if (!rDataSeq.maFormula.isEmpty())
      78             :     {
      79             :         // parse the formula string, create a token sequence
      80          39 :         FormulaParser& rParser = getFormulaParser();
      81          39 :         CellAddress aBaseAddr( getCurrentSheetIndex(), 0, 0 );
      82          39 :         ApiTokenSequence aTokens = rParser.importFormula( aBaseAddr, rDataSeq.maFormula );
      83             : 
      84             :         try
      85             :         {
      86             :             // create the data sequence
      87          39 :             xDataSeq = xSheetProvider->createDataSequenceByFormulaTokens(aTokens);
      88             :         }
      89           0 :         catch (Exception&)
      90             :         {
      91             :             OSL_FAIL( "ExcelChartConverter::createDataSequence - cannot create data sequence" );
      92          39 :         }
      93             :     }
      94           7 :     else if (!rDataSeq.maData.empty())
      95             :     {
      96             :         // create a single-row array from constant source data
      97           7 :         Matrix< Any > aMatrix( rDataSeq.maData.size(), 1 );
      98           7 :         Matrix< Any >::iterator aMIt = aMatrix.begin();
      99             :         // TODO: how to handle missing values in the map?
     100          34 :         for( DataSequenceModel::AnyMap::const_iterator aDIt = rDataSeq.maData.begin(), aDEnd = rDataSeq.maData.end(); aDIt != aDEnd; ++aDIt, ++aMIt )
     101          27 :             *aMIt = aDIt->second;
     102          14 :         OUString aRangeRep = FormulaProcessorBase::generateApiArray( aMatrix );
     103             : 
     104           7 :         if (!aRangeRep.isEmpty())
     105             :         {
     106             :             try
     107             :             {
     108             :                 // create the data sequence
     109           7 :                 xDataSeq = rxDataProvider->createDataSequenceByRangeRepresentation( aRangeRep );
     110             :             }
     111           0 :             catch (Exception&)
     112             :             {
     113             :                 OSL_FAIL( "ExcelChartConverter::createDataSequence - cannot create data sequence" );
     114             :             }
     115           7 :         }
     116             :     }
     117          46 :     return xDataSeq;
     118             : }
     119             : 
     120             : } // namespace xls
     121          18 : } // namespace oox
     122             : 
     123             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10