LCOV - code coverage report
Current view: top level - chart2/source/controller/chartapiwrapper - WrappedSeriesOrDiagramProperty.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 61 62 98.4 %
Date: 2014-11-03 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       81814 :     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       81814 :             , m_ePropertyType( ePropertyType )
      59             :     {
      60       81814 :     }
      61       81814 :     virtual ~WrappedSeriesOrDiagramProperty() {};
      62             : 
      63       11600 :     bool detectInnerValue( PROPERTYTYPE& rValue, bool& rHasAmbiguousValue ) const
      64             :     {
      65       11600 :         bool bHasDetectableInnerValue = false;
      66       11600 :         rHasAmbiguousValue = false;
      67       23200 :         if( m_ePropertyType == DIAGRAM &&
      68       11600 :             m_spChart2ModelContact.get() )
      69             :         {
      70             :             ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > > aSeriesVector(
      71       11600 :                 ::chart::DiagramHelper::getDataSeriesFromDiagram( m_spChart2ModelContact->getChart2Diagram() ) );
      72             :             ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > >::const_iterator aIter =
      73       11600 :                     aSeriesVector.begin();
      74       34722 :             for( ; aIter != aSeriesVector.end(); ++aIter )
      75             :             {
      76       23328 :                 PROPERTYTYPE aCurValue = getValueFromSeries( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >::query( *aIter ) );
      77       23328 :                 if( !bHasDetectableInnerValue )
      78       10238 :                     rValue = aCurValue;
      79             :                 else
      80             :                 {
      81       13090 :                     if( rValue != aCurValue )
      82             :                     {
      83         206 :                         rHasAmbiguousValue = true;
      84         206 :                         break;
      85             :                     }
      86             :                     else
      87       12884 :                         rValue = aCurValue;
      88             :                 }
      89       23122 :                 bHasDetectableInnerValue = true;
      90       11600 :             }
      91             :         }
      92       11600 :         return bHasDetectableInnerValue;
      93             :     }
      94          16 :     void setInnerValue( PROPERTYTYPE aNewValue ) const
      95             :     {
      96          32 :         if( m_ePropertyType == DIAGRAM &&
      97          16 :             m_spChart2ModelContact.get() )
      98             :         {
      99             :             ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > > aSeriesVector(
     100          16 :                 ::chart::DiagramHelper::getDataSeriesFromDiagram( m_spChart2ModelContact->getChart2Diagram() ) );
     101             :             ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > >::const_iterator aIter =
     102          16 :                     aSeriesVector.begin();
     103          64 :             for( ; aIter != aSeriesVector.end(); ++aIter )
     104             :             {
     105          48 :                 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xSeriesPropertySet( *aIter, ::com::sun::star::uno::UNO_QUERY );
     106          48 :                 if( xSeriesPropertySet.is() )
     107             :                 {
     108          48 :                     setValueToSeries( xSeriesPropertySet, aNewValue );
     109             :                 }
     110          16 :             }
     111             :         }
     112          16 :     }
     113        2904 :     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        2904 :         PROPERTYTYPE aNewValue = PROPERTYTYPE();
     117        2904 :         if( ! (rOuterValue >>= aNewValue) )
     118           0 :             throw ::com::sun::star::lang::IllegalArgumentException( "statistic property requires different type", 0, 0 );
     119             : 
     120        2904 :         if( m_ePropertyType == DIAGRAM )
     121             :         {
     122         226 :             m_aOuterValue = rOuterValue;
     123             : 
     124         226 :             bool bHasAmbiguousValue = false;
     125         226 :             PROPERTYTYPE aOldValue = PROPERTYTYPE();
     126         226 :             if( detectInnerValue( aOldValue, bHasAmbiguousValue ) )
     127             :             {
     128          16 :                 if( bHasAmbiguousValue || aNewValue != aOldValue )
     129          16 :                     setInnerValue( aNewValue );
     130          20 :             }
     131             :         }
     132             :         else
     133             :         {
     134        2678 :             setValueToSeries( xInnerPropertySet, aNewValue );
     135          42 :         }
     136        2904 :     }
     137             : 
     138       41494 :     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       41494 :         if( m_ePropertyType == DIAGRAM )
     142             :         {
     143        9840 :             bool bHasAmbiguousValue = false;
     144        3292 :             PROPERTYTYPE aValue;
     145        9840 :             if( detectInnerValue( aValue, bHasAmbiguousValue ) )
     146             :             {
     147        8948 :                 if(bHasAmbiguousValue)
     148          48 :                     m_aOuterValue <<= m_aDefaultValue;
     149             :                 else
     150        8900 :                     m_aOuterValue <<= aValue;
     151             :             }
     152        9840 :             return m_aOuterValue;
     153             :         }
     154             :         else
     155             :         {
     156       31654 :             ::com::sun::star::uno::Any aRet( m_aDefaultValue );
     157       31654 :             aRet <<= getValueFromSeries( xInnerPropertySet );
     158       31654 :             return aRet;
     159             :         }
     160             :     }
     161             : 
     162       33224 :     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       33224 :         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