LCOV - code coverage report
Current view: top level - chart2/source/controller/chartapiwrapper - WrappedSplineProperties.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 84 105 80.0 %
Date: 2014-11-03 Functions: 16 16 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        1740 :     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        1740 :             , m_aOwnInnerName(rInnerName)
      54             :     {
      55        1740 :     }
      56        2900 :     virtual ~WrappedSplineProperty() {};
      57             : 
      58        3338 :     bool detectInnerValue( PROPERTYTYPE& rValue, bool& rHasAmbiguousValue ) const
      59             :     {
      60        3338 :         bool bHasDetectableInnerValue = false;
      61        3338 :         rHasAmbiguousValue = false;
      62             :         Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType > > aChartTypes(
      63        3338 :             ::chart::DiagramHelper::getChartTypesFromDiagram( m_spChart2ModelContact->getChart2Diagram() ) );
      64       10268 :         for( sal_Int32 nN = aChartTypes.getLength(); nN--; )
      65             :         {
      66             :             try
      67             :             {
      68        3592 :                 uno::Reference<beans::XPropertySet> xChartTypePropertySet(aChartTypes[nN], uno::UNO_QUERY);
      69        3592 :                 if (!xChartTypePropertySet.is())
      70           0 :                     continue;
      71             : 
      72        4368 :                 Any aSingleValue = this->convertInnerToOuterValue( xChartTypePropertySet->getPropertyValue(m_aOwnInnerName) );
      73         776 :                 PROPERTYTYPE aCurValue = PROPERTYTYPE();
      74         776 :                 aSingleValue >>= aCurValue;
      75         776 :                 if( !bHasDetectableInnerValue )
      76         776 :                     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        4368 :                 bHasDetectableInnerValue = true;
      88             :             }
      89        5632 :             catch( uno::Exception & ex )
      90             :             {
      91             :                 //spline properties are not supported by all charttypes
      92             :                 //in that cases this exception is ok
      93        2816 :                 ex.Context.is();//to have debug information without compilation warnings
      94             :             }
      95             :         }
      96        3338 :         return bHasDetectableInnerValue;
      97             :     }
      98          30 :     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          30 :         if( ! (rOuterValue >>= aNewValue) )
     103           0 :             throw ::com::sun::star::lang::IllegalArgumentException( "spline property requires different type", 0, 0 );
     104             : 
     105          30 :         m_aOuterValue = rOuterValue;
     106             : 
     107          30 :         bool bHasAmbiguousValue = false;
     108          30 :         PROPERTYTYPE aOldValue = PROPERTYTYPE();
     109          30 :         if( detectInnerValue( aOldValue, bHasAmbiguousValue ) )
     110             :         {
     111          24 :             if( bHasAmbiguousValue || aNewValue != aOldValue )
     112             :             {
     113             :                 Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType > > aChartTypes(
     114          24 :                     ::chart::DiagramHelper::getChartTypesFromDiagram( m_spChart2ModelContact->getChart2Diagram() ) );
     115          72 :                 for( sal_Int32 nN = aChartTypes.getLength(); nN--; )
     116             :                 {
     117             :                     try
     118             :                     {
     119          24 :                         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xChartTypePropertySet( aChartTypes[nN], ::com::sun::star::uno::UNO_QUERY );
     120          24 :                         if( xChartTypePropertySet.is() )
     121             :                         {
     122          24 :                             xChartTypePropertySet->setPropertyValue(m_aOwnInnerName,this->convertOuterToInnerValue(uno::makeAny(aNewValue)));
     123          24 :                         }
     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          24 :                 }
     132             :             }
     133             :         }
     134          30 :     }
     135             : 
     136        3308 :     ::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        3308 :         bool bHasAmbiguousValue = false;
     140             :         PROPERTYTYPE aValue;
     141        3308 :         if( detectInnerValue( aValue, bHasAmbiguousValue ) )
     142             :         {
     143         752 :             m_aOuterValue <<= aValue;
     144             :         }
     145        3308 :         return m_aOuterValue;
     146             :     }
     147             : 
     148        3216 :     ::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        3216 :         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          28 : void WrappedSplineProperties::addProperties( ::std::vector< Property > & rOutProperties )
     185             : {
     186             :     rOutProperties.push_back(
     187             :         Property( CHART_UNONAME_SPLINE_TYPE,
     188             :                   PROP_CHART_SPLINE_TYPE,
     189          28 :                   cppu::UnoType<sal_Int32>::get(),
     190             :                   beans::PropertyAttribute::BOUND
     191             :                   | beans::PropertyAttribute::MAYBEDEFAULT
     192          56 :                   | beans::PropertyAttribute::MAYBEVOID ));
     193             :     rOutProperties.push_back(
     194             :         Property( CHART_UNONAME_SPLINE_ORDER,
     195             :                   PROP_CHART_SPLINE_ORDER,
     196          28 :                   cppu::UnoType<sal_Int32>::get(),
     197             :                   beans::PropertyAttribute::BOUND
     198             :                   | beans::PropertyAttribute::MAYBEDEFAULT
     199          56 :                   | beans::PropertyAttribute::MAYBEVOID ));
     200             :     rOutProperties.push_back(
     201             :         Property( CHART_UNONAME_SPLINE_RESOLUTION,
     202             :                   PROP_CHART_SPLINE_RESOLUTION,
     203          28 :                   cppu::UnoType<sal_Int32>::get(),
     204             :                   beans::PropertyAttribute::BOUND
     205             :                   | beans::PropertyAttribute::MAYBEDEFAULT
     206          56 :                   | beans::PropertyAttribute::MAYBEVOID ));
     207          28 : }
     208             : 
     209         580 : void WrappedSplineProperties::addWrappedProperties( std::vector< WrappedProperty* >& rList
     210             :                                     , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
     211             : {
     212         580 :     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         580 :             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         580 :             uno::makeAny(sal_Int32(20)), spChart2ModelContact));
     221         580 : }
     222             : 
     223         580 : WrappedSplineTypeProperty::WrappedSplineTypeProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
     224         580 :     : WrappedSplineProperty<sal_Int32>(CHART_UNONAME_SPLINE_TYPE, CHART_UNONAME_CURVE_STYLE, uno::makeAny(sal_Int32(0)), spChart2ModelContact )
     225             : {
     226         580 : }
     227        1160 : WrappedSplineTypeProperty::~WrappedSplineTypeProperty()
     228             : {
     229        1160 : }
     230         304 : Any WrappedSplineTypeProperty::convertInnerToOuterValue( const Any& rInnerValue ) const
     231             : {
     232         304 :     chart2::CurveStyle aInnerValue = chart2::CurveStyle_LINES;
     233         304 :     rInnerValue >>= aInnerValue;
     234             : 
     235             :     sal_Int32 nOuterValue;
     236         304 :     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         304 :             nOuterValue = 0;
     258             :     }
     259             : 
     260         304 :     return uno::makeAny(nOuterValue);
     261             : }
     262          24 : Any WrappedSplineTypeProperty::convertOuterToInnerValue( const Any& rOuterValue ) const
     263             : {
     264          24 :     sal_Int32 nOuterValue=0;
     265          24 :     rOuterValue >>= nOuterValue;
     266             : 
     267             :     chart2::CurveStyle aInnerValue;
     268             : 
     269          24 :     switch (nOuterValue)
     270             :     {
     271             :         case 1:
     272           4 :             aInnerValue = chart2::CurveStyle_CUBIC_SPLINES;
     273           4 :             break;
     274             :         case 2:
     275           4 :             aInnerValue = chart2::CurveStyle_B_SPLINES;
     276           4 :             break;
     277             :         case 3:
     278           4 :             aInnerValue = chart2::CurveStyle_STEP_START;
     279           4 :             break;
     280             :         case 4:
     281           4 :             aInnerValue = chart2::CurveStyle_STEP_END;
     282           4 :             break;
     283             :         case 5:
     284           4 :             aInnerValue = chart2::CurveStyle_STEP_CENTER_X;
     285           4 :             break;
     286             :         case 6:
     287           4 :             aInnerValue = chart2::CurveStyle_STEP_CENTER_Y;
     288           4 :             break;
     289             :         default:
     290             :             SAL_WARN_IF(chart2::CurveStyle_LINES != 0, "chart2", "Unknown line style");
     291           0 :             aInnerValue = chart2::CurveStyle_LINES;
     292             :     }
     293             : 
     294          24 :     return uno::makeAny(aInnerValue);
     295             : }
     296             : 
     297             : } //namespace wrapper
     298         102 : } //namespace chart
     299             : 
     300             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10