LCOV - code coverage report
Current view: top level - chart2/source/tools - DataSourceHelper.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 178 261 68.2 %
Date: 2015-06-13 12:38:46 Functions: 16 24 66.7 %
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        3050 : void lcl_addRanges( ::std::vector< OUString > & rOutResult,
      50             :                     const uno::Reference< data::XLabeledDataSequence > & xLabeledSeq )
      51             : {
      52        3050 :     if( ! xLabeledSeq.is())
      53        3050 :         return;
      54        3050 :     uno::Reference< data::XDataSequence > xSeq( xLabeledSeq->getLabel());
      55        3050 :     if( xSeq.is())
      56        2288 :         rOutResult.push_back( xSeq->getSourceRangeRepresentation());
      57        3050 :     xSeq.set( xLabeledSeq->getValues());
      58        3050 :     if( xSeq.is())
      59        3050 :         rOutResult.push_back( xSeq->getSourceRangeRepresentation());
      60             : }
      61             : 
      62        2290 : void lcl_addDataSourceRanges(
      63             :     ::std::vector< OUString > & rOutResult,
      64             :     const uno::Reference< data::XDataSource > & xDataSource )
      65             : {
      66        2290 :     if( xDataSource.is() )
      67             :     {
      68        2290 :         uno::Sequence< uno::Reference< data::XLabeledDataSequence > > aDataSequences( xDataSource->getDataSequences() );
      69        4584 :         for( sal_Int32 i=0; i<aDataSequences.getLength(); ++i)
      70        4584 :             lcl_addRanges( rOutResult, aDataSequences[i] );
      71             :     }
      72        2290 : }
      73             : 
      74        2289 : void lcl_addErrorBarRanges(
      75             :     ::std::vector< OUString > & rOutResult,
      76             :     const uno::Reference< XDataSeries > & xDataSeries )
      77             : {
      78        2289 :     uno::Reference< beans::XPropertySet > xSeriesProp( xDataSeries, uno::UNO_QUERY );
      79        2289 :     if( !xSeriesProp.is())
      80        2289 :         return;
      81             : 
      82             :     try
      83             :     {
      84        2289 :         uno::Reference< beans::XPropertySet > xErrorBarProp;
      85        4578 :         if( ( xSeriesProp->getPropertyValue( CHART_UNONAME_ERRORBAR_Y) >>= xErrorBarProp ) &&
      86        2289 :             xErrorBarProp.is())
      87             :         {
      88         871 :             sal_Int32 eStyle = ::com::sun::star::chart::ErrorBarStyle::NONE;
      89        1742 :             if( ( xErrorBarProp->getPropertyValue( "ErrorBarStyle") >>= eStyle ) &&
      90         871 :                 eStyle == ::com::sun::star::chart::ErrorBarStyle::FROM_DATA )
      91             :             {
      92           1 :                 uno::Reference< data::XDataSource > xErrorBarDataSource( xErrorBarProp, uno::UNO_QUERY );
      93           1 :                 if( xErrorBarDataSource.is() )
      94           1 :                     lcl_addDataSourceRanges( rOutResult, xErrorBarDataSource );
      95             :             }
      96             :         }
      97             : 
      98        2289 :         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        2289 :         }
     109             :     }
     110           0 :     catch( const uno::Exception & ex )
     111             :     {
     112             :         ASSERT_EXCEPTION( ex );
     113        2289 :     }
     114             : }
     115             : 
     116             : } // anonymous namespace
     117             : 
     118           8 : Reference< chart2::data::XDataSource > DataSourceHelper::createDataSource(
     119             :         const Sequence< Reference< chart2::data::XLabeledDataSequence > >& rSequences )
     120             : {
     121           8 :     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        5332 : uno::Sequence< beans::PropertyValue > DataSourceHelper::createArguments(
     154             :                                             bool bUseColumns, bool bFirstCellAsLabel, bool bHasCategories )
     155             : {
     156        5332 :     ::com::sun::star::chart::ChartDataRowSource eRowSource = ::com::sun::star::chart::ChartDataRowSource_ROWS;
     157        5332 :     if( bUseColumns )
     158        2670 :         eRowSource = ::com::sun::star::chart::ChartDataRowSource_COLUMNS;
     159             : 
     160        5332 :     uno::Sequence< beans::PropertyValue > aArguments(3);
     161       10664 :     aArguments[0] = beans::PropertyValue( "DataRowSource"
     162             :         , -1, uno::makeAny( eRowSource )
     163        5332 :         , beans::PropertyState_DIRECT_VALUE );
     164       10664 :     aArguments[1] = beans::PropertyValue( "FirstCellAsLabel"
     165             :         , -1, uno::makeAny( bFirstCellAsLabel )
     166        5332 :         , beans::PropertyState_DIRECT_VALUE );
     167       10664 :     aArguments[2] = beans::PropertyValue( "HasCategories"
     168             :         , -1, uno::makeAny( bHasCategories )
     169        5332 :         , beans::PropertyState_DIRECT_VALUE );
     170             : 
     171        5332 :     return aArguments;
     172             : }
     173             : 
     174        5332 : 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        5332 :     uno::Sequence< beans::PropertyValue > aArguments( createArguments( bUseColumns, bFirstCellAsLabel, bHasCategories ));
     180        5332 :     aArguments.realloc( aArguments.getLength() + 1 );
     181       10664 :     aArguments[aArguments.getLength() - 1] =
     182             :         beans::PropertyValue( "CellRangeRepresentation"
     183             :                               , -1, uno::makeAny( rRangeRepresentation )
     184        5332 :                               , beans::PropertyState_DIRECT_VALUE );
     185        5332 :     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        5332 :     return aArguments;
     194             : }
     195             : 
     196        6320 : 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        6320 :     const beans::PropertyValue* pArguments = rArguments.getConstArray();
     201       31698 :     for(sal_Int32 i=0; i<rArguments.getLength(); ++i, ++pArguments)
     202             :     {
     203       25378 :         const beans::PropertyValue& aProperty = *pArguments;
     204       25378 :         if ( aProperty.Name == "DataRowSource" )
     205             :         {
     206             :             ::com::sun::star::chart::ChartDataRowSource eRowSource;
     207        6304 :             if( aProperty.Value >>= eRowSource )
     208        6304 :                 bUseColumns = (eRowSource==::com::sun::star::chart::ChartDataRowSource_COLUMNS);
     209             :         }
     210       19074 :         else if ( aProperty.Name == "FirstCellAsLabel" )
     211             :         {
     212        6304 :             aProperty.Value >>= bFirstCellAsLabel;
     213             :         }
     214       12770 :         else if ( aProperty.Name == "HasCategories" )
     215             :         {
     216        6303 :             aProperty.Value >>= bHasCategories;
     217             :         }
     218        6467 :         else if ( aProperty.Name == "CellRangeRepresentation" )
     219             :         {
     220        6314 :             aProperty.Value >>= rRangeRepresentation;
     221             :         }
     222         153 :         else if ( aProperty.Name == "SequenceMapping" )
     223             :         {
     224           0 :             aProperty.Value >>= rSequenceMapping;
     225             :         }
     226             :     }
     227        6320 : }
     228             : 
     229        1720 : uno::Reference< chart2::data::XDataSource > DataSourceHelper::pressUsedDataIntoRectangularFormat(
     230             :         const uno::Reference< chart2::XChartDocument >& xChartDoc, bool bWithCategories )
     231             : {
     232        1720 :     ::std::vector< Reference< chart2::data::XLabeledDataSequence > > aResultVector;
     233             : 
     234             :     //categories are always the first sequence
     235        3440 :     Reference< chart2::XDiagram > xDiagram( xChartDoc->getFirstDiagram());
     236             : 
     237        1720 :     if( bWithCategories )
     238             :     {
     239        1720 :         Reference< chart2::data::XLabeledDataSequence > xCategories( DiagramHelper::getCategoriesFromDiagram( xDiagram ) );
     240        1720 :         if( xCategories.is() )
     241        1301 :             aResultVector.push_back( xCategories );
     242             :     }
     243             : 
     244        3440 :     ::std::vector< Reference< chart2::XDataSeries > > xSeriesVector( DiagramHelper::getDataSeriesFromDiagram( xDiagram ) );
     245             :     uno::Reference< chart2::data::XDataSource > xSeriesSource(
     246        3440 :         DataSeriesHelper::getDataSource( ContainerHelper::ContainerToSequence(xSeriesVector) ) );
     247        3440 :     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        3440 :         DataSeriesHelper::getDataSequenceByRole( xSeriesSource, "values-x" ) );
     252        1720 :     if( xXValues.is() )
     253         161 :         aResultVector.push_back( xXValues );
     254             : 
     255             :     //add all other sequences now without x-values
     256        5677 :     for( sal_Int32 nN=0; nN<aDataSeqences.getLength(); nN++ )
     257             :     {
     258        3957 :         OUString aRole = DataSeriesHelper::getRole(aDataSeqences[nN]);
     259        3957 :         if( aRole != "values-x" )
     260        3704 :             aResultVector.push_back( aDataSeqences[nN] );
     261        3957 :     }
     262             : 
     263        3440 :     Sequence< Reference< chart2::data::XLabeledDataSequence > > aResultSequence( aResultVector.size() );
     264        1720 :     ::std::copy( aResultVector.begin(), aResultVector.end(), aResultSequence.getArray() );
     265             : 
     266        3440 :     return new DataSource( aResultSequence );
     267             : }
     268             : 
     269         769 : uno::Sequence< OUString > DataSourceHelper::getUsedDataRanges(
     270             :     const uno::Reference< chart2::XDiagram > & xDiagram )
     271             : {
     272         769 :     ::std::vector< OUString > aResult;
     273             : 
     274         769 :     if( xDiagram.is())
     275             :     {
     276         769 :         uno::Reference< data::XLabeledDataSequence > xCategories( DiagramHelper::getCategoriesFromDiagram( xDiagram ) );
     277         769 :         if( xCategories.is() )
     278         756 :             lcl_addRanges( aResult, xCategories );
     279             : 
     280        1538 :         ::std::vector< uno::Reference< XDataSeries > > aSeriesVector( DiagramHelper::getDataSeriesFromDiagram( xDiagram ) );
     281        9174 :         for( ::std::vector< uno::Reference< XDataSeries > >::const_iterator aSeriesIt( aSeriesVector.begin() )
     282        6116 :                  ; aSeriesIt != aSeriesVector.end(); ++aSeriesIt )
     283             :         {
     284        2289 :             uno::Reference< data::XDataSource > xDataSource( *aSeriesIt, uno::UNO_QUERY );
     285        2289 :             lcl_addDataSourceRanges( aResult, xDataSource );
     286        2289 :             lcl_addErrorBarRanges( aResult, *aSeriesIt );
     287        3058 :         }
     288             :     }
     289             : 
     290         769 :     return ContainerHelper::ContainerToSequence( aResult );
     291             : }
     292             : 
     293           6 : uno::Sequence< OUString > DataSourceHelper::getUsedDataRanges( const uno::Reference< frame::XModel > & xChartModel )
     294             : {
     295           6 :     uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
     296           6 :     return getUsedDataRanges( xDiagram );
     297             : }
     298             : 
     299         390 : uno::Reference< chart2::data::XDataSource > DataSourceHelper::getUsedData(
     300             :     const uno::Reference< chart2::XChartDocument >& xChartDoc )
     301             : {
     302         390 :     return pressUsedDataIntoRectangularFormat( xChartDoc );
     303             : }
     304             : 
     305           2 : uno::Reference< chart2::data::XDataSource > DataSourceHelper::getUsedData(
     306             :     const uno::Reference< frame::XModel >& xChartModel )
     307             : {
     308           2 :     ::std::vector< uno::Reference< chart2::data::XLabeledDataSequence > > aResult;
     309             : 
     310           4 :     uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
     311           4 :     uno::Reference< data::XLabeledDataSequence > xCategories( DiagramHelper::getCategoriesFromDiagram( xDiagram ) );
     312           2 :     if( xCategories.is() )
     313           2 :         aResult.push_back( xCategories );
     314             : 
     315           4 :     ::std::vector< uno::Reference< XDataSeries > > aSeriesVector( ChartModelHelper::getDataSeries( xChartModel ) );
     316          12 :     for( ::std::vector< uno::Reference< XDataSeries > >::const_iterator aSeriesIt( aSeriesVector.begin() )
     317           8 :         ; aSeriesIt != aSeriesVector.end(); ++aSeriesIt )
     318             :     {
     319           2 :         uno::Reference< data::XDataSource > xDataSource( *aSeriesIt, uno::UNO_QUERY );
     320           2 :         if( !xDataSource.is() )
     321           0 :             continue;
     322           4 :         uno::Sequence< uno::Reference< data::XLabeledDataSequence > > aDataSequences( xDataSource->getDataSequences() );
     323             :         ::std::copy( aDataSequences.begin(), aDataSequences.end(),
     324           2 :                      ::std::back_inserter( aResult ));
     325           2 :     }
     326             : 
     327             :     return uno::Reference< chart2::data::XDataSource >(
     328           4 :         new DataSource( ContainerHelper::ContainerToSequence( aResult )));
     329             : }
     330             : 
     331         308 : uno::Reference< chart2::data::XDataSource > DataSourceHelper::getUsedData(
     332             :     ChartModel& rModel )
     333             : {
     334         308 :     ::std::vector< uno::Reference< chart2::data::XLabeledDataSequence > > aResult;
     335             : 
     336         616 :     uno::Reference< XDiagram > xDiagram( rModel.getFirstDiagram() );
     337         616 :     uno::Reference< data::XLabeledDataSequence > xCategories( DiagramHelper::getCategoriesFromDiagram( xDiagram ) );
     338         308 :     if( xCategories.is() )
     339         132 :         aResult.push_back( xCategories );
     340             : 
     341         616 :     ::std::vector< uno::Reference< XDataSeries > > aSeriesVector( ChartModelHelper::getDataSeries( rModel ) );
     342        2202 :     for( ::std::vector< uno::Reference< XDataSeries > >::const_iterator aSeriesIt( aSeriesVector.begin() )
     343        1468 :         ; aSeriesIt != aSeriesVector.end(); ++aSeriesIt )
     344             :     {
     345         426 :         uno::Reference< data::XDataSource > xDataSource( *aSeriesIt, uno::UNO_QUERY );
     346         426 :         if( !xDataSource.is() )
     347           0 :             continue;
     348         852 :         uno::Sequence< uno::Reference< data::XLabeledDataSequence > > aDataSequences( xDataSource->getDataSequences() );
     349             :         ::std::copy( aDataSequences.begin(), aDataSequences.end(),
     350         426 :                      ::std::back_inserter( aResult ));
     351         426 :     }
     352             : 
     353             :     return uno::Reference< chart2::data::XDataSource >(
     354         616 :         new DataSource( ContainerHelper::ContainerToSequence( aResult )));
     355             : }
     356             : 
     357        1330 : 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        1330 :     bool bSomethingDetected = false;
     367             : 
     368        1330 :     uno::Reference< XChartDocument > xChartDocument( xChartModel, uno::UNO_QUERY );
     369        1330 :     if( !xChartDocument.is() )
     370           0 :         return bSomethingDetected;
     371        2660 :     uno::Reference< data::XDataProvider >  xDataProvider( xChartDocument->getDataProvider() );
     372        1330 :     if( !xDataProvider.is() )
     373           5 :         return bSomethingDetected;
     374             : 
     375             :     try
     376             :     {
     377             :         DataSourceHelper::readArguments(
     378        1325 :             xDataProvider->detectArguments( pressUsedDataIntoRectangularFormat( xChartDocument ) ),
     379        1325 :             rOutRangeString, rSequenceMapping, rOutUseColumns, rOutFirstCellAsLabel, rOutHasCategories );
     380        1325 :         bSomethingDetected = !rOutRangeString.isEmpty();
     381             : 
     382             :         uno::Reference< chart2::data::XLabeledDataSequence > xCategories(
     383        1325 :                     DiagramHelper::getCategoriesFromDiagram( xChartDocument->getFirstDiagram() ));
     384        1325 :         rOutHasCategories = xCategories.is();
     385             :     }
     386           0 :     catch( uno::Exception & ex )
     387             :     {
     388             :         ASSERT_EXCEPTION( ex );
     389             :     }
     390        2655 :     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(cppu::UnoType<bool>::get()));
     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           5 : 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           5 :     uno::Reference< XChartDocument > xChartDocument( xChartModel, uno::UNO_QUERY );
     445           5 :     if( !xChartDocument.is() )
     446           0 :         return;
     447          10 :     uno::Reference< data::XDataProvider > xDataProvider( xChartDocument->getDataProvider() );
     448           5 :     if( !xDataProvider.is() )
     449           0 :         return;
     450          10 :     uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
     451           5 :     if( !xDiagram.is() )
     452           0 :         return;
     453          10 :     uno::Reference< chart2::XChartTypeManager > xChartTypeManager( xChartDocument->getChartTypeManager() );
     454           5 :     if( !xChartTypeManager.is() )
     455           0 :         return;
     456          10 :     uno::Reference< lang::XMultiServiceFactory > xTemplateFactory( xChartTypeManager, uno::UNO_QUERY );
     457           5 :     if( !xTemplateFactory.is() )
     458           0 :         return;
     459             : 
     460          10 :     OUString aRangeString;
     461             :     bool bDummy;
     462          10 :     uno::Sequence< sal_Int32 > aDummy;
     463           5 :     readArguments( xDataProvider->detectArguments( pressUsedDataIntoRectangularFormat( xChartDocument )),
     464           5 :                    aRangeString, aDummy, bDummy, bDummy, bDummy );
     465             : 
     466             :     uno::Sequence< beans::PropertyValue > aArguments(
     467          10 :         createArguments( aRangeString, rSequenceMapping, bUseColumns, bFirstCellAsLabel, bUseCategories ) );
     468             : 
     469           5 :     uno::Reference< chart2::data::XDataSource > xDataSource( xDataProvider->createDataSource(
     470          10 :                                                                  aArguments ) );
     471           5 :     if( !xDataSource.is() )
     472           0 :         return;
     473             : 
     474          10 :     ControllerLockGuardUNO aCtrlLockGuard( xChartModel );
     475          10 :     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        2662 : OUString DataSourceHelper::getRangeFromValues(
     511             :     const Reference< data::XLabeledDataSequence > & xLSeq )
     512             : {
     513        2662 :     OUString aResult;
     514        2662 :     if( xLSeq.is() )
     515             :     {
     516        2662 :         Reference< data::XDataSequence > xValues( xLSeq->getValues() );
     517        2662 :         if( xValues.is() )
     518        2660 :             aResult = xValues->getSourceRangeRepresentation();
     519             :     }
     520        2662 :     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             : } //namespace chart
     544             : 
     545             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11