LCOV - code coverage report
Current view: top level - chart2/source/tools - DataSourceHelper.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 181 264 68.6 %
Date: 2014-11-03 Functions: 18 26 69.2 %
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 "DataSourceHelper.hxx"
      21             : #include "macros.hxx"
      22             : #include "ChartModelHelper.hxx"
      23             : #include "DiagramHelper.hxx"
      24             : #include "DataSeriesHelper.hxx"
      25             : #include "DataSource.hxx"
      26             : #include "ContainerHelper.hxx"
      27             : #include "ControllerLockGuard.hxx"
      28             : #include "PropertyHelper.hxx"
      29             : #include "CachedDataSequence.hxx"
      30             : #include "LabeledDataSequence.hxx"
      31             : #include <unonames.hxx>
      32             : 
      33             : #include <com/sun/star/chart2/XChartDocument.hpp>
      34             : #include <com/sun/star/chart2/data/XDataSource.hpp>
      35             : #include <com/sun/star/chart2/data/XLabeledDataSequence.hpp>
      36             : 
      37             : #include <com/sun/star/chart/ChartDataRowSource.hpp>
      38             : #include <com/sun/star/chart/ErrorBarStyle.hpp>
      39             : 
      40             : namespace chart
      41             : {
      42             : using namespace ::com::sun::star;
      43             : using namespace ::com::sun::star::chart2;
      44             : using ::com::sun::star::uno::Reference;
      45             : using ::com::sun::star::uno::Sequence;
      46             : 
      47             : namespace
      48             : {
      49         920 : void lcl_addRanges( ::std::vector< OUString > & rOutResult,
      50             :                     const uno::Reference< data::XLabeledDataSequence > & xLabeledSeq )
      51             : {
      52         920 :     if( ! xLabeledSeq.is())
      53         920 :         return;
      54         920 :     uno::Reference< data::XDataSequence > xSeq( xLabeledSeq->getLabel());
      55         920 :     if( xSeq.is())
      56         682 :         rOutResult.push_back( xSeq->getSourceRangeRepresentation());
      57         920 :     xSeq.set( xLabeledSeq->getValues());
      58         920 :     if( xSeq.is())
      59         920 :         rOutResult.push_back( xSeq->getSourceRangeRepresentation());
      60             : }
      61             : 
      62         686 : void lcl_addDataSourceRanges(
      63             :     ::std::vector< OUString > & rOutResult,
      64             :     const uno::Reference< data::XDataSource > & xDataSource )
      65             : {
      66         686 :     if( xDataSource.is() )
      67             :     {
      68         686 :         uno::Sequence< uno::Reference< data::XLabeledDataSequence > > aDataSequences( xDataSource->getDataSequences() );
      69        1380 :         for( sal_Int32 i=0; i<aDataSequences.getLength(); ++i)
      70        1380 :             lcl_addRanges( rOutResult, aDataSequences[i] );
      71             :     }
      72         686 : }
      73             : 
      74         684 : void lcl_addErrorBarRanges(
      75             :     ::std::vector< OUString > & rOutResult,
      76             :     const uno::Reference< XDataSeries > & xDataSeries )
      77             : {
      78         684 :     uno::Reference< beans::XPropertySet > xSeriesProp( xDataSeries, uno::UNO_QUERY );
      79         684 :     if( !xSeriesProp.is())
      80         684 :         return;
      81             : 
      82             :     try
      83             :     {
      84         684 :         uno::Reference< beans::XPropertySet > xErrorBarProp;
      85        1368 :         if( ( xSeriesProp->getPropertyValue( CHART_UNONAME_ERRORBAR_Y) >>= xErrorBarProp ) &&
      86         684 :             xErrorBarProp.is())
      87             :         {
      88         230 :             sal_Int32 eStyle = ::com::sun::star::chart::ErrorBarStyle::NONE;
      89         460 :             if( ( xErrorBarProp->getPropertyValue( "ErrorBarStyle") >>= eStyle ) &&
      90         230 :                 eStyle == ::com::sun::star::chart::ErrorBarStyle::FROM_DATA )
      91             :             {
      92           2 :                 uno::Reference< data::XDataSource > xErrorBarDataSource( xErrorBarProp, uno::UNO_QUERY );
      93           2 :                 if( xErrorBarDataSource.is() )
      94           2 :                     lcl_addDataSourceRanges( rOutResult, xErrorBarDataSource );
      95             :             }
      96             :         }
      97             : 
      98         684 :         if( ( xSeriesProp->getPropertyValue(CHART_UNONAME_ERRORBAR_X) >>= xErrorBarProp ) && xErrorBarProp.is())
      99             :         {
     100           0 :             sal_Int32 eStyle = ::com::sun::star::chart::ErrorBarStyle::NONE;
     101           0 :             if( ( xErrorBarProp->getPropertyValue("ErrorBarStyle") >>= eStyle ) &&
     102           0 :                 eStyle == ::com::sun::star::chart::ErrorBarStyle::FROM_DATA )
     103             :             {
     104           0 :                 uno::Reference< data::XDataSource > xErrorBarDataSource( xErrorBarProp, uno::UNO_QUERY );
     105           0 :                 if( xErrorBarDataSource.is() )
     106           0 :                     lcl_addDataSourceRanges( rOutResult, xErrorBarDataSource );
     107             :             }
     108         684 :         }
     109             :     }
     110           0 :     catch( const uno::Exception & ex )
     111             :     {
     112             :         ASSERT_EXCEPTION( ex );
     113         684 :     }
     114             : }
     115             : 
     116             : } // anonymous namespace
     117             : 
     118          18 : Reference< chart2::data::XDataSource > DataSourceHelper::createDataSource(
     119             :         const Sequence< Reference< chart2::data::XLabeledDataSequence > >& rSequences )
     120             : {
     121          18 :     return new DataSource(rSequences);
     122             : }
     123             : 
     124           0 : Reference< chart2::data::XDataSequence > DataSourceHelper::createCachedDataSequence()
     125             : {
     126           0 :     return new ::chart::CachedDataSequence();
     127             : }
     128             : 
     129           0 : Reference< chart2::data::XDataSequence > DataSourceHelper::createCachedDataSequence( const OUString& rSingleText )
     130             : {
     131           0 :     return new ::chart::CachedDataSequence( rSingleText );
     132             : }
     133             : 
     134           0 : Reference< chart2::data::XLabeledDataSequence > DataSourceHelper::createLabeledDataSequence(
     135             :         const Reference< chart2::data::XDataSequence >& xValues ,
     136             :         const Reference< chart2::data::XDataSequence >& xLabels )
     137             : {
     138           0 :     return new ::chart::LabeledDataSequence( xValues, xLabels );
     139             : }
     140             : 
     141           0 : Reference< chart2::data::XLabeledDataSequence > DataSourceHelper::createLabeledDataSequence(
     142             :         const Reference< chart2::data::XDataSequence >& xValues )
     143             : {
     144           0 :     return new ::chart::LabeledDataSequence( xValues );
     145             : }
     146             : 
     147           0 : Reference< chart2::data::XLabeledDataSequence > DataSourceHelper::createLabeledDataSequence(
     148             :         const Reference< uno::XComponentContext >& xContext )
     149             : {
     150           0 :     return new ::chart::LabeledDataSequence( xContext );
     151             : }
     152             : 
     153        2858 : uno::Sequence< beans::PropertyValue > DataSourceHelper::createArguments(
     154             :                                             bool bUseColumns, bool bFirstCellAsLabel, bool bHasCategories )
     155             : {
     156        2858 :     ::com::sun::star::chart::ChartDataRowSource eRowSource = ::com::sun::star::chart::ChartDataRowSource_ROWS;
     157        2858 :     if( bUseColumns )
     158        1437 :         eRowSource = ::com::sun::star::chart::ChartDataRowSource_COLUMNS;
     159             : 
     160        2858 :     uno::Sequence< beans::PropertyValue > aArguments(3);
     161        5716 :     aArguments[0] = beans::PropertyValue( "DataRowSource"
     162             :         , -1, uno::makeAny( eRowSource )
     163        2858 :         , beans::PropertyState_DIRECT_VALUE );
     164        5716 :     aArguments[1] = beans::PropertyValue( "FirstCellAsLabel"
     165             :         , -1, uno::makeAny( bFirstCellAsLabel )
     166        2858 :         , beans::PropertyState_DIRECT_VALUE );
     167        5716 :     aArguments[2] = beans::PropertyValue( "HasCategories"
     168             :         , -1, uno::makeAny( bHasCategories )
     169        2858 :         , beans::PropertyState_DIRECT_VALUE );
     170             : 
     171        2858 :     return aArguments;
     172             : }
     173             : 
     174        2858 : uno::Sequence< beans::PropertyValue > DataSourceHelper::createArguments(
     175             :                                             const OUString & rRangeRepresentation,
     176             :                                             const uno::Sequence< sal_Int32 >& rSequenceMapping,
     177             :                                             bool bUseColumns, bool bFirstCellAsLabel, bool bHasCategories )
     178             : {
     179        2858 :     uno::Sequence< beans::PropertyValue > aArguments( createArguments( bUseColumns, bFirstCellAsLabel, bHasCategories ));
     180        2858 :     aArguments.realloc( aArguments.getLength() + 1 );
     181        5716 :     aArguments[aArguments.getLength() - 1] =
     182             :         beans::PropertyValue( "CellRangeRepresentation"
     183             :                               , -1, uno::makeAny( rRangeRepresentation )
     184        2858 :                               , beans::PropertyState_DIRECT_VALUE );
     185        2858 :     if( rSequenceMapping.getLength() )
     186             :     {
     187           0 :         aArguments.realloc( aArguments.getLength() + 1 );
     188           0 :         aArguments[aArguments.getLength() - 1] =
     189             :             beans::PropertyValue( "SequenceMapping"
     190             :                                 , -1, uno::makeAny( rSequenceMapping )
     191           0 :                                 , beans::PropertyState_DIRECT_VALUE );
     192             :     }
     193        2858 :     return aArguments;
     194             : }
     195             : 
     196        5082 : void DataSourceHelper::readArguments( const uno::Sequence< beans::PropertyValue >& rArguments
     197             :                                      , OUString & rRangeRepresentation, uno::Sequence< sal_Int32 >& rSequenceMapping
     198             :             , bool& bUseColumns, bool& bFirstCellAsLabel, bool& bHasCategories )
     199             : {
     200        5082 :     const beans::PropertyValue* pArguments = rArguments.getConstArray();
     201       25592 :     for(sal_Int32 i=0; i<rArguments.getLength(); ++i, ++pArguments)
     202             :     {
     203       20510 :         const beans::PropertyValue& aProperty = *pArguments;
     204       20510 :         if ( aProperty.Name == "DataRowSource" )
     205             :         {
     206             :             ::com::sun::star::chart::ChartDataRowSource eRowSource;
     207        5050 :             if( aProperty.Value >>= eRowSource )
     208        5050 :                 bUseColumns = (eRowSource==::com::sun::star::chart::ChartDataRowSource_COLUMNS);
     209             :         }
     210       15460 :         else if ( aProperty.Name == "FirstCellAsLabel" )
     211             :         {
     212        5050 :             aProperty.Value >>= bFirstCellAsLabel;
     213             :         }
     214       10410 :         else if ( aProperty.Name == "HasCategories" )
     215             :         {
     216        5046 :             aProperty.Value >>= bHasCategories;
     217             :         }
     218        5364 :         else if ( aProperty.Name == "CellRangeRepresentation" )
     219             :         {
     220        5070 :             aProperty.Value >>= rRangeRepresentation;
     221             :         }
     222         294 :         else if ( aProperty.Name == "SequenceMapping" )
     223             :         {
     224           0 :             aProperty.Value >>= rSequenceMapping;
     225             :         }
     226             :     }
     227        5082 : }
     228             : 
     229        3471 : uno::Reference< chart2::data::XDataSource > DataSourceHelper::pressUsedDataIntoRectangularFormat(
     230             :         const uno::Reference< chart2::XChartDocument >& xChartDoc, bool bWithCategories )
     231             : {
     232        3471 :     ::std::vector< Reference< chart2::data::XLabeledDataSequence > > aResultVector;
     233             : 
     234             :     //categories are always the first sequence
     235        6942 :     Reference< chart2::XDiagram > xDiagram( xChartDoc->getFirstDiagram());
     236             : 
     237        3471 :     if( bWithCategories )
     238             :     {
     239        3471 :         Reference< chart2::data::XLabeledDataSequence > xCategories( DiagramHelper::getCategoriesFromDiagram( xDiagram ) );
     240        3471 :         if( xCategories.is() )
     241        2549 :             aResultVector.push_back( xCategories );
     242             :     }
     243             : 
     244        6942 :     ::std::vector< Reference< chart2::XDataSeries > > xSeriesVector( DiagramHelper::getDataSeriesFromDiagram( xDiagram ) );
     245             :     uno::Reference< chart2::data::XDataSource > xSeriesSource(
     246        6942 :         DataSeriesHelper::getDataSource( ContainerHelper::ContainerToSequence(xSeriesVector) ) );
     247        6942 :     Sequence< Reference< chart2::data::XLabeledDataSequence > > aDataSeqences( xSeriesSource->getDataSequences() );
     248             : 
     249             :     //the first x-values is always the next sequence //todo ... other x-values get lost for old format
     250             :     Reference< chart2::data::XLabeledDataSequence > xXValues(
     251        6942 :         DataSeriesHelper::getDataSequenceByRole( xSeriesSource, "values-x" ) );
     252        3471 :     if( xXValues.is() )
     253         340 :         aResultVector.push_back( xXValues );
     254             : 
     255             :     //add all other sequences now without x-values
     256       11338 :     for( sal_Int32 nN=0; nN<aDataSeqences.getLength(); nN++ )
     257             :     {
     258        7867 :         OUString aRole = DataSeriesHelper::getRole(aDataSeqences[nN]);
     259        7867 :         if( !aRole.equals("values-x") )
     260        7319 :             aResultVector.push_back( aDataSeqences[nN] );
     261        7867 :     }
     262             : 
     263        6942 :     Sequence< Reference< chart2::data::XLabeledDataSequence > > aResultSequence( aResultVector.size() );
     264        3471 :     ::std::copy( aResultVector.begin(), aResultVector.end(), aResultSequence.getArray() );
     265             : 
     266        6942 :     return new DataSource( aResultSequence );
     267             : }
     268             : 
     269         236 : uno::Sequence< OUString > DataSourceHelper::getUsedDataRanges(
     270             :     const uno::Reference< chart2::XDiagram > & xDiagram )
     271             : {
     272         236 :     ::std::vector< OUString > aResult;
     273             : 
     274         236 :     if( xDiagram.is())
     275             :     {
     276         236 :         uno::Reference< data::XLabeledDataSequence > xCategories( DiagramHelper::getCategoriesFromDiagram( xDiagram ) );
     277         236 :         if( xCategories.is() )
     278         226 :             lcl_addRanges( aResult, xCategories );
     279             : 
     280         472 :         ::std::vector< uno::Reference< XDataSeries > > aSeriesVector( DiagramHelper::getDataSeriesFromDiagram( xDiagram ) );
     281        2760 :         for( ::std::vector< uno::Reference< XDataSeries > >::const_iterator aSeriesIt( aSeriesVector.begin() )
     282        1840 :                  ; aSeriesIt != aSeriesVector.end(); ++aSeriesIt )
     283             :         {
     284         684 :             uno::Reference< data::XDataSource > xDataSource( *aSeriesIt, uno::UNO_QUERY );
     285         684 :             lcl_addDataSourceRanges( aResult, xDataSource );
     286         684 :             lcl_addErrorBarRanges( aResult, *aSeriesIt );
     287         920 :         }
     288             :     }
     289             : 
     290         236 :     return ContainerHelper::ContainerToSequence( aResult );
     291             : }
     292             : 
     293          12 : uno::Sequence< OUString > DataSourceHelper::getUsedDataRanges( const uno::Reference< frame::XModel > & xChartModel )
     294             : {
     295          12 :     uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
     296          12 :     return getUsedDataRanges( xDiagram );
     297             : }
     298             : 
     299         669 : uno::Reference< chart2::data::XDataSource > DataSourceHelper::getUsedData(
     300             :     const uno::Reference< chart2::XChartDocument >& xChartDoc )
     301             : {
     302         669 :     return pressUsedDataIntoRectangularFormat( xChartDoc );
     303             : }
     304             : 
     305           4 : uno::Reference< chart2::data::XDataSource > DataSourceHelper::getUsedData(
     306             :     const uno::Reference< frame::XModel >& xChartModel )
     307             : {
     308           4 :     ::std::vector< uno::Reference< chart2::data::XLabeledDataSequence > > aResult;
     309             : 
     310           8 :     uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
     311           8 :     uno::Reference< data::XLabeledDataSequence > xCategories( DiagramHelper::getCategoriesFromDiagram( xDiagram ) );
     312           4 :     if( xCategories.is() )
     313           4 :         aResult.push_back( xCategories );
     314             : 
     315           8 :     ::std::vector< uno::Reference< XDataSeries > > aSeriesVector( ChartModelHelper::getDataSeries( xChartModel ) );
     316          24 :     for( ::std::vector< uno::Reference< XDataSeries > >::const_iterator aSeriesIt( aSeriesVector.begin() )
     317          16 :         ; aSeriesIt != aSeriesVector.end(); ++aSeriesIt )
     318             :     {
     319           4 :         uno::Reference< data::XDataSource > xDataSource( *aSeriesIt, uno::UNO_QUERY );
     320           4 :         if( !xDataSource.is() )
     321           0 :             continue;
     322           8 :         uno::Sequence< uno::Reference< data::XLabeledDataSequence > > aDataSequences( xDataSource->getDataSequences() );
     323           4 :         ::std::copy( aDataSequences.getConstArray(), aDataSequences.getConstArray() + aDataSequences.getLength(),
     324           8 :                      ::std::back_inserter( aResult ));
     325           4 :     }
     326             : 
     327             :     return uno::Reference< chart2::data::XDataSource >(
     328           8 :         new DataSource( ContainerHelper::ContainerToSequence( aResult )));
     329             : }
     330             : 
     331         578 : uno::Reference< chart2::data::XDataSource > DataSourceHelper::getUsedData(
     332             :     ChartModel& rModel )
     333             : {
     334         578 :     ::std::vector< uno::Reference< chart2::data::XLabeledDataSequence > > aResult;
     335             : 
     336        1156 :     uno::Reference< XDiagram > xDiagram( rModel.getFirstDiagram() );
     337        1156 :     uno::Reference< data::XLabeledDataSequence > xCategories( DiagramHelper::getCategoriesFromDiagram( xDiagram ) );
     338         578 :     if( xCategories.is() )
     339         258 :         aResult.push_back( xCategories );
     340             : 
     341        1156 :     ::std::vector< uno::Reference< XDataSeries > > aSeriesVector( ChartModelHelper::getDataSeries( rModel ) );
     342        3792 :     for( ::std::vector< uno::Reference< XDataSeries > >::const_iterator aSeriesIt( aSeriesVector.begin() )
     343        2528 :         ; aSeriesIt != aSeriesVector.end(); ++aSeriesIt )
     344             :     {
     345         686 :         uno::Reference< data::XDataSource > xDataSource( *aSeriesIt, uno::UNO_QUERY );
     346         686 :         if( !xDataSource.is() )
     347           0 :             continue;
     348        1372 :         uno::Sequence< uno::Reference< data::XLabeledDataSequence > > aDataSequences( xDataSource->getDataSequences() );
     349         686 :         ::std::copy( aDataSequences.getConstArray(), aDataSequences.getConstArray() + aDataSequences.getLength(),
     350        1372 :                      ::std::back_inserter( aResult ));
     351         686 :     }
     352             : 
     353             :     return uno::Reference< chart2::data::XDataSource >(
     354        1156 :         new DataSource( ContainerHelper::ContainerToSequence( aResult )));
     355             : }
     356             : 
     357        2830 : bool DataSourceHelper::detectRangeSegmentation(
     358             :     const uno::Reference<
     359             :         frame::XModel >& xChartModel
     360             :     , OUString& rOutRangeString
     361             :     , ::com::sun::star::uno::Sequence< sal_Int32 >& rSequenceMapping
     362             :     , bool& rOutUseColumns
     363             :     , bool& rOutFirstCellAsLabel
     364             :     , bool& rOutHasCategories )
     365             : {
     366        2830 :     bool bSomethingDetected = false;
     367             : 
     368        2830 :     uno::Reference< XChartDocument > xChartDocument( xChartModel, uno::UNO_QUERY );
     369        2830 :     if( !xChartDocument.is() )
     370           0 :         return bSomethingDetected;
     371        5660 :     uno::Reference< data::XDataProvider >  xDataProvider( xChartDocument->getDataProvider() );
     372        2830 :     if( !xDataProvider.is() )
     373          38 :         return bSomethingDetected;
     374             : 
     375             :     try
     376             :     {
     377             :         DataSourceHelper::readArguments(
     378        2792 :             xDataProvider->detectArguments( pressUsedDataIntoRectangularFormat( xChartDocument ) ),
     379        2792 :             rOutRangeString, rSequenceMapping, rOutUseColumns, rOutFirstCellAsLabel, rOutHasCategories );
     380        2792 :         bSomethingDetected = !rOutRangeString.isEmpty();
     381             : 
     382             :         uno::Reference< chart2::data::XLabeledDataSequence > xCategories(
     383        2792 :                     DiagramHelper::getCategoriesFromDiagram( xChartDocument->getFirstDiagram() ));
     384        2792 :         rOutHasCategories = xCategories.is();
     385             :     }
     386           0 :     catch( uno::Exception & ex )
     387             :     {
     388             :         ASSERT_EXCEPTION( ex );
     389             :     }
     390        5622 :     return bSomethingDetected;
     391             : }
     392             : 
     393           0 : bool DataSourceHelper::allArgumentsForRectRangeDetected(
     394             :     const uno::Reference< chart2::XChartDocument >& xChartDocument )
     395             : {
     396           0 :     bool bHasDataRowSource = false;
     397           0 :     bool bHasFirstCellAsLabel = false;
     398           0 :     bool bHasCellRangeRepresentation = false;
     399             : 
     400           0 :     uno::Reference< data::XDataProvider > xDataProvider( xChartDocument->getDataProvider() );
     401           0 :     if( !xDataProvider.is() )
     402           0 :         return false;
     403             : 
     404             :     try
     405             :     {
     406             :         const uno::Sequence< beans::PropertyValue > aArguments(
     407           0 :             xDataProvider->detectArguments( pressUsedDataIntoRectangularFormat( xChartDocument )));
     408           0 :         const beans::PropertyValue* pArguments = aArguments.getConstArray();
     409           0 :         for(sal_Int32 i=0; i<aArguments.getLength(); ++i, ++pArguments)
     410             :         {
     411           0 :             const beans::PropertyValue& aProperty = *pArguments;
     412           0 :             if ( aProperty.Name == "DataRowSource" )
     413             :             {
     414             :                 bHasDataRowSource =
     415           0 :                     (aProperty.Value.hasValue() && aProperty.Value.isExtractableTo(
     416           0 :                         cppu::UnoType<com::sun::star::chart::ChartDataRowSource>::get()));
     417             :             }
     418           0 :             else if ( aProperty.Name == "FirstCellAsLabel" )
     419             :             {
     420             :                 bHasFirstCellAsLabel =
     421           0 :                     (aProperty.Value.hasValue() && aProperty.Value.isExtractableTo(::getBooleanCppuType()));
     422             :             }
     423           0 :             else if ( aProperty.Name == "CellRangeRepresentation" )
     424             :             {
     425           0 :                 OUString aRange;
     426             :                 bHasCellRangeRepresentation =
     427           0 :                     (aProperty.Value.hasValue() && (aProperty.Value >>= aRange) && !aRange.isEmpty());
     428             :             }
     429           0 :         }
     430             :     }
     431           0 :     catch( const uno::Exception & ex )
     432             :     {
     433             :         ASSERT_EXCEPTION( ex );
     434             :     }
     435             : 
     436           0 :     return (bHasCellRangeRepresentation && bHasDataRowSource && bHasFirstCellAsLabel);
     437             : }
     438             : 
     439          10 : void DataSourceHelper::setRangeSegmentation(
     440             :             const uno::Reference< frame::XModel >& xChartModel
     441             :             , const ::com::sun::star::uno::Sequence< sal_Int32 >& rSequenceMapping
     442             :             , bool bUseColumns , bool bFirstCellAsLabel, bool bUseCategories )
     443             : {
     444          10 :     uno::Reference< XChartDocument > xChartDocument( xChartModel, uno::UNO_QUERY );
     445          10 :     if( !xChartDocument.is() )
     446           0 :         return;
     447          20 :     uno::Reference< data::XDataProvider > xDataProvider( xChartDocument->getDataProvider() );
     448          10 :     if( !xDataProvider.is() )
     449           0 :         return;
     450          20 :     uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
     451          10 :     if( !xDiagram.is() )
     452           0 :         return;
     453          20 :     uno::Reference< chart2::XChartTypeManager > xChartTypeManager( xChartDocument->getChartTypeManager() );
     454          10 :     if( !xChartTypeManager.is() )
     455           0 :         return;
     456          20 :     uno::Reference< lang::XMultiServiceFactory > xTemplateFactory( xChartTypeManager, uno::UNO_QUERY );
     457          10 :     if( !xTemplateFactory.is() )
     458           0 :         return;
     459             : 
     460          20 :     OUString aRangeString;
     461             :     bool bDummy;
     462          20 :     uno::Sequence< sal_Int32 > aDummy;
     463          10 :     readArguments( xDataProvider->detectArguments( pressUsedDataIntoRectangularFormat( xChartDocument )),
     464          10 :                    aRangeString, aDummy, bDummy, bDummy, bDummy );
     465             : 
     466             :     uno::Sequence< beans::PropertyValue > aArguments(
     467          20 :         createArguments( aRangeString, rSequenceMapping, bUseColumns, bFirstCellAsLabel, bUseCategories ) );
     468             : 
     469          10 :     uno::Reference< chart2::data::XDataSource > xDataSource( xDataProvider->createDataSource(
     470          20 :                                                                  aArguments ) );
     471          10 :     if( !xDataSource.is() )
     472           0 :         return;
     473             : 
     474          20 :     ControllerLockGuardUNO aCtrlLockGuard( xChartModel );
     475          20 :     xDiagram->setDiagramData( xDataSource, aArguments );
     476             : }
     477             : 
     478           0 : Sequence< OUString > DataSourceHelper::getRangesFromLabeledDataSequence(
     479             :     const Reference< data::XLabeledDataSequence > & xLSeq )
     480             : {
     481           0 :     Sequence< OUString > aResult;
     482           0 :     if( xLSeq.is())
     483             :     {
     484           0 :         Reference< data::XDataSequence > xLabel( xLSeq->getLabel());
     485           0 :         Reference< data::XDataSequence > xValues( xLSeq->getValues());
     486             : 
     487           0 :         if( xLabel.is())
     488             :         {
     489           0 :             if( xValues.is())
     490             :             {
     491           0 :                 aResult.realloc( 2 );
     492           0 :                 aResult[0] = xLabel->getSourceRangeRepresentation();
     493           0 :                 aResult[1] = xValues->getSourceRangeRepresentation();
     494             :             }
     495             :             else
     496             :             {
     497           0 :                 aResult.realloc( 1 );
     498           0 :                 aResult[0] = xLabel->getSourceRangeRepresentation();
     499             :             }
     500             :         }
     501           0 :         else if( xValues.is())
     502             :         {
     503           0 :             aResult.realloc( 1 );
     504           0 :             aResult[0] = xValues->getSourceRangeRepresentation();
     505           0 :         }
     506             :     }
     507           0 :     return aResult;
     508             : }
     509             : 
     510        1421 : OUString DataSourceHelper::getRangeFromValues(
     511             :     const Reference< data::XLabeledDataSequence > & xLSeq )
     512             : {
     513        1421 :     OUString aResult;
     514        1421 :     if( xLSeq.is() )
     515             :     {
     516        1421 :         Reference< data::XDataSequence > xValues( xLSeq->getValues() );
     517        1421 :         if( xValues.is() )
     518        1417 :             aResult = xValues->getSourceRangeRepresentation();
     519             :     }
     520        1421 :     return aResult;
     521             : }
     522             : 
     523           0 : Sequence< OUString > DataSourceHelper::getRangesFromDataSource( const Reference< data::XDataSource > & xSource )
     524             : {
     525           0 :     ::std::vector< OUString > aResult;
     526           0 :     if( xSource.is())
     527             :     {
     528           0 :         Sequence< Reference< data::XLabeledDataSequence > > aLSeqSeq( xSource->getDataSequences());
     529           0 :         for( sal_Int32 i=0; i<aLSeqSeq.getLength(); ++i )
     530             :         {
     531           0 :             Reference< data::XDataSequence > xLabel( aLSeqSeq[i]->getLabel());
     532           0 :             Reference< data::XDataSequence > xValues( aLSeqSeq[i]->getValues());
     533             : 
     534           0 :             if( xLabel.is())
     535           0 :                 aResult.push_back( xLabel->getSourceRangeRepresentation());
     536           0 :             if( xValues.is())
     537           0 :                 aResult.push_back( xValues->getSourceRangeRepresentation());
     538           0 :         }
     539             :     }
     540           0 :     return ContainerHelper::ContainerToSequence( aResult );
     541             : }
     542             : 
     543         108 : } //namespace chart
     544             : 
     545             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10