LCOV - code coverage report
Current view: top level - libreoffice/chart2/source/tools - ChartModelHelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 74 101 73.3 %
Date: 2012-12-27 Functions: 10 14 71.4 %
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 "ChartModelHelper.hxx"
      21             : #include "macros.hxx"
      22             : #include "DiagramHelper.hxx"
      23             : #include "DataSourceHelper.hxx"
      24             : #include "ControllerLockGuard.hxx"
      25             : #include "RangeHighlighter.hxx"
      26             : #include "InternalDataProvider.hxx"
      27             : 
      28             : #include <com/sun/star/chart2/data/XDataReceiver.hpp>
      29             : #include <com/sun/star/chart2/XChartDocument.hpp>
      30             : #include <com/sun/star/chart2/XChartTypeContainer.hpp>
      31             : #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
      32             : #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
      33             : #include <com/sun/star/embed/Aspects.hpp>
      34             : #include <com/sun/star/embed/XVisualObject.hpp>
      35             : #include <com/sun/star/view/XSelectionChangeListener.hpp>
      36             : 
      37             : //.............................................................................
      38             : namespace chart
      39             : {
      40             : //.............................................................................
      41             : using namespace ::com::sun::star;
      42             : using namespace ::com::sun::star::chart2;
      43             : 
      44           0 : uno::Reference< chart2::data::XRangeHighlighter > ChartModelHelper::createRangeHighlighter(
      45             :         const uno::Reference< view::XSelectionSupplier > & xSelectionSupplier )
      46             : {
      47           0 :     return new RangeHighlighter( xSelectionSupplier );
      48             : }
      49             : 
      50          41 : uno::Reference< chart2::data::XDataProvider > ChartModelHelper::createInternalDataProvider(
      51             :     const uno::Reference< ::com::sun::star::chart2::XChartDocument >& xChartDoc, bool bConnectToModel )
      52             : {
      53          41 :     return new InternalDataProvider( xChartDoc, bConnectToModel );
      54             : }
      55             : 
      56         976 : uno::Reference< XDiagram > ChartModelHelper::findDiagram( const uno::Reference< frame::XModel >& xModel )
      57             : {
      58         976 :     uno::Reference< XChartDocument > xChartDoc( xModel, uno::UNO_QUERY );
      59         976 :     if( xChartDoc.is())
      60         976 :         return ChartModelHelper::findDiagram( xChartDoc );
      61           0 :     return NULL;
      62             : }
      63             : 
      64        1098 : uno::Reference< XDiagram > ChartModelHelper::findDiagram( const uno::Reference< chart2::XChartDocument >& xChartDoc )
      65             : {
      66             :     try
      67             :     {
      68        1098 :         if( xChartDoc.is())
      69        1057 :             return xChartDoc->getFirstDiagram();
      70             :     }
      71           0 :     catch( const uno::Exception & ex )
      72             :     {
      73             :         ASSERT_EXCEPTION( ex );
      74             :     }
      75          41 :     return NULL;
      76             : }
      77             : 
      78         287 : uno::Reference< XCoordinateSystem > ChartModelHelper::getFirstCoordinateSystem( const uno::Reference< frame::XModel >& xModel )
      79             : {
      80         287 :     uno::Reference< XCoordinateSystem > XCooSys;
      81         287 :     uno::Reference< XCoordinateSystemContainer > xCooSysCnt( ChartModelHelper::findDiagram( xModel ), uno::UNO_QUERY );
      82         287 :     if( xCooSysCnt.is() )
      83             :     {
      84         287 :         uno::Sequence< uno::Reference< XCoordinateSystem > > aCooSysSeq( xCooSysCnt->getCoordinateSystems() );
      85         287 :         if( aCooSysSeq.getLength() )
      86         287 :             XCooSys = aCooSysSeq[0];
      87             :     }
      88         287 :     return XCooSys;
      89             : }
      90             : 
      91          81 : ::std::vector< uno::Reference< XDataSeries > > ChartModelHelper::getDataSeries(
      92             :     const uno::Reference< XChartDocument > & xChartDoc )
      93             : {
      94          81 :     ::std::vector< uno::Reference< XDataSeries > > aResult;
      95             : 
      96          81 :     uno::Reference< XDiagram > xDiagram = ChartModelHelper::findDiagram( xChartDoc );
      97          81 :     if( xDiagram.is())
      98          81 :         aResult = DiagramHelper::getDataSeriesFromDiagram( xDiagram );
      99             : 
     100          81 :     return aResult;
     101             : }
     102             : 
     103          81 : ::std::vector< uno::Reference< XDataSeries > > ChartModelHelper::getDataSeries(
     104             :     const uno::Reference< frame::XModel > & xModel )
     105             : {
     106          81 :     return getDataSeries( uno::Reference< chart2::XChartDocument >( xModel, uno::UNO_QUERY ));
     107             : }
     108             : 
     109             : 
     110           0 : uno::Reference< XChartType > ChartModelHelper::getChartTypeOfSeries(
     111             :                                 const uno::Reference< frame::XModel >& xModel
     112             :                               , const uno::Reference< XDataSeries >&   xGivenDataSeries )
     113             : {
     114           0 :     return DiagramHelper::getChartTypeOfSeries( ChartModelHelper::findDiagram( xModel ), xGivenDataSeries );
     115             : }
     116             : 
     117         223 : awt::Size ChartModelHelper::getDefaultPageSize()
     118             : {
     119         223 :     return awt::Size( 16000, 9000 );
     120             : }
     121             : 
     122         100 : awt::Size ChartModelHelper::getPageSize( const uno::Reference< frame::XModel >& xModel )
     123             : {
     124         100 :     awt::Size aPageSize( ChartModelHelper::getDefaultPageSize() );
     125         100 :     uno::Reference< embed::XVisualObject > xVisualObject(xModel,uno::UNO_QUERY);
     126             :     OSL_ENSURE(xVisualObject.is(),"need xVisualObject for page size");
     127         100 :     if( xVisualObject.is() )
     128         100 :         aPageSize = xVisualObject->getVisualAreaSize( embed::Aspects::MSOLE_CONTENT );
     129         100 :     return aPageSize;
     130             : }
     131             : 
     132           0 : void ChartModelHelper::setPageSize( const awt::Size& rSize, const uno::Reference< frame::XModel >& xModel )
     133             : {
     134           0 :     uno::Reference< embed::XVisualObject > xVisualObject(xModel,uno::UNO_QUERY);
     135             :     OSL_ENSURE(xVisualObject.is(),"need xVisualObject for page size");
     136           0 :     if( xVisualObject.is() )
     137           0 :         xVisualObject->setVisualAreaSize( embed::Aspects::MSOLE_CONTENT, rSize );
     138           0 : }
     139             : 
     140           0 : void ChartModelHelper::triggerRangeHighlighting( const uno::Reference< frame::XModel >& xModel )
     141             : {
     142           0 :     uno::Reference< chart2::data::XDataReceiver > xDataReceiver( xModel, uno::UNO_QUERY );
     143           0 :     if( xDataReceiver.is() )
     144             :     {
     145           0 :         uno::Reference< view::XSelectionChangeListener > xSelectionChangeListener( xDataReceiver->getRangeHighlighter(), uno::UNO_QUERY );
     146             :         //trigger selection of cell range
     147           0 :         if( xSelectionChangeListener.is() )
     148             :         {
     149           0 :             lang::EventObject aEvent( xSelectionChangeListener );
     150           0 :             xSelectionChangeListener->selectionChanged( aEvent );
     151           0 :         }
     152           0 :     }
     153           0 : }
     154             : 
     155          40 : bool ChartModelHelper::isIncludeHiddenCells( const uno::Reference< frame::XModel >& xChartModel )
     156             : {
     157          40 :     bool bIncluded = true;  // hidden cells are included by default.
     158             : 
     159          40 :     uno::Reference< chart2::XDiagram > xDiagram( ChartModelHelper::findDiagram(xChartModel) );
     160          40 :     if (!xDiagram.is())
     161           0 :         return bIncluded;
     162             : 
     163          40 :     uno::Reference< beans::XPropertySet > xProp( xDiagram, uno::UNO_QUERY );
     164          40 :     if (!xProp.is())
     165           0 :         return bIncluded;
     166             : 
     167             :     try
     168             :     {
     169          40 :         xProp->getPropertyValue(C2U("IncludeHiddenCells")) >>= bIncluded;
     170             :     }
     171           0 :     catch( const beans::UnknownPropertyException& )
     172             :     {
     173             :     }
     174             : 
     175          40 :     return bIncluded;
     176             : }
     177             : 
     178          81 : bool ChartModelHelper::setIncludeHiddenCells( bool bIncludeHiddenCells, const uno::Reference< frame::XModel >& xChartModel )
     179             : {
     180          81 :     bool bChanged = false;
     181             :     try
     182             :     {
     183          81 :         ControllerLockGuard aLockedControllers( xChartModel );
     184             : 
     185          81 :         uno::Reference< beans::XPropertySet > xDiagramProperties( ChartModelHelper::findDiagram(xChartModel), uno::UNO_QUERY );
     186          81 :         if (xDiagramProperties.is())
     187             :         {
     188          81 :             bool bOldValue = bIncludeHiddenCells;
     189          81 :             xDiagramProperties->getPropertyValue( C2U("IncludeHiddenCells") ) >>= bOldValue;
     190          81 :             if( bOldValue == bIncludeHiddenCells )
     191           0 :                 bChanged = true;
     192             : 
     193             :             //set the property on all instances in all cases to get the different objects in sync!
     194             : 
     195          81 :             uno::Any aNewValue = uno::makeAny(bIncludeHiddenCells);
     196             : 
     197             :             try
     198             :             {
     199          81 :                 uno::Reference< chart2::XChartDocument > xChartDoc( xChartModel, uno::UNO_QUERY );
     200          81 :                 if( xChartDoc.is() )
     201             :                 {
     202          81 :                     uno::Reference< beans::XPropertySet > xDataProviderProperties( xChartDoc->getDataProvider(), uno::UNO_QUERY );
     203          81 :                     if( xDataProviderProperties.is() )
     204          40 :                         xDataProviderProperties->setPropertyValue(C2U("IncludeHiddenCells"), aNewValue );
     205          81 :                 }
     206             :             }
     207           0 :             catch( const beans::UnknownPropertyException& )
     208             :             {
     209             :                 //the property is optional!
     210             :             }
     211             : 
     212             :             try
     213             :             {
     214          81 :                 uno::Reference< chart2::data::XDataSource > xUsedData( DataSourceHelper::getUsedData( xChartModel ) );
     215          81 :                 if( xUsedData.is() )
     216             :                 {
     217          81 :                     uno::Reference< beans::XPropertySet > xProp;
     218          81 :                     uno::Sequence< uno::Reference< chart2::data::XLabeledDataSequence > > aData( xUsedData->getDataSequences());
     219         142 :                     for( sal_Int32 i=0; i<aData.getLength(); ++i )
     220             :                     {
     221         102 :                         xProp.set( uno::Reference< beans::XPropertySet >( aData[i]->getValues(), uno::UNO_QUERY ) );
     222         102 :                         if(xProp.is())
     223         143 :                             xProp->setPropertyValue(C2U("IncludeHiddenCells"), aNewValue );
     224          61 :                         xProp.set( uno::Reference< beans::XPropertySet >( aData[i]->getLabel(), uno::UNO_QUERY ) );
     225          61 :                         if(xProp.is())
     226          21 :                             xProp->setPropertyValue(C2U("IncludeHiddenCells"), aNewValue );
     227          81 :                     }
     228          81 :                 }
     229             :             }
     230          41 :             catch( const beans::UnknownPropertyException& )
     231             :             {
     232             :                 //the property is optional!
     233             :             }
     234             : 
     235          81 :             xDiagramProperties->setPropertyValue( C2U("IncludeHiddenCells"), aNewValue);
     236          81 :         }
     237             :     }
     238           0 :     catch (const uno::Exception& e)
     239             :     {
     240             :         ASSERT_EXCEPTION(e);
     241             :     }
     242          81 :     return bChanged;
     243             : }
     244             : 
     245             : //.............................................................................
     246             : } //namespace chart
     247             : //.............................................................................
     248             : 
     249             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10