LCOV - code coverage report
Current view: top level - chart2/source/model/template - BubbleDataInterpreter.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 136 0.0 %
Date: 2014-04-14 Functions: 0 6 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 "BubbleDataInterpreter.hxx"
      21             : #include "DataSeries.hxx"
      22             : #include "macros.hxx"
      23             : #include "DataSeriesHelper.hxx"
      24             : #include "CommonConverters.hxx"
      25             : #include "ContainerHelper.hxx"
      26             : #include <com/sun/star/beans/XPropertySet.hpp>
      27             : #include <com/sun/star/chart2/data/XDataSink.hpp>
      28             : #include <com/sun/star/util/XCloneable.hpp>
      29             : 
      30             : using namespace ::com::sun::star;
      31             : using namespace ::com::sun::star::chart2;
      32             : using namespace ::std;
      33             : 
      34             : using ::com::sun::star::uno::Reference;
      35             : using ::com::sun::star::uno::Sequence;
      36             : 
      37             : namespace chart
      38             : {
      39             : 
      40           0 : BubbleDataInterpreter::BubbleDataInterpreter(
      41             :     const uno::Reference< uno::XComponentContext > & xContext ) :
      42           0 :         DataInterpreter( xContext )
      43             : {
      44           0 : }
      45             : 
      46           0 : BubbleDataInterpreter::~BubbleDataInterpreter()
      47             : {
      48           0 : }
      49             : 
      50             : // ____ XDataInterpreter ____
      51           0 : chart2::InterpretedData SAL_CALL BubbleDataInterpreter::interpretDataSource(
      52             :     const Reference< chart2::data::XDataSource >& xSource,
      53             :     const Sequence< beans::PropertyValue >& aArguments,
      54             :     const Sequence< Reference< XDataSeries > >& aSeriesToReUse )
      55             :     throw (uno::RuntimeException, std::exception)
      56             : {
      57           0 :     if( ! xSource.is())
      58           0 :         return InterpretedData();
      59             : 
      60           0 :     Sequence< Reference< data::XLabeledDataSequence > > aData( xSource->getDataSequences() );
      61             : 
      62           0 :     Reference< data::XLabeledDataSequence > xValuesX;
      63           0 :     vector< Reference< data::XLabeledDataSequence > > aYValuesVector;
      64           0 :     vector< Reference< data::XLabeledDataSequence > > aSizeValuesVector;
      65             : 
      66           0 :     Reference< data::XLabeledDataSequence > xCategories;
      67           0 :     bool bHasCategories = HasCategories( aArguments, aData );
      68           0 :     bool bUseCategoriesAsX = UseCategoriesAsX( aArguments );
      69             : 
      70           0 :     sal_Int32 nDataSeqCount = aData.getLength();
      71             : 
      72           0 :     bool bSetXValues = bHasCategories ? ( (nDataSeqCount-1) > 2 && (nDataSeqCount-1) % 2 != 0 )
      73           0 :                                  :( nDataSeqCount > 2 && nDataSeqCount % 2 != 0 );
      74             : 
      75           0 :     bool bCategoriesUsed = false;
      76           0 :     bool bNextIsYValues = bHasCategories ? nDataSeqCount>2 : nDataSeqCount>1;
      77           0 :     for( sal_Int32 nDataIdx = 0; nDataIdx < nDataSeqCount; ++nDataIdx )
      78             :     {
      79             :         try
      80             :         {
      81           0 :             if( bHasCategories && !bCategoriesUsed )
      82             :             {
      83           0 :                 xCategories.set( aData[nDataIdx] );
      84           0 :                 if( xCategories.is())
      85             :                 {
      86           0 :                     SetRole( xCategories->getValues(), "categories");
      87           0 :                     if( bUseCategoriesAsX )
      88             :                     {
      89           0 :                         bSetXValues = false;
      90           0 :                         bNextIsYValues = nDataSeqCount > 2;
      91             :                     }
      92             :                 }
      93           0 :                 bCategoriesUsed = true;
      94             :             }
      95           0 :             else if( !xValuesX.is() && bSetXValues )
      96             :             {
      97           0 :                 xValuesX.set( aData[nDataIdx] );
      98           0 :                 if( xValuesX.is())
      99           0 :                     SetRole( xValuesX->getValues(), "values-x");
     100             :             }
     101           0 :             else if( bNextIsYValues )
     102             :             {
     103           0 :                 aYValuesVector.push_back( aData[nDataIdx] );
     104           0 :                 if( aData[nDataIdx].is())
     105           0 :                     SetRole( aData[nDataIdx]->getValues(), "values-y");
     106           0 :                 bNextIsYValues = false;
     107             :             }
     108           0 :             else if( !bNextIsYValues )
     109             :             {
     110           0 :                 aSizeValuesVector.push_back( aData[nDataIdx] );
     111           0 :                 if( aData[nDataIdx].is())
     112           0 :                     SetRole( aData[nDataIdx]->getValues(), "values-size");
     113           0 :                 bNextIsYValues = (nDataSeqCount-(nDataIdx+1)) >= 2;//two or more left
     114             :             }
     115             :         }
     116           0 :         catch( const uno::Exception & ex )
     117             :         {
     118             :             ASSERT_EXCEPTION( ex );
     119             :         }
     120             :     }
     121             : 
     122             :     // create DataSeries
     123           0 :     sal_Int32 nSeriesIndex = 0;
     124           0 :     vector< Reference< XDataSeries > > aSeriesVec;
     125           0 :     aSeriesVec.reserve( aSizeValuesVector.size());
     126             : 
     127           0 :     Reference< data::XLabeledDataSequence > xClonedXValues = xValuesX;
     128           0 :     Reference< util::XCloneable > xCloneableX( xValuesX, uno::UNO_QUERY );
     129             : 
     130           0 :     for( size_t nN = 0; nN < aSizeValuesVector.size(); ++nN, ++nSeriesIndex )
     131             :     {
     132           0 :         vector< Reference< data::XLabeledDataSequence > > aNewData;
     133           0 :         if( xValuesX.is() )
     134             :         {
     135           0 :             if( nN > 0 && xCloneableX.is() )
     136           0 :                 xClonedXValues.set( xCloneableX->createClone(), uno::UNO_QUERY );
     137           0 :             aNewData.push_back( xClonedXValues );
     138             :         }
     139           0 :         if( aYValuesVector.size() > nN )
     140           0 :             aNewData.push_back( aYValuesVector[nN] );
     141           0 :         if( aSizeValuesVector.size() > nN )
     142           0 :             aNewData.push_back( aSizeValuesVector[nN] );
     143             : 
     144           0 :         Reference< XDataSeries > xSeries;
     145           0 :         if( nSeriesIndex < aSeriesToReUse.getLength())
     146           0 :             xSeries.set( aSeriesToReUse[nSeriesIndex] );
     147             :         else
     148           0 :             xSeries.set( new DataSeries( GetComponentContext() ) );
     149             :         OSL_ASSERT( xSeries.is() );
     150           0 :         Reference< data::XDataSink > xSink( xSeries, uno::UNO_QUERY );
     151             :         OSL_ASSERT( xSink.is() );
     152           0 :         xSink->setData( ContainerHelper::ContainerToSequence( aNewData ) );
     153             : 
     154           0 :         aSeriesVec.push_back( xSeries );
     155           0 :     }
     156             : 
     157           0 :     Sequence< Sequence< Reference< XDataSeries > > > aSeries(1);
     158           0 :     aSeries[0] = ContainerHelper::ContainerToSequence( aSeriesVec );
     159           0 :     return InterpretedData( aSeries, xCategories );
     160             : }
     161             : 
     162           0 : chart2::InterpretedData SAL_CALL BubbleDataInterpreter::reinterpretDataSeries(
     163             :     const chart2::InterpretedData& aInterpretedData )
     164             :     throw (uno::RuntimeException, std::exception)
     165             : {
     166           0 :     InterpretedData aResult( aInterpretedData );
     167             : 
     168           0 :     sal_Int32 i=0;
     169           0 :     Sequence< Reference< XDataSeries > > aSeries( FlattenSequence( aInterpretedData.Series ));
     170           0 :     const sal_Int32 nCount = aSeries.getLength();
     171           0 :     for( ; i<nCount; ++i )
     172             :     {
     173             :         try
     174             :         {
     175           0 :             Reference< data::XDataSource > xSeriesSource( aSeries[i], uno::UNO_QUERY_THROW );
     176           0 :             Sequence< Reference< data::XLabeledDataSequence > > aNewSequences;
     177             : 
     178             :             Reference< data::XLabeledDataSequence > xValuesSize(
     179           0 :                 DataSeriesHelper::getDataSequenceByRole( xSeriesSource, "values-size", false ));
     180             :             Reference< data::XLabeledDataSequence > xValuesY(
     181           0 :                 DataSeriesHelper::getDataSequenceByRole( xSeriesSource, "values-y", false ));
     182             :             Reference< data::XLabeledDataSequence > xValuesX(
     183           0 :                 DataSeriesHelper::getDataSequenceByRole( xSeriesSource, "values-x", false ));
     184             : 
     185           0 :             if( ! xValuesX.is() ||
     186           0 :                 ! xValuesY.is() ||
     187           0 :                 ! xValuesSize.is() )
     188             :             {
     189             :                 vector< Reference< data::XLabeledDataSequence > > aValueSeqVec(
     190             :                     DataSeriesHelper::getAllDataSequencesByRole(
     191           0 :                         xSeriesSource->getDataSequences(), "values", true ));
     192           0 :                 if( xValuesX.is())
     193           0 :                     aValueSeqVec.erase( find( aValueSeqVec.begin(), aValueSeqVec.end(), xValuesX ));
     194           0 :                 if( xValuesY.is())
     195           0 :                     aValueSeqVec.erase( find( aValueSeqVec.begin(), aValueSeqVec.end(), xValuesY ));
     196           0 :                 if( xValuesSize.is())
     197           0 :                     aValueSeqVec.erase( find( aValueSeqVec.begin(), aValueSeqVec.end(), xValuesSize ));
     198             : 
     199           0 :                 size_t nIndex = 0;
     200             : 
     201           0 :                 if( ! xValuesSize.is() &&
     202           0 :                     aValueSeqVec.size() > nIndex )
     203             :                 {
     204           0 :                     xValuesSize.set( aValueSeqVec[nIndex++] );
     205           0 :                     if( xValuesSize.is())
     206           0 :                         SetRole( xValuesSize->getValues(), "values-size");
     207             :                 }
     208             : 
     209           0 :                 if( ! xValuesY.is() &&
     210           0 :                     aValueSeqVec.size() > nIndex )
     211             :                 {
     212           0 :                     xValuesY.set( aValueSeqVec[nIndex++] );
     213           0 :                     if( xValuesY.is())
     214           0 :                         SetRole( xValuesY->getValues(), "values-y");
     215             :                 }
     216             : 
     217           0 :                 if( ! xValuesX.is() &&
     218           0 :                     aValueSeqVec.size() > nIndex )
     219             :                 {
     220           0 :                     xValuesX.set( aValueSeqVec[nIndex++] );
     221           0 :                     if( xValuesX.is())
     222           0 :                         SetRole( xValuesY->getValues(), "values-x");
     223           0 :                 }
     224             :             }
     225           0 :             if( xValuesSize.is())
     226             :             {
     227           0 :                 if( xValuesY.is() )
     228             :                 {
     229           0 :                     if( xValuesX.is() )
     230             :                     {
     231           0 :                         aNewSequences.realloc(3);
     232           0 :                         aNewSequences[0] = xValuesX;
     233           0 :                         aNewSequences[1] = xValuesY;
     234           0 :                         aNewSequences[2] = xValuesSize;
     235             :                     }
     236             :                     else
     237             :                     {
     238           0 :                         aNewSequences.realloc(2);
     239           0 :                         aNewSequences[0] = xValuesY;
     240           0 :                         aNewSequences[1] = xValuesSize;
     241             :                     }
     242             :                 }
     243             :                 else
     244             :                 {
     245           0 :                     aNewSequences.realloc(1);
     246           0 :                     aNewSequences[0] = xValuesSize;
     247             :                 }
     248             :             }
     249             : 
     250           0 :             Sequence< Reference< data::XLabeledDataSequence > > aSeqs( xSeriesSource->getDataSequences());
     251           0 :             if( aSeqs.getLength() != aNewSequences.getLength() )
     252             :             {
     253             : #if OSL_DEBUG_LEVEL > 1
     254             :                 sal_Int32 j=0;
     255             :                 for( ; j<aSeqs.getLength(); ++j )
     256             :                 {
     257             :                     OSL_ENSURE( aSeqs[j] == xValuesY || aSeqs[j] == xValuesX || aSeqs[j] == xValuesSize, "All sequences should be used" );
     258             :                 }
     259             : #endif
     260           0 :                 Reference< data::XDataSink > xSink( xSeriesSource, uno::UNO_QUERY_THROW );
     261           0 :                 xSink->setData( aNewSequences );
     262           0 :             }
     263             :         }
     264           0 :         catch( const uno::Exception & ex )
     265             :         {
     266             :             ASSERT_EXCEPTION( ex );
     267             :         }
     268             :     }
     269             : 
     270           0 :     return aResult;
     271             : }
     272             : 
     273           0 : sal_Bool SAL_CALL BubbleDataInterpreter::isDataCompatible(
     274             :     const chart2::InterpretedData& aInterpretedData )
     275             :     throw (uno::RuntimeException, std::exception)
     276             : {
     277           0 :     Sequence< Reference< XDataSeries > > aSeries( FlattenSequence( aInterpretedData.Series ));
     278           0 :     for( sal_Int32 i=0; i<aSeries.getLength(); ++i )
     279             :     {
     280             :         try
     281             :         {
     282           0 :             Reference< data::XDataSource > xSrc( aSeries[i], uno::UNO_QUERY_THROW );
     283           0 :             Sequence< Reference< data::XLabeledDataSequence > > aSeq( xSrc->getDataSequences());
     284           0 :             if( aSeq.getLength() != 3 )
     285           0 :                 return sal_False;
     286             :         }
     287           0 :         catch( const uno::Exception & ex )
     288             :         {
     289             :             ASSERT_EXCEPTION( ex );
     290             :         }
     291             :     }
     292             : 
     293           0 :     return sal_True;
     294             : }
     295             : 
     296             : } // namespace chart
     297             : 
     298             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10