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

Generated by: LCOV version 1.10