LCOV - code coverage report
Current view: top level - oox/source/drawingml/chart - chartconverter.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 5 57 8.8 %
Date: 2012-08-25 Functions: 5 10 50.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 3 108 2.8 %

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

Generated by: LCOV version 1.10