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

Generated by: LCOV version 1.11