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