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

Generated by: LCOV version 1.10