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

Generated by: LCOV version 1.10