LCOV - code coverage report
Current view: top level - chart2/source/controller/chartapiwrapper - WrappedSplineProperties.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 85 104 81.7 %
Date: 2015-06-13 12:38:46 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         921 :     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         921 :             , m_aOwnInnerName(rInnerName)
      54             :     {
      55         921 :     }
      56        1535 :     virtual ~WrappedSplineProperty() {};
      57             : 
      58        1664 :     bool detectInnerValue( PROPERTYTYPE& rValue, bool& rHasAmbiguousValue ) const
      59             :     {
      60        1664 :         bool bHasDetectableInnerValue = false;
      61        1664 :         rHasAmbiguousValue = false;
      62             :         Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType > > aChartTypes(
      63        1664 :             ::chart::DiagramHelper::getChartTypesFromDiagram( m_spChart2ModelContact->getChart2Diagram() ) );
      64        5137 :         for( sal_Int32 nN = aChartTypes.getLength(); nN--; )
      65             :         {
      66             :             try
      67             :             {
      68        1809 :                 uno::Reference<beans::XPropertySet> xChartTypePropertySet(aChartTypes[nN], uno::UNO_QUERY);
      69        1809 :                 if (!xChartTypePropertySet.is())
      70           0 :                     continue;
      71             : 
      72        2174 :                 Any aSingleValue = this->convertInnerToOuterValue( xChartTypePropertySet->getPropertyValue(m_aOwnInnerName) );
      73         365 :                 PROPERTYTYPE aCurValue = PROPERTYTYPE();
      74         365 :                 aSingleValue >>= aCurValue;
      75         365 :                 if( !bHasDetectableInnerValue )
      76         365 :                     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        2174 :                 bHasDetectableInnerValue = true;
      88             :             }
      89        2888 :             catch( uno::Exception & ex )
      90             :             {
      91             :                 //spline properties are not supported by all charttypes
      92             :                 //in that cases this exception is ok
      93        1444 :                 ex.Context.is();//to have debug information without compilation warnings
      94             :             }
      95             :         }
      96        1664 :         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        1649 :     ::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        1649 :         bool bHasAmbiguousValue = false;
     140             :         PROPERTYTYPE aValue;
     141        1649 :         if( detectInnerValue( aValue, bHasAmbiguousValue ) )
     142             :         {
     143         353 :             m_aOuterValue <<= aValue;
     144             :         }
     145        1649 :         return m_aOuterValue;
     146             :     }
     147             : 
     148        1608 :     ::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        1608 :         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          14 : void WrappedSplineProperties::addProperties( ::std::vector< Property > & rOutProperties )
     185             : {
     186             :     rOutProperties.push_back(
     187             :         Property( CHART_UNONAME_SPLINE_TYPE,
     188             :                   PROP_CHART_SPLINE_TYPE,
     189          14 :                   cppu::UnoType<sal_Int32>::get(),
     190             :                   beans::PropertyAttribute::BOUND
     191             :                   | beans::PropertyAttribute::MAYBEDEFAULT
     192          28 :                   | beans::PropertyAttribute::MAYBEVOID ));
     193             :     rOutProperties.push_back(
     194             :         Property( CHART_UNONAME_SPLINE_ORDER,
     195             :                   PROP_CHART_SPLINE_ORDER,
     196          14 :                   cppu::UnoType<sal_Int32>::get(),
     197             :                   beans::PropertyAttribute::BOUND
     198             :                   | beans::PropertyAttribute::MAYBEDEFAULT
     199          28 :                   | beans::PropertyAttribute::MAYBEVOID ));
     200             :     rOutProperties.push_back(
     201             :         Property( CHART_UNONAME_SPLINE_RESOLUTION,
     202             :                   PROP_CHART_SPLINE_RESOLUTION,
     203          14 :                   cppu::UnoType<sal_Int32>::get(),
     204             :                   beans::PropertyAttribute::BOUND
     205             :                   | beans::PropertyAttribute::MAYBEDEFAULT
     206          28 :                   | beans::PropertyAttribute::MAYBEVOID ));
     207          14 : }
     208             : 
     209         307 : void WrappedSplineProperties::addWrappedProperties( std::vector< WrappedProperty* >& rList
     210             :                                     , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
     211             : {
     212         307 :     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         307 :             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         307 :             uno::makeAny(sal_Int32(20)), spChart2ModelContact));
     221         307 : }
     222             : 
     223         307 : WrappedSplineTypeProperty::WrappedSplineTypeProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
     224         307 :     : WrappedSplineProperty<sal_Int32>(CHART_UNONAME_SPLINE_TYPE, CHART_UNONAME_CURVE_STYLE, uno::makeAny(sal_Int32(0)), spChart2ModelContact )
     225             : {
     226         307 : }
     227         614 : WrappedSplineTypeProperty::~WrappedSplineTypeProperty()
     228             : {
     229         614 : }
     230         153 : Any WrappedSplineTypeProperty::convertInnerToOuterValue( const Any& rInnerValue ) const
     231             : {
     232         153 :     chart2::CurveStyle aInnerValue = chart2::CurveStyle_LINES;
     233         153 :     rInnerValue >>= aInnerValue;
     234             : 
     235             :     sal_Int32 nOuterValue;
     236         153 :     switch (aInnerValue)
     237             :     {
     238             :         case chart2::CurveStyle_CUBIC_SPLINES:
     239           2 :             nOuterValue = 1;
     240           2 :             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         151 :             nOuterValue = 0;
     258             :     }
     259             : 
     260         153 :     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.11