LCOV - code coverage report
Current view: top level - chart2/source/controller/chartapiwrapper - WrappedSplineProperties.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 83 104 79.8 %
Date: 2014-04-11 Functions: 14 14 100.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             : 
      20             : #include "WrappedSplineProperties.hxx"
      21             : #include "macros.hxx"
      22             : #include "FastPropertyIdRanges.hxx"
      23             : #include "DiagramHelper.hxx"
      24             : #include <unonames.hxx>
      25             : 
      26             : #include <com/sun/star/chart2/CurveStyle.hpp>
      27             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      28             : 
      29             : using namespace ::com::sun::star;
      30             : using ::com::sun::star::uno::Any;
      31             : using ::com::sun::star::uno::Reference;
      32             : using ::com::sun::star::uno::Sequence;
      33             : using ::com::sun::star::beans::Property;
      34             : 
      35             : namespace chart
      36             : {
      37             : namespace wrapper
      38             : {
      39             : 
      40             : //PROPERTYTYPE is the type of the outer property
      41             : 
      42             : template< typename PROPERTYTYPE >
      43             : class WrappedSplineProperty : public WrappedProperty
      44             : {
      45             : public:
      46         612 :     explicit WrappedSplineProperty( const OUString& rOuterName, const OUString& rInnerName
      47             :         , const ::com::sun::star::uno::Any& rDefaulValue
      48             :         , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
      49             :             : WrappedProperty(rOuterName,OUString())
      50             :             , m_spChart2ModelContact(spChart2ModelContact)
      51             :             , m_aOuterValue(rDefaulValue)
      52             :             , m_aDefaultValue(rDefaulValue)
      53         612 :             , m_aOwnInnerName(rInnerName)
      54             :     {
      55         612 :     }
      56         990 :     virtual ~WrappedSplineProperty() {};
      57             : 
      58        1050 :     bool detectInnerValue( PROPERTYTYPE& rValue, bool& rHasAmbiguousValue ) const
      59             :     {
      60        1050 :         bool bHasDetectableInnerValue = false;
      61        1050 :         rHasAmbiguousValue = false;
      62             :         Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType > > aChartTypes(
      63        1050 :             ::chart::DiagramHelper::getChartTypesFromDiagram( m_spChart2ModelContact->getChart2Diagram() ) );
      64        3223 :         for( sal_Int32 nN = aChartTypes.getLength(); nN--; )
      65             :         {
      66             :             try
      67             :             {
      68        1123 :                 uno::Reference<beans::XPropertySet> xChartTypePropertySet(aChartTypes[nN], uno::UNO_QUERY);
      69        1123 :                 if (!xChartTypePropertySet.is())
      70           0 :                     continue;
      71             : 
      72        1270 :                 Any aSingleValue = this->convertInnerToOuterValue( xChartTypePropertySet->getPropertyValue(m_aOwnInnerName) );
      73         147 :                 PROPERTYTYPE aCurValue = PROPERTYTYPE();
      74         147 :                 aSingleValue >>= aCurValue;
      75         147 :                 if( !bHasDetectableInnerValue )
      76         147 :                     rValue = aCurValue;
      77             :                 else
      78             :                 {
      79           0 :                     if( rValue != aCurValue )
      80             :                     {
      81           0 :                         rHasAmbiguousValue = true;
      82           0 :                         break;
      83             :                     }
      84             :                     else
      85           0 :                         rValue = aCurValue;
      86             :                 }
      87        1270 :                 bHasDetectableInnerValue = true;
      88             :             }
      89        1952 :             catch( uno::Exception & ex )
      90             :             {
      91             :                 //spline properties are not supported by all charttypes
      92             :                 //in that cases this exception is ok
      93         976 :                 ex.Context.is();//to have debug information without compilation warnings
      94             :             }
      95             :         }
      96        1050 :         return bHasDetectableInnerValue;
      97             :     }
      98          15 :     void setPropertyValue( const ::com::sun::star::uno::Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& /*xInnerPropertySet*/ ) const
      99             :                     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
     100             :     {
     101             :         PROPERTYTYPE aNewValue;
     102          15 :         if( ! (rOuterValue >>= aNewValue) )
     103           0 :             throw ::com::sun::star::lang::IllegalArgumentException( "spline property requires different type", 0, 0 );
     104             : 
     105          15 :         m_aOuterValue = rOuterValue;
     106             : 
     107          15 :         bool bHasAmbiguousValue = false;
     108          15 :         PROPERTYTYPE aOldValue = PROPERTYTYPE();
     109          15 :         if( detectInnerValue( aOldValue, bHasAmbiguousValue ) )
     110             :         {
     111          12 :             if( bHasAmbiguousValue || aNewValue != aOldValue )
     112             :             {
     113             :                 Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType > > aChartTypes(
     114          12 :                     ::chart::DiagramHelper::getChartTypesFromDiagram( m_spChart2ModelContact->getChart2Diagram() ) );
     115          36 :                 for( sal_Int32 nN = aChartTypes.getLength(); nN--; )
     116             :                 {
     117             :                     try
     118             :                     {
     119          12 :                         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xChartTypePropertySet( aChartTypes[nN], ::com::sun::star::uno::UNO_QUERY );
     120          12 :                         if( xChartTypePropertySet.is() )
     121             :                         {
     122          12 :                             xChartTypePropertySet->setPropertyValue(m_aOwnInnerName,this->convertOuterToInnerValue(uno::makeAny(aNewValue)));
     123          12 :                         }
     124             :                     }
     125           0 :                     catch( uno::Exception & ex )
     126             :                     {
     127             :                         //spline properties are not supported by all charttypes
     128             :                         //in that cases this exception is ok
     129           0 :                         ex.Context.is();//to have debug information without compilation warnings
     130             :                     }
     131          12 :                 }
     132             :             }
     133             :         }
     134          15 :     }
     135             : 
     136        1035 :     ::com::sun::star::uno::Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& /*xInnerPropertySet*/ ) const
     137             :                             throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
     138             :     {
     139        1035 :         bool bHasAmbiguousValue = false;
     140             :         PROPERTYTYPE aValue;
     141        1035 :         if( detectInnerValue( aValue, bHasAmbiguousValue ) )
     142             :         {
     143         135 :             m_aOuterValue <<= aValue;
     144             :         }
     145        1035 :         return m_aOuterValue;
     146             :     }
     147             : 
     148        1026 :     ::com::sun::star::uno::Any getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& /*xInnerPropertyState*/ ) const
     149             :                             throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
     150             :     {
     151        1026 :         return m_aDefaultValue;
     152             :     }
     153             : 
     154             : protected:
     155             :     ::boost::shared_ptr< Chart2ModelContact >   m_spChart2ModelContact;
     156             :     mutable ::com::sun::star::uno::Any     m_aOuterValue;
     157             :     ::com::sun::star::uno::Any             m_aDefaultValue;
     158             :     // this inner name is not set as inner name at the base class
     159             :     const OUString m_aOwnInnerName;
     160             : };
     161             : 
     162             : class WrappedSplineTypeProperty : public WrappedSplineProperty< sal_Int32 >
     163             : {
     164             : public:
     165             :     explicit WrappedSplineTypeProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact );
     166             :     virtual ~WrappedSplineTypeProperty();
     167             : 
     168             :     virtual ::com::sun::star::uno::Any convertInnerToOuterValue( const ::com::sun::star::uno::Any& rInnerValue ) const SAL_OVERRIDE;
     169             :     virtual ::com::sun::star::uno::Any convertOuterToInnerValue( const ::com::sun::star::uno::Any& rOuterValue ) const SAL_OVERRIDE;
     170             : };
     171             : 
     172             : namespace
     173             : {
     174             : enum
     175             : {
     176             :     //spline properties
     177             :       PROP_CHART_SPLINE_TYPE = FAST_PROPERTY_ID_START_CHART_SPLINE_PROP
     178             :     , PROP_CHART_SPLINE_ORDER
     179             :     , PROP_CHART_SPLINE_RESOLUTION
     180             : };
     181             : 
     182             : }//anonymous namespace
     183             : 
     184          12 : void WrappedSplineProperties::addProperties( ::std::vector< Property > & rOutProperties )
     185             : {
     186             :     rOutProperties.push_back(
     187             :         Property( CHART_UNONAME_SPLINE_TYPE,
     188             :                   PROP_CHART_SPLINE_TYPE,
     189          12 :                   ::getCppuType( reinterpret_cast< sal_Int32 * >(0)),
     190             :                   beans::PropertyAttribute::BOUND
     191             :                   | beans::PropertyAttribute::MAYBEDEFAULT
     192          24 :                   | beans::PropertyAttribute::MAYBEVOID ));
     193             :     rOutProperties.push_back(
     194             :         Property( CHART_UNONAME_SPLINE_ORDER,
     195             :                   PROP_CHART_SPLINE_ORDER,
     196          12 :                   ::getCppuType( reinterpret_cast< sal_Int32 * >(0)),
     197             :                   beans::PropertyAttribute::BOUND
     198             :                   | beans::PropertyAttribute::MAYBEDEFAULT
     199          24 :                   | beans::PropertyAttribute::MAYBEVOID ));
     200             :     rOutProperties.push_back(
     201             :         Property( CHART_UNONAME_SPLINE_RESOLUTION,
     202             :                   PROP_CHART_SPLINE_RESOLUTION,
     203          12 :                   ::getCppuType( reinterpret_cast< sal_Int32 * >(0)),
     204             :                   beans::PropertyAttribute::BOUND
     205             :                   | beans::PropertyAttribute::MAYBEDEFAULT
     206          24 :                   | beans::PropertyAttribute::MAYBEVOID ));
     207          12 : }
     208             : 
     209         204 : void WrappedSplineProperties::addWrappedProperties( std::vector< WrappedProperty* >& rList
     210             :                                     , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
     211             : {
     212         204 :     rList.push_back( new WrappedSplineTypeProperty( spChart2ModelContact ) );
     213             :     rList.push_back(
     214             :         new WrappedSplineProperty<sal_Int32>(
     215             :             CHART_UNONAME_SPLINE_ORDER, CHART_UNONAME_SPLINE_ORDER,
     216         204 :             uno::makeAny(sal_Int32(3)), spChart2ModelContact));
     217             :     rList.push_back(
     218             :         new WrappedSplineProperty<sal_Int32>(
     219             :             CHART_UNONAME_SPLINE_RESOLUTION, CHART_UNONAME_CURVE_RESOLUTION,
     220         204 :             uno::makeAny(sal_Int32(20)), spChart2ModelContact));
     221         204 : }
     222             : 
     223         204 : WrappedSplineTypeProperty::WrappedSplineTypeProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
     224         204 :     : WrappedSplineProperty<sal_Int32>(CHART_UNONAME_SPLINE_TYPE, CHART_UNONAME_CURVE_STYLE, uno::makeAny(sal_Int32(0)), spChart2ModelContact )
     225             : {
     226         204 : }
     227         396 : WrappedSplineTypeProperty::~WrappedSplineTypeProperty()
     228             : {
     229         396 : }
     230          63 : Any WrappedSplineTypeProperty::convertInnerToOuterValue( const Any& rInnerValue ) const
     231             : {
     232          63 :     chart2::CurveStyle aInnerValue = chart2::CurveStyle_LINES;
     233          63 :     rInnerValue >>= aInnerValue;
     234             : 
     235             :     sal_Int32 nOuterValue;
     236          63 :     switch (aInnerValue)
     237             :     {
     238             :         case chart2::CurveStyle_CUBIC_SPLINES:
     239           0 :             nOuterValue = 1;
     240           0 :             break;
     241             :         case chart2::CurveStyle_B_SPLINES:
     242           0 :             nOuterValue = 2;
     243           0 :             break;
     244             :         case chart2::CurveStyle_STEP_START:
     245           0 :             nOuterValue = 3;
     246           0 :             break;
     247             :         case chart2::CurveStyle_STEP_END:
     248           0 :             nOuterValue = 4;
     249           0 :             break;
     250             :         case chart2::CurveStyle_STEP_CENTER_X:
     251           0 :             nOuterValue = 5;
     252           0 :             break;
     253             :         case chart2::CurveStyle_STEP_CENTER_Y:
     254           0 :             nOuterValue = 6;
     255           0 :             break;
     256             :         default:
     257          63 :             nOuterValue = 0;
     258             :     }
     259             : 
     260          63 :     return uno::makeAny(nOuterValue);
     261             : }
     262          12 : Any WrappedSplineTypeProperty::convertOuterToInnerValue( const Any& rOuterValue ) const
     263             : {
     264          12 :     sal_Int32 nOuterValue=0;
     265          12 :     rOuterValue >>= nOuterValue;
     266             : 
     267             :     chart2::CurveStyle aInnerValue;
     268             : 
     269          12 :     switch (nOuterValue)
     270             :     {
     271             :         case 1:
     272           2 :             aInnerValue = chart2::CurveStyle_CUBIC_SPLINES;
     273           2 :             break;
     274             :         case 2:
     275           2 :             aInnerValue = chart2::CurveStyle_B_SPLINES;
     276           2 :             break;
     277             :         case 3:
     278           2 :             aInnerValue = chart2::CurveStyle_STEP_START;
     279           2 :             break;
     280             :         case 4:
     281           2 :             aInnerValue = chart2::CurveStyle_STEP_END;
     282           2 :             break;
     283             :         case 5:
     284           2 :             aInnerValue = chart2::CurveStyle_STEP_CENTER_X;
     285           2 :             break;
     286             :         case 6:
     287           2 :             aInnerValue = chart2::CurveStyle_STEP_CENTER_Y;
     288           2 :             break;
     289             :         default:
     290             :             SAL_WARN_IF(chart2::CurveStyle_LINES != 0, "chart2", "Unknown line style");
     291           0 :             aInnerValue = chart2::CurveStyle_LINES;
     292             :     }
     293             : 
     294          12 :     return uno::makeAny(aInnerValue);
     295             : }
     296             : 
     297             : } //namespace wrapper
     298             : } //namespace chart
     299             : 
     300             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10