LCOV - code coverage report
Current view: top level - chart2/source/tools - ChartModelHelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 77 101 76.2 %
Date: 2012-08-25 Functions: 11 14 78.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 90 212 42.5 %

           Branch data     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                 :          2 : uno::Reference< chart2::data::XRangeHighlighter > ChartModelHelper::createRangeHighlighter(
      45                 :            :         const uno::Reference< view::XSelectionSupplier > & xSelectionSupplier )
      46                 :            : {
      47 [ +  - ][ +  - ]:          2 :     return new RangeHighlighter( xSelectionSupplier );
      48                 :            : }
      49                 :            : 
      50                 :         71 : uno::Reference< chart2::data::XDataProvider > ChartModelHelper::createInternalDataProvider(
      51                 :            :     const uno::Reference< ::com::sun::star::chart2::XChartDocument >& xChartDoc, bool bConnectToModel )
      52                 :            : {
      53 [ +  - ][ +  - ]:         71 :     return new InternalDataProvider( xChartDoc, bConnectToModel );
      54                 :            : }
      55                 :            : 
      56                 :      82691 : uno::Reference< XDiagram > ChartModelHelper::findDiagram( const uno::Reference< frame::XModel >& xModel )
      57                 :            : {
      58         [ +  - ]:      82691 :     uno::Reference< XChartDocument > xChartDoc( xModel, uno::UNO_QUERY );
      59         [ +  - ]:      82691 :     if( xChartDoc.is())
      60         [ +  - ]:      82691 :         return ChartModelHelper::findDiagram( xChartDoc );
      61         [ #  # ]:      82691 :     return NULL;
      62                 :            : }
      63                 :            : 
      64                 :      86682 : uno::Reference< XDiagram > ChartModelHelper::findDiagram( const uno::Reference< chart2::XChartDocument >& xChartDoc )
      65                 :            : {
      66                 :            :     try
      67                 :            :     {
      68         [ +  + ]:      86682 :         if( xChartDoc.is())
      69 [ +  - ][ +  - ]:      86626 :             return xChartDoc->getFirstDiagram();
      70                 :            :     }
      71                 :          0 :     catch( const uno::Exception & ex )
      72                 :            :     {
      73                 :            :         ASSERT_EXCEPTION( ex );
      74                 :            :     }
      75         [ #  # ]:      86682 :     return NULL;
      76                 :            : }
      77                 :            : 
      78                 :       5992 : uno::Reference< XCoordinateSystem > ChartModelHelper::getFirstCoordinateSystem( const uno::Reference< frame::XModel >& xModel )
      79                 :            : {
      80                 :       5992 :     uno::Reference< XCoordinateSystem > XCooSys;
      81 [ +  - ][ +  - ]:       5992 :     uno::Reference< XCoordinateSystemContainer > xCooSysCnt( ChartModelHelper::findDiagram( xModel ), uno::UNO_QUERY );
      82         [ +  - ]:       5992 :     if( xCooSysCnt.is() )
      83                 :            :     {
      84 [ +  - ][ +  - ]:       5992 :         uno::Sequence< uno::Reference< XCoordinateSystem > > aCooSysSeq( xCooSysCnt->getCoordinateSystems() );
      85         [ +  + ]:       5992 :         if( aCooSysSeq.getLength() )
      86 [ +  - ][ +  - ]:       5992 :             XCooSys = aCooSysSeq[0];
                 [ +  - ]
      87                 :            :     }
      88                 :       5992 :     return XCooSys;
      89                 :            : }
      90                 :            : 
      91                 :         71 : ::std::vector< uno::Reference< XDataSeries > > ChartModelHelper::getDataSeries(
      92                 :            :     const uno::Reference< XChartDocument > & xChartDoc )
      93                 :            : {
      94         [ +  - ]:         71 :     ::std::vector< uno::Reference< XDataSeries > > aResult;
      95                 :            : 
      96         [ +  - ]:         71 :     uno::Reference< XDiagram > xDiagram = ChartModelHelper::findDiagram( xChartDoc );
      97         [ +  - ]:         71 :     if( xDiagram.is())
      98         [ +  - ]:         71 :         aResult = DiagramHelper::getDataSeriesFromDiagram( xDiagram );
      99                 :            : 
     100                 :         71 :     return aResult;
     101                 :            : }
     102                 :            : 
     103                 :         56 : ::std::vector< uno::Reference< XDataSeries > > ChartModelHelper::getDataSeries(
     104                 :            :     const uno::Reference< frame::XModel > & xModel )
     105                 :            : {
     106         [ +  - ]:         56 :     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                 :       3145 : awt::Size ChartModelHelper::getDefaultPageSize()
     118                 :            : {
     119                 :       3145 :     return awt::Size( 16000, 9000 );
     120                 :            : }
     121                 :            : 
     122                 :       1151 : awt::Size ChartModelHelper::getPageSize( const uno::Reference< frame::XModel >& xModel )
     123                 :            : {
     124         [ +  - ]:       1151 :     awt::Size aPageSize( ChartModelHelper::getDefaultPageSize() );
     125         [ +  - ]:       1151 :     uno::Reference< embed::XVisualObject > xVisualObject(xModel,uno::UNO_QUERY);
     126                 :            :     OSL_ENSURE(xVisualObject.is(),"need xVisualObject for page size");
     127         [ +  - ]:       1151 :     if( xVisualObject.is() )
     128 [ +  - ][ +  - ]:       1151 :         aPageSize = xVisualObject->getVisualAreaSize( embed::Aspects::MSOLE_CONTENT );
     129                 :       1151 :     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                 :         16 : bool ChartModelHelper::isIncludeHiddenCells( const uno::Reference< frame::XModel >& xChartModel )
     156                 :            : {
     157                 :         16 :     bool bIncluded = true;  // hidden cells are included by default.
     158                 :            : 
     159         [ +  - ]:         16 :     uno::Reference< chart2::XDiagram > xDiagram( ChartModelHelper::findDiagram(xChartModel) );
     160         [ -  + ]:         16 :     if (!xDiagram.is())
     161                 :          0 :         return bIncluded;
     162                 :            : 
     163         [ +  - ]:         16 :     uno::Reference< beans::XPropertySet > xProp( xDiagram, uno::UNO_QUERY );
     164         [ -  + ]:         16 :     if (!xProp.is())
     165                 :          0 :         return bIncluded;
     166                 :            : 
     167                 :            :     try
     168                 :            :     {
     169 [ +  - ][ +  - ]:         16 :         xProp->getPropertyValue(C2U("IncludeHiddenCells")) >>= bIncluded;
         [ +  - ][ #  # ]
     170                 :            :     }
     171         [ #  # ]:          0 :     catch( const beans::UnknownPropertyException& )
     172                 :            :     {
     173                 :            :     }
     174                 :            : 
     175                 :         16 :     return bIncluded;
     176                 :            : }
     177                 :            : 
     178                 :         56 : bool ChartModelHelper::setIncludeHiddenCells( bool bIncludeHiddenCells, const uno::Reference< frame::XModel >& xChartModel )
     179                 :            : {
     180                 :         56 :     bool bChanged = false;
     181                 :            :     try
     182                 :            :     {
     183         [ +  - ]:         56 :         ControllerLockGuard aLockedControllers( xChartModel );
     184                 :            : 
     185 [ +  - ][ +  - ]:         56 :         uno::Reference< beans::XPropertySet > xDiagramProperties( ChartModelHelper::findDiagram(xChartModel), uno::UNO_QUERY );
     186         [ +  - ]:         56 :         if (xDiagramProperties.is())
     187                 :            :         {
     188                 :         56 :             bool bOldValue = bIncludeHiddenCells;
     189 [ +  - ][ +  - ]:         56 :             xDiagramProperties->getPropertyValue( C2U("IncludeHiddenCells") ) >>= bOldValue;
                 [ +  - ]
     190         [ -  + ]:         56 :             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         [ +  - ]:         56 :             uno::Any aNewValue = uno::makeAny(bIncludeHiddenCells);
     196                 :            : 
     197                 :            :             try
     198                 :            :             {
     199         [ +  - ]:         56 :                 uno::Reference< chart2::XChartDocument > xChartDoc( xChartModel, uno::UNO_QUERY );
     200         [ +  - ]:         56 :                 if( xChartDoc.is() )
     201                 :            :                 {
     202 [ +  - ][ +  - ]:         56 :                     uno::Reference< beans::XPropertySet > xDataProviderProperties( xChartDoc->getDataProvider(), uno::UNO_QUERY );
                 [ +  - ]
     203         [ +  + ]:         56 :                     if( xDataProviderProperties.is() )
     204 [ +  - ][ +  - ]:         56 :                         xDataProviderProperties->setPropertyValue(C2U("IncludeHiddenCells"), aNewValue );
                 [ +  - ]
     205         [ #  # ]:         56 :                 }
     206                 :            :             }
     207         [ #  # ]:          0 :             catch( const beans::UnknownPropertyException& )
     208                 :            :             {
     209                 :            :                 //the property is optional!
     210                 :            :             }
     211                 :            : 
     212                 :            :             try
     213                 :            :             {
     214         [ +  - ]:         56 :                 uno::Reference< chart2::data::XDataSource > xUsedData( DataSourceHelper::getUsedData( xChartModel ) );
     215         [ +  - ]:         56 :                 if( xUsedData.is() )
     216                 :            :                 {
     217                 :         56 :                     uno::Reference< beans::XPropertySet > xProp;
     218 [ +  - ][ +  - ]:         56 :                     uno::Sequence< uno::Reference< chart2::data::XLabeledDataSequence > > aData( xUsedData->getDataSequences());
     219         [ +  + ]:         68 :                     for( sal_Int32 i=0; i<aData.getLength(); ++i )
     220                 :            :                     {
     221 [ +  - ][ +  - ]:         62 :                         xProp.set( uno::Reference< beans::XPropertySet >( aData[i]->getValues(), uno::UNO_QUERY ) );
         [ +  - ][ +  - ]
                 [ +  - ]
     222         [ +  - ]:         62 :                         if(xProp.is())
     223 [ +  - ][ +  - ]:         62 :                             xProp->setPropertyValue(C2U("IncludeHiddenCells"), aNewValue );
                 [ +  + ]
     224 [ +  - ][ +  - ]:         12 :                         xProp.set( uno::Reference< beans::XPropertySet >( aData[i]->getLabel(), uno::UNO_QUERY ) );
         [ +  - ][ +  - ]
                 [ +  - ]
     225         [ +  + ]:         12 :                         if(xProp.is())
     226 [ +  - ][ +  - ]:          6 :                             xProp->setPropertyValue(C2U("IncludeHiddenCells"), aNewValue );
                 [ +  - ]
     227         [ +  - ]:         56 :                     }
     228         [ -  + ]:         56 :                 }
     229                 :            :             }
     230         [ +  - ]:         50 :             catch( const beans::UnknownPropertyException& )
     231                 :            :             {
     232                 :            :                 //the property is optional!
     233                 :            :             }
     234                 :            : 
     235 [ +  - ][ +  - ]:         56 :             xDiagramProperties->setPropertyValue( C2U("IncludeHiddenCells"), aNewValue);
                 [ +  - ]
     236 [ +  - ][ #  # ]:         56 :         }
     237                 :            :     }
     238                 :          0 :     catch (const uno::Exception& e)
     239                 :            :     {
     240                 :            :         ASSERT_EXCEPTION(e);
     241                 :            :     }
     242                 :         56 :     return bChanged;
     243                 :            : }
     244                 :            : 
     245                 :            : //.............................................................................
     246                 :            : } //namespace chart
     247                 :            : //.............................................................................
     248                 :            : 
     249                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10