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