LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/oox/source/drawingml/chart - chartconverter.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 11 57 19.3 %
Date: 2013-07-09 Functions: 6 10 60.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 "oox/drawingml/chart/chartconverter.hxx"
      21             : 
      22             : #include <com/sun/star/chart2/XChartDocument.hpp>
      23             : #include "oox/drawingml/chart/chartspaceconverter.hxx"
      24             : #include "oox/drawingml/chart/chartspacemodel.hxx"
      25             : #include "oox/helper/containerhelper.hxx"
      26             : #include "oox/core/xmlfilterbase.hxx"
      27             : 
      28             : using ::oox::drawingml::chart::DataSequenceModel;
      29             : using ::com::sun::star::uno::Any;
      30             : namespace oox {
      31             : namespace drawingml {
      32             : namespace chart {
      33             : 
      34             : // ============================================================================
      35             : 
      36             : using namespace ::com::sun::star;
      37             : using namespace ::com::sun::star::chart2;
      38             : using namespace ::com::sun::star::chart2::data;
      39             : using namespace ::com::sun::star::drawing;
      40             : using namespace ::com::sun::star::uno;
      41             : 
      42             : using ::oox::core::XmlFilterBase;
      43             : 
      44             : // ============================================================================
      45             : 
      46             : static const sal_Unicode API_TOKEN_ARRAY_OPEN      = '{';
      47             : static const sal_Unicode API_TOKEN_ARRAY_CLOSE     = '}';
      48             : static const sal_Unicode API_TOKEN_ARRAY_ROWSEP    = '|';
      49             : static const sal_Unicode API_TOKEN_ARRAY_COLSEP    = ';';
      50             : 
      51             : // Code similar to oox/source/xls/formulabase.cxx
      52           0 : static OUString lclGenerateApiString( const OUString& rString )
      53             : {
      54           0 :     OUString aRetString = rString;
      55           0 :     sal_Int32 nQuotePos = aRetString.getLength();
      56           0 :     while( (nQuotePos = aRetString.lastIndexOf( '"', nQuotePos )) >= 0 )
      57           0 :         aRetString = aRetString.replaceAt( nQuotePos, 1, "\"\"" );
      58           0 :     return OUStringBuffer().append( sal_Unicode( '"' ) ).append( aRetString ).append( sal_Unicode( '"' ) ).makeStringAndClear();
      59             : }
      60             : 
      61           0 : static OUString lclGenerateApiArray( const Matrix< Any >& rMatrix )
      62             : {
      63             :     OSL_ENSURE( !rMatrix.empty(), "ChartConverter::lclGenerateApiArray - missing matrix values" );
      64           0 :     OUStringBuffer aBuffer;
      65           0 :     aBuffer.append( API_TOKEN_ARRAY_OPEN );
      66           0 :     for( size_t nRow = 0, nHeight = rMatrix.height(); nRow < nHeight; ++nRow )
      67             :     {
      68           0 :         if( nRow > 0 )
      69           0 :             aBuffer.append( API_TOKEN_ARRAY_ROWSEP );
      70           0 :         for( Matrix< Any >::const_iterator aBeg = rMatrix.row_begin( nRow ), aIt = aBeg, aEnd = rMatrix.row_end( nRow ); aIt != aEnd; ++aIt )
      71             :         {
      72           0 :             double fValue = 0.0;
      73           0 :             OUString aString;
      74           0 :             if( aIt != aBeg )
      75           0 :                 aBuffer.append( API_TOKEN_ARRAY_COLSEP );
      76           0 :             if( *aIt >>= fValue )
      77           0 :                 aBuffer.append( fValue );
      78           0 :             else if( *aIt >>= aString )
      79           0 :                 aBuffer.append( lclGenerateApiString( aString ) );
      80             :             else
      81           0 :                 aBuffer.appendAscii( "\"\"" );
      82           0 :         }
      83             :     }
      84           0 :     aBuffer.append( API_TOKEN_ARRAY_CLOSE );
      85           0 :     return aBuffer.makeStringAndClear();
      86             : }
      87             : 
      88             : // ============================================================================
      89             : 
      90          73 : ChartConverter::ChartConverter()
      91             : {
      92          73 : }
      93             : 
      94         125 : ChartConverter::~ChartConverter()
      95             : {
      96         125 : }
      97             : 
      98           2 : void ChartConverter::convertFromModel( XmlFilterBase& rFilter,
      99             :         ChartSpaceModel& rChartModel, const Reference< XChartDocument >& rxChartDoc,
     100             :         const Reference< XShapes >& rxExternalPage, const awt::Point& rChartPos, const awt::Size& rChartSize )
     101             : {
     102             :     OSL_ENSURE( rxChartDoc.is(), "ChartConverter::convertFromModel - missing chart document" );
     103           2 :     if( rxChartDoc.is() )
     104             :     {
     105           2 :         ConverterRoot aConvBase( rFilter, *this, rChartModel, rxChartDoc, rChartSize );
     106           4 :         ChartSpaceConverter aSpaceConv( aConvBase, rChartModel );
     107           4 :         aSpaceConv.convertFromModel( rxExternalPage, rChartPos );
     108             :     }
     109           2 : }
     110             : 
     111           0 : void ChartConverter::createDataProvider( const Reference< XChartDocument >& rxChartDoc )
     112             : {
     113             :     try
     114             :     {
     115           0 :         if( !rxChartDoc->hasInternalDataProvider() )
     116           0 :             rxChartDoc->createInternalDataProvider( sal_False );
     117             :     }
     118           0 :     catch( Exception& )
     119             :     {
     120             :     }
     121           0 : }
     122             : 
     123           0 : Reference< XDataSequence > ChartConverter::createDataSequence( const Reference< XDataProvider >& rxDataProvider, const DataSequenceModel& rDataSeq )
     124             : {
     125           0 :     Reference< XDataSequence > xDataSeq;
     126           0 :     if( rxDataProvider.is() )
     127             :     {
     128           0 :         OUString aRangeRep;
     129           0 :         if( !rDataSeq.maData.empty() )
     130             :         {
     131             :             // create a single-row array from constant source data
     132           0 :             Matrix< Any > aMatrix( rDataSeq.maData.size(), 1 );
     133           0 :             Matrix< Any >::iterator aMIt = aMatrix.begin();
     134             :             // TODO: how to handle missing values in the map?
     135           0 :             for( DataSequenceModel::AnyMap::const_iterator aDIt = rDataSeq.maData.begin(), aDEnd = rDataSeq.maData.end(); aDIt != aDEnd; ++aDIt, ++aMIt )
     136           0 :                 *aMIt = aDIt->second;
     137           0 :             aRangeRep = lclGenerateApiArray( aMatrix );
     138             :         }
     139             : 
     140           0 :         if( !aRangeRep.isEmpty() ) try
     141             :         {
     142             :             // create the data sequence
     143           0 :             xDataSeq = rxDataProvider->createDataSequenceByRangeRepresentation( aRangeRep );
     144           0 :             return xDataSeq;
     145             :         }
     146           0 :         catch( Exception& )
     147             :         {
     148             :             OSL_FAIL( "ChartConverter::createDataSequence - cannot create data sequence" );
     149           0 :         }
     150             :     }
     151             : 
     152           0 :     return 0;
     153             : }
     154             : 
     155             : // ============================================================================
     156             : 
     157             : } // namespace chart
     158             : } // namespace drawingml
     159         141 : } // namespace oox
     160             : 
     161             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10