LCOV - code coverage report
Current view: top level - oox/source/drawingml/chart - chartspaceconverter.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 68 1.5 %
Date: 2012-08-25 Functions: 2 6 33.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 2 204 1.0 %

           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/chartspaceconverter.hxx"
      21                 :            : 
      22                 :            : #include <com/sun/star/chart/MissingValueTreatment.hpp>
      23                 :            : #include <com/sun/star/chart/XChartDocument.hpp>
      24                 :            : #include <com/sun/star/chart2/XChartDocument.hpp>
      25                 :            : #include <com/sun/star/chart2/XTitled.hpp>
      26                 :            : #include <com/sun/star/chart2/data/XDataReceiver.hpp>
      27                 :            : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
      28                 :            : #include "oox/core/xmlfilterbase.hxx"
      29                 :            : #include "oox/drawingml/chart/chartconverter.hxx"
      30                 :            : #include "oox/drawingml/chart/chartdrawingfragment.hxx"
      31                 :            : #include "oox/drawingml/chart/chartspacemodel.hxx"
      32                 :            : #include "oox/drawingml/chart/plotareaconverter.hxx"
      33                 :            : #include "oox/drawingml/chart/titleconverter.hxx"
      34                 :            : 
      35                 :            : using ::rtl::OUString;
      36                 :            : using ::com::sun::star::awt::Point;
      37                 :            : using ::com::sun::star::uno::Reference;
      38                 :            : using ::com::sun::star::uno::Exception;
      39                 :            : using ::com::sun::star::uno::UNO_QUERY;
      40                 :            : using ::com::sun::star::uno::UNO_QUERY_THROW;
      41                 :            : using ::com::sun::star::uno::makeAny;
      42                 :            : using ::com::sun::star::util::XNumberFormatsSupplier;
      43                 :            : using ::com::sun::star::drawing::XDrawPageSupplier;
      44                 :            : using ::com::sun::star::drawing::XShapes;
      45                 :            : using ::com::sun::star::chart2::XDiagram;
      46                 :            : using ::com::sun::star::chart2::XTitled;
      47                 :            : using ::com::sun::star::chart2::data::XDataReceiver;
      48                 :            : using ::com::sun::star::beans::XPropertySet;
      49                 :            : 
      50                 :            : namespace oox {
      51                 :            : namespace drawingml {
      52                 :            : namespace chart {
      53                 :            : 
      54                 :            : // ============================================================================
      55                 :            : 
      56                 :            : using namespace ::com::sun::star::awt;
      57                 :            : using namespace ::com::sun::star::chart2;
      58                 :            : using namespace ::com::sun::star::chart2::data;
      59                 :            : using namespace ::com::sun::star::drawing;
      60                 :            : using namespace ::com::sun::star::uno;
      61                 :            : using namespace ::com::sun::star::util;
      62                 :            : 
      63                 :            : using ::rtl::OUString;
      64                 :            : 
      65                 :            : // ============================================================================
      66                 :            : 
      67                 :          0 : ChartSpaceConverter::ChartSpaceConverter( const ConverterRoot& rParent, ChartSpaceModel& rModel ) :
      68                 :          0 :     ConverterBase< ChartSpaceModel >( rParent, rModel )
      69                 :            : {
      70                 :          0 : }
      71                 :            : 
      72                 :          0 : ChartSpaceConverter::~ChartSpaceConverter()
      73                 :            : {
      74         [ #  # ]:          0 : }
      75                 :            : 
      76                 :          0 : void ChartSpaceConverter::convertFromModel( const Reference< XShapes >& rxExternalPage, const Point& rChartPos )
      77                 :            : {
      78 [ #  # ][ #  # ]:          0 :     if( !getChartConverter() )
      79                 :          0 :         return;
      80                 :            : 
      81                 :            :     /*  create data provider (virtual function in the ChartConverter class,
      82                 :            :         derived converters may create an external data provider) */
      83 [ #  # ][ #  # ]:          0 :     getChartConverter()->createDataProvider( getChartDocument() );
                 [ #  # ]
      84                 :            : 
      85                 :            :     // attach number formatter of container document to data receiver
      86                 :            :     try
      87                 :            :     {
      88 [ #  # ][ #  # ]:          0 :         Reference< XDataReceiver > xDataRec( getChartDocument(), UNO_QUERY_THROW );
      89 [ #  # ][ #  # ]:          0 :         Reference< XNumberFormatsSupplier > xNumFmtSupp( getFilter().getModel(), UNO_QUERY_THROW );
                 [ #  # ]
      90 [ #  # ][ #  # ]:          0 :         xDataRec->attachNumberFormatsSupplier( xNumFmtSupp );
                 [ #  # ]
      91                 :            :     }
      92         [ #  # ]:          0 :     catch( Exception& )
      93                 :            :     {
      94                 :            :     }
      95                 :            : 
      96                 :            :     // formatting of the chart background
      97 [ #  # ][ #  # ]:          0 :     PropertySet aBackPropSet( getChartDocument()->getPageBackground() );
         [ #  # ][ #  # ]
      98 [ #  # ][ #  # ]:          0 :     getFormatter().convertFrameFormatting( aBackPropSet, mrModel.mxShapeProp, OBJECTTYPE_CHARTSPACE );
      99                 :            : 
     100                 :            :     // convert plot area (container of all chart type groups)
     101 [ #  # ][ #  # ]:          0 :     PlotAreaConverter aPlotAreaConv( *this, mrModel.mxPlotArea.getOrCreate() );
     102 [ #  # ][ #  # ]:          0 :     aPlotAreaConv.convertFromModel( mrModel.mxView3D.getOrCreate() );
     103                 :            : 
     104                 :            :     // plot area converter has created the diagram object
     105 [ #  # ][ #  # ]:          0 :     Reference< XDiagram > xDiagram = getChartDocument()->getFirstDiagram();
                 [ #  # ]
     106                 :            : 
     107                 :            :     // convert wall and floor formatting in 3D charts
     108 [ #  # ][ #  # ]:          0 :     if( xDiagram.is() && aPlotAreaConv.isWall3dChart() )
                 [ #  # ]
     109                 :            :     {
     110 [ #  # ][ #  # ]:          0 :         WallFloorConverter aFloorConv( *this, mrModel.mxFloor.getOrCreate() );
     111         [ #  # ]:          0 :         aFloorConv.convertFromModel( xDiagram, OBJECTTYPE_FLOOR );
     112                 :            : 
     113 [ #  # ][ #  # ]:          0 :         WallFloorConverter aWallConv( *this, mrModel.mxBackWall.getOrCreate() );
     114 [ #  # ][ #  # ]:          0 :         aWallConv.convertFromModel( xDiagram, OBJECTTYPE_WALL );
                 [ #  # ]
     115                 :            :     }
     116                 :            : 
     117                 :            :     // chart title
     118         [ #  # ]:          0 :     if( !mrModel.mbAutoTitleDel ) try
     119                 :            :     {
     120                 :            :         /*  If the title model is missing, but the chart shows exactly one
     121                 :            :             series, the series title is shown as chart title. */
     122                 :          0 :         OUString aAutoTitle = aPlotAreaConv.getAutomaticTitle();
     123 [ #  # ][ #  # ]:          0 :         if( mrModel.mxTitle.is() || !aAutoTitle.isEmpty() )
         [ #  # ][ #  # ]
     124                 :            :         {
     125         [ #  # ]:          0 :             if( aAutoTitle.isEmpty() )
     126         [ #  # ]:          0 :                 aAutoTitle = CREATE_OUSTRING( "Chart Title" );
     127 [ #  # ][ #  # ]:          0 :             Reference< XTitled > xTitled( getChartDocument(), UNO_QUERY_THROW );
     128 [ #  # ][ #  # ]:          0 :             TitleConverter aTitleConv( *this, mrModel.mxTitle.getOrCreate() );
     129 [ #  # ][ #  # ]:          0 :             aTitleConv.convertFromModel( xTitled, aAutoTitle, OBJECTTYPE_CHARTTITLE );
     130         [ #  # ]:          0 :         }
     131                 :            :     }
     132         [ #  # ]:          0 :     catch( Exception& )
     133                 :            :     {
     134                 :            :     }
     135                 :            : 
     136                 :            :     // legend
     137 [ #  # ][ #  # ]:          0 :     if( xDiagram.is() && mrModel.mxLegend.is() )
         [ #  # ][ #  # ]
     138                 :            :     {
     139         [ #  # ]:          0 :         LegendConverter aLegendConv( *this, *mrModel.mxLegend );
     140 [ #  # ][ #  # ]:          0 :         aLegendConv.convertFromModel( xDiagram );
     141                 :            :     }
     142                 :            : 
     143                 :            :     // treatment of missing values
     144         [ #  # ]:          0 :     if( xDiagram.is() )
     145                 :            :     {
     146                 :            :         using namespace ::com::sun::star::chart::MissingValueTreatment;
     147                 :          0 :         sal_Int32 nMissingValues = LEAVE_GAP;
     148   [ #  #  #  # ]:          0 :         switch( mrModel.mnDispBlanksAs )
     149                 :            :         {
     150                 :          0 :             case XML_gap:   nMissingValues = LEAVE_GAP; break;
     151                 :          0 :             case XML_zero:  nMissingValues = USE_ZERO;  break;
     152                 :          0 :             case XML_span:  nMissingValues = CONTINUE;  break;
     153                 :            :         }
     154         [ #  # ]:          0 :         PropertySet aDiaProp( xDiagram );
     155 [ #  # ][ #  # ]:          0 :         aDiaProp.setProperty( PROP_MissingValueTreatment, nMissingValues );
     156                 :            :     }
     157                 :            : 
     158                 :            :     /*  Following all conversions needing the old Chart1 API that involves full
     159                 :            :         initialization of the chart view. */
     160                 :            :     namespace cssc = ::com::sun::star::chart;
     161 [ #  # ][ #  # ]:          0 :     Reference< cssc::XChartDocument > xChart1Doc( getChartDocument(), UNO_QUERY );
     162         [ #  # ]:          0 :     if( xChart1Doc.is() )
     163                 :            :     {
     164                 :            :         /*  Set the IncludeHiddenCells property via the old API as only this
     165                 :            :             ensures that the data provider and all created sequences get this
     166                 :            :             flag correctly. */
     167 [ #  # ][ #  # ]:          0 :         PropertySet aDiaProp( xChart1Doc->getDiagram() );
                 [ #  # ]
     168         [ #  # ]:          0 :         aDiaProp.setProperty( PROP_IncludeHiddenCells, !mrModel.mbPlotVisOnly );
     169                 :            : 
     170                 :            :         // plot area position and size
     171         [ #  # ]:          0 :         aPlotAreaConv.convertPositionFromModel();
     172                 :            : 
     173                 :            :         // positions of main title and all axis titles
     174 [ #  # ][ #  # ]:          0 :         convertTitlePositions();
     175                 :            :     }
     176                 :            : 
     177                 :            :     // embedded drawing shapes
     178         [ #  # ]:          0 :     if( !mrModel.maDrawingPath.isEmpty() ) try
     179                 :            :     {
     180                 :            :         /*  Get the internal draw page of the chart document, if no external
     181                 :            :             drawing page has been passed. */
     182                 :          0 :         Reference< XShapes > xShapes;
     183                 :          0 :         Point aShapesOffset( 0, 0 );
     184         [ #  # ]:          0 :         if( rxExternalPage.is() )
     185                 :            :         {
     186         [ #  # ]:          0 :             xShapes = rxExternalPage;
     187                 :            :             // offset for embedded shapes to move them inside the chart area
     188                 :          0 :             aShapesOffset = rChartPos;
     189                 :            :         }
     190                 :            :         else
     191                 :            :         {
     192 [ #  # ][ #  # ]:          0 :             Reference< XDrawPageSupplier > xDrawPageSupp( getChartDocument(), UNO_QUERY_THROW );
     193 [ #  # ][ #  # ]:          0 :             xShapes.set( xDrawPageSupp->getDrawPage(), UNO_QUERY_THROW );
                 [ #  # ]
     194                 :            :         }
     195                 :            : 
     196                 :            :         /*  If an external drawing page is passed, all embedded shapes will be
     197                 :            :             inserted there (used e.g. with 'chart sheets' in spreadsheet
     198                 :            :             documents). In this case, all types of shapes including OLE objects
     199                 :            :             are supported. If the shapes are inserted into the internal chart
     200                 :            :             drawing page instead, it is not possible to embed OLE objects. */
     201                 :          0 :         bool bOleSupport = rxExternalPage.is();
     202                 :            : 
     203                 :            :         // now, xShapes is not null anymore
     204         [ #  # ]:          0 :         getFilter().importFragment( new ChartDrawingFragment(
     205 [ #  # ][ #  # ]:          0 :             getFilter(), mrModel.maDrawingPath, xShapes, getChartSize(), aShapesOffset, bOleSupport ) );
         [ #  # ][ #  # ]
                 [ #  # ]
     206                 :            :     }
     207         [ #  # ]:          0 :     catch( Exception& )
     208                 :            :     {
     209                 :            :     }
     210                 :            : 
     211                 :            :     // pivot chart
     212         [ #  # ]:          0 :     if ( mrModel.mbPivotChart )
     213                 :            :     {
     214 [ #  # ][ #  # ]:          0 :         PropertySet aProps( getChartDocument() );
     215         [ #  # ]:          0 :         aProps.setProperty( PROP_DisableDataTableDialog , true );
     216 [ #  # ][ #  # ]:          0 :         aProps.setProperty( PROP_DisableComplexChartTypes , true );
     217 [ #  # ][ #  # ]:          0 :     }
     218                 :            : }
     219                 :            : 
     220                 :            : // ============================================================================
     221                 :            : 
     222                 :            : } // namespace chart
     223                 :            : } // namespace drawingml
     224 [ +  - ][ +  - ]:        285 : } // namespace oox
     225                 :            : 
     226                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10