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

Generated by: LCOV version 1.10