LCOV - code coverage report
Current view: top level - chart2/source/controller/chartapiwrapper - WrappedSeriesOrDiagramProperty.hxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 61 62 98.4 %
Date: 2014-04-11 Functions: 51 72 70.8 %
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             : #ifndef INCLUDED_CHART2_SOURCE_CONTROLLER_CHARTAPIWRAPPER_WRAPPEDSERIESORDIAGRAMPROPERTY_HXX
      20             : #define INCLUDED_CHART2_SOURCE_CONTROLLER_CHARTAPIWRAPPER_WRAPPEDSERIESORDIAGRAMPROPERTY_HXX
      21             : 
      22             : #include "WrappedProperty.hxx"
      23             : #include "Chart2ModelContact.hxx"
      24             : #include "macros.hxx"
      25             : #include "DiagramHelper.hxx"
      26             : #include <com/sun/star/chart2/XDataSeries.hpp>
      27             : 
      28             : #include <boost/shared_ptr.hpp>
      29             : #include <vector>
      30             : 
      31             : namespace chart
      32             : {
      33             : namespace wrapper
      34             : {
      35             : 
      36             : enum tSeriesOrDiagramPropertyType
      37             : {
      38             :     DATA_SERIES,
      39             :     DIAGRAM
      40             : };
      41             : 
      42             : //PROPERTYTYPE is the type of the outer property
      43             : 
      44             : template< typename PROPERTYTYPE >
      45             : class WrappedSeriesOrDiagramProperty : public WrappedProperty
      46             : {
      47             : public:
      48             :     virtual PROPERTYTYPE getValueFromSeries( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xSeriesPropertySet ) const =0;
      49             :     virtual void setValueToSeries( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xSeriesPropertySet, const PROPERTYTYPE & aNewValue ) const =0;
      50             : 
      51       27986 :     explicit WrappedSeriesOrDiagramProperty( const OUString& rName, const ::com::sun::star::uno::Any& rDefaulValue
      52             :         , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact
      53             :         , tSeriesOrDiagramPropertyType ePropertyType )
      54             :             : WrappedProperty(rName,OUString())
      55             :             , m_spChart2ModelContact(spChart2ModelContact)
      56             :             , m_aOuterValue(rDefaulValue)
      57             :             , m_aDefaultValue(rDefaulValue)
      58       27986 :             , m_ePropertyType( ePropertyType )
      59             :     {
      60       27986 :     }
      61       27872 :     virtual ~WrappedSeriesOrDiagramProperty() {};
      62             : 
      63        3614 :     bool detectInnerValue( PROPERTYTYPE& rValue, bool& rHasAmbiguousValue ) const
      64             :     {
      65        3614 :         bool bHasDetectableInnerValue = false;
      66        3614 :         rHasAmbiguousValue = false;
      67        7228 :         if( m_ePropertyType == DIAGRAM &&
      68        3614 :             m_spChart2ModelContact.get() )
      69             :         {
      70             :             ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > > aSeriesVector(
      71        3614 :                 ::chart::DiagramHelper::getDataSeriesFromDiagram( m_spChart2ModelContact->getChart2Diagram() ) );
      72             :             ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > >::const_iterator aIter =
      73        3614 :                     aSeriesVector.begin();
      74       11344 :             for( ; aIter != aSeriesVector.end(); ++aIter )
      75             :             {
      76        7749 :                 PROPERTYTYPE aCurValue = getValueFromSeries( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >::query( *aIter ) );
      77        7749 :                 if( !bHasDetectableInnerValue )
      78        3209 :                     rValue = aCurValue;
      79             :                 else
      80             :                 {
      81        4540 :                     if( rValue != aCurValue )
      82             :                     {
      83          19 :                         rHasAmbiguousValue = true;
      84          19 :                         break;
      85             :                     }
      86             :                     else
      87        4521 :                         rValue = aCurValue;
      88             :                 }
      89        7730 :                 bHasDetectableInnerValue = true;
      90        3614 :             }
      91             :         }
      92        3614 :         return bHasDetectableInnerValue;
      93             :     }
      94           8 :     void setInnerValue( PROPERTYTYPE aNewValue ) const
      95             :     {
      96          16 :         if( m_ePropertyType == DIAGRAM &&
      97           8 :             m_spChart2ModelContact.get() )
      98             :         {
      99             :             ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > > aSeriesVector(
     100           8 :                 ::chart::DiagramHelper::getDataSeriesFromDiagram( m_spChart2ModelContact->getChart2Diagram() ) );
     101             :             ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > >::const_iterator aIter =
     102           8 :                     aSeriesVector.begin();
     103          32 :             for( ; aIter != aSeriesVector.end(); ++aIter )
     104             :             {
     105          24 :                 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xSeriesPropertySet( *aIter, ::com::sun::star::uno::UNO_QUERY );
     106          24 :                 if( xSeriesPropertySet.is() )
     107             :                 {
     108          24 :                     setValueToSeries( xSeriesPropertySet, aNewValue );
     109             :                 }
     110           8 :             }
     111             :         }
     112           8 :     }
     113         960 :     virtual void setPropertyValue( const ::com::sun::star::uno::Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
     114             :                     throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
     115             :     {
     116         960 :         PROPERTYTYPE aNewValue = PROPERTYTYPE();
     117         960 :         if( ! (rOuterValue >>= aNewValue) )
     118           0 :             throw ::com::sun::star::lang::IllegalArgumentException( "statistic property requires different type", 0, 0 );
     119             : 
     120         960 :         if( m_ePropertyType == DIAGRAM )
     121             :         {
     122          81 :             m_aOuterValue = rOuterValue;
     123             : 
     124          81 :             bool bHasAmbiguousValue = false;
     125          81 :             PROPERTYTYPE aOldValue = PROPERTYTYPE();
     126          81 :             if( detectInnerValue( aOldValue, bHasAmbiguousValue ) )
     127             :             {
     128           8 :                 if( bHasAmbiguousValue || aNewValue != aOldValue )
     129           8 :                     setInnerValue( aNewValue );
     130          10 :             }
     131             :         }
     132             :         else
     133             :         {
     134         879 :             setValueToSeries( xInnerPropertySet, aNewValue );
     135          21 :         }
     136         960 :     }
     137             : 
     138       13793 :     virtual ::com::sun::star::uno::Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
     139             :                             throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
     140             :     {
     141       13793 :         if( m_ePropertyType == DIAGRAM )
     142             :         {
     143        3075 :             bool bHasAmbiguousValue = false;
     144        1032 :             PROPERTYTYPE aValue;
     145        3075 :             if( detectInnerValue( aValue, bHasAmbiguousValue ) )
     146             :             {
     147        2826 :                 if(bHasAmbiguousValue)
     148           6 :                     m_aOuterValue <<= m_aDefaultValue;
     149             :                 else
     150        2820 :                     m_aOuterValue <<= aValue;
     151             :             }
     152        3075 :             return m_aOuterValue;
     153             :         }
     154             :         else
     155             :         {
     156       10718 :             ::com::sun::star::uno::Any aRet( m_aDefaultValue );
     157       10718 :             aRet <<= getValueFromSeries( xInnerPropertySet );
     158       10718 :             return aRet;
     159             :         }
     160             :     }
     161             : 
     162       11082 :     virtual ::com::sun::star::uno::Any getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& /* xInnerPropertyState */ ) const
     163             :                             throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
     164             :     {
     165       11082 :         return m_aDefaultValue;
     166             :     }
     167             : 
     168             : protected:
     169             :     ::boost::shared_ptr< Chart2ModelContact >  m_spChart2ModelContact;
     170             :     mutable ::com::sun::star::uno::Any         m_aOuterValue;
     171             :     ::com::sun::star::uno::Any                 m_aDefaultValue;
     172             :     tSeriesOrDiagramPropertyType               m_ePropertyType;
     173             : };
     174             : 
     175             : } //namespace wrapper
     176             : } //namespace chart
     177             : 
     178             : // INCLUDED_CHART2_SOURCE_CONTROLLER_CHARTAPIWRAPPER_WRAPPEDSERIESORDIAGRAMPROPERTY_HXX
     179             : #endif
     180             : 
     181             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10