LCOV - code coverage report
Current view: top level - chart2/source/controller/chartapiwrapper - WrappedSeriesOrDiagramProperty.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 61 62 98.4 %
Date: 2015-06-13 12:38:46 Functions: 52 72 72.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             : #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       39476 :     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       39476 :             , m_ePropertyType( ePropertyType )
      59             :     {
      60       39476 :     }
      61       39476 :     virtual ~WrappedSeriesOrDiagramProperty() {};
      62             : 
      63        5579 :     bool detectInnerValue( PROPERTYTYPE& rValue, bool& rHasAmbiguousValue ) const
      64             :     {
      65        5579 :         bool bHasDetectableInnerValue = false;
      66        5579 :         rHasAmbiguousValue = false;
      67       11158 :         if( m_ePropertyType == DIAGRAM &&
      68        5579 :             m_spChart2ModelContact.get() )
      69             :         {
      70             :             ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > > aSeriesVector(
      71        5579 :                 ::chart::DiagramHelper::getDataSeriesFromDiagram( m_spChart2ModelContact->getChart2Diagram() ) );
      72             :             ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > >::const_iterator aIter =
      73        5579 :                     aSeriesVector.begin();
      74       16836 :             for( ; aIter != aSeriesVector.end(); ++aIter )
      75             :             {
      76       11338 :                 PROPERTYTYPE aCurValue = getValueFromSeries( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >::query( *aIter ) );
      77       11338 :                 if( !bHasDetectableInnerValue )
      78        5121 :                     rValue = aCurValue;
      79             :                 else
      80             :                 {
      81        6217 :                     if( rValue != aCurValue )
      82             :                     {
      83          81 :                         rHasAmbiguousValue = true;
      84          81 :                         break;
      85             :                     }
      86             :                     else
      87        6136 :                         rValue = aCurValue;
      88             :                 }
      89       11257 :                 bHasDetectableInnerValue = true;
      90        5579 :             }
      91             :         }
      92        5579 :         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         979 :     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         979 :         PROPERTYTYPE aNewValue = PROPERTYTYPE();
     117         979 :         if( ! (rOuterValue >>= aNewValue) )
     118           0 :             throw ::com::sun::star::lang::IllegalArgumentException( "statistic property requires different type", 0, 0 );
     119             : 
     120         979 :         if( m_ePropertyType == DIAGRAM )
     121             :         {
     122         100 :             m_aOuterValue = rOuterValue;
     123             : 
     124         100 :             bool bHasAmbiguousValue = false;
     125         100 :             PROPERTYTYPE aOldValue = PROPERTYTYPE();
     126         100 :             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          20 :         }
     136         979 :     }
     137             : 
     138       17363 :     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       17363 :         if( m_ePropertyType == DIAGRAM )
     142             :         {
     143        4764 :             bool bHasAmbiguousValue = false;
     144        1622 :             PROPERTYTYPE aValue;
     145        4764 :             if( detectInnerValue( aValue, bHasAmbiguousValue ) )
     146             :             {
     147        4486 :                 if(bHasAmbiguousValue)
     148          24 :                     m_aOuterValue <<= m_aDefaultValue;
     149             :                 else
     150        4462 :                     m_aOuterValue <<= aValue;
     151             :             }
     152        4764 :             return m_aOuterValue;
     153             :         }
     154             :         else
     155             :         {
     156       12599 :             ::com::sun::star::uno::Any aRet( m_aDefaultValue );
     157       12599 :             aRet <<= getValueFromSeries( xInnerPropertySet );
     158       12599 :             return aRet;
     159             :         }
     160             :     }
     161             : 
     162       15210 :     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       15210 :         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.11