LCOV - code coverage report
Current view: top level - chart2/source/controller/chartapiwrapper - WrappedStockProperties.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 84 104 80.8 %
Date: 2012-08-25 Functions: 16 17 94.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 80 246 32.5 %

           Branch data     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                 :            : 
      21                 :            : #include "WrappedStockProperties.hxx"
      22                 :            : #include "macros.hxx"
      23                 :            : #include "FastPropertyIdRanges.hxx"
      24                 :            : #include "DiagramHelper.hxx"
      25                 :            : #include "ChartModelHelper.hxx"
      26                 :            : #include "ControllerLockGuard.hxx"
      27                 :            : #include <com/sun/star/chart2/XChartDocument.hpp>
      28                 :            : #include <com/sun/star/beans/PropertyAttribute.hpp>
      29                 :            : 
      30                 :            : using namespace ::com::sun::star;
      31                 :            : using ::com::sun::star::uno::Any;
      32                 :            : using ::com::sun::star::uno::Reference;
      33                 :            : using ::com::sun::star::uno::Sequence;
      34                 :            : using ::com::sun::star::beans::Property;
      35                 :            : using ::rtl::OUString;
      36                 :            : 
      37                 :            : //.............................................................................
      38                 :            : namespace chart
      39                 :            : {
      40                 :            : namespace wrapper
      41                 :            : {
      42                 :            : 
      43                 :            : //-----------------------------------------------------------------------------
      44                 :            : 
      45                 :            : class WrappedStockProperty : public WrappedProperty
      46                 :            : {
      47                 :            : public:
      48                 :            :     explicit WrappedStockProperty( const ::rtl::OUString& rOuterName
      49                 :            :         , const ::com::sun::star::uno::Any& rDefaulValue
      50                 :            :         , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact );
      51                 :            :     virtual ~WrappedStockProperty();
      52                 :            : 
      53                 :            :     void setPropertyValue( const ::com::sun::star::uno::Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
      54                 :            :                     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);
      55                 :            : 
      56                 :            :     ::com::sun::star::uno::Any getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& xInnerPropertyState ) const
      57                 :            :                             throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
      58                 :            : 
      59                 :            :     virtual uno::Reference< chart2::XChartTypeTemplate > getNewTemplate( sal_Bool bNewValue, const rtl::OUString& rCurrentTemplate, const Reference< lang::XMultiServiceFactory >& xFactory ) const = 0;
      60                 :            : 
      61                 :            : protected:
      62                 :            :     ::boost::shared_ptr< Chart2ModelContact >   m_spChart2ModelContact;
      63                 :            :     mutable ::com::sun::star::uno::Any     m_aOuterValue;
      64                 :            :     ::com::sun::star::uno::Any             m_aDefaultValue;
      65                 :            : };
      66                 :            : 
      67                 :         66 : WrappedStockProperty::WrappedStockProperty( const ::rtl::OUString& rOuterName
      68                 :            :     , const ::com::sun::star::uno::Any& rDefaulValue
      69                 :            :     , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
      70                 :            :     : WrappedProperty(rOuterName,rtl::OUString())
      71                 :            :         , m_spChart2ModelContact(spChart2ModelContact)
      72                 :            :         , m_aOuterValue()
      73 [ +  - ][ +  - ]:         66 :         , m_aDefaultValue(rDefaulValue)
      74                 :            : {
      75                 :         66 : }
      76         [ +  - ]:         66 : WrappedStockProperty::~WrappedStockProperty()
      77                 :            : {
      78         [ -  + ]:         66 : }
      79                 :            : 
      80                 :         12 : void WrappedStockProperty::setPropertyValue( const ::com::sun::star::uno::Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& /*xInnerPropertySet*/ ) const
      81                 :            :                 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)
      82                 :            : {
      83                 :         12 :     sal_Bool bNewValue = false;
      84         [ -  + ]:         12 :     if( ! (rOuterValue >>= bNewValue) )
      85 [ #  # ][ #  # ]:          0 :         throw lang::IllegalArgumentException( "stock properties require type sal_Bool", 0, 0 );
      86                 :            : 
      87                 :         12 :     m_aOuterValue = rOuterValue;
      88                 :            : 
      89         [ +  - ]:         12 :     Reference< chart2::XChartDocument > xChartDoc( m_spChart2ModelContact->getChart2Document() );
      90         [ +  - ]:         12 :     Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
      91         [ +  - ]:         12 :     sal_Int32 nDimension = ::chart::DiagramHelper::getDimension( xDiagram );
      92 [ +  - ][ +  - ]:         12 :     if( xChartDoc.is() && xDiagram.is() && nDimension==2 )
         [ +  - ][ +  - ]
      93                 :            :     {
      94 [ +  - ][ +  - ]:         12 :         Reference< lang::XMultiServiceFactory > xFactory( xChartDoc->getChartTypeManager(), uno::UNO_QUERY );
                 [ +  - ]
      95                 :            :         DiagramHelper::tTemplateWithServiceName aTemplateAndService =
      96         [ +  - ]:         12 :                 DiagramHelper::getTemplateForDiagram( xDiagram, xFactory );
      97                 :            : 
      98                 :            :         uno::Reference< chart2::XChartTypeTemplate > xTemplate =
      99         [ +  - ]:         12 :                 getNewTemplate( bNewValue, aTemplateAndService.second, xFactory );
     100                 :            : 
     101         [ -  + ]:         12 :         if(xTemplate.is())
     102                 :            :         {
     103                 :            :             try
     104                 :            :             {
     105                 :            :                 // locked controllers
     106 [ #  # ][ #  # ]:          0 :                 ControllerLockGuard aCtrlLockGuard( m_spChart2ModelContact->getChartModel() );
     107 [ #  # ][ #  # ]:          0 :                 xTemplate->changeDiagram( xDiagram );
         [ #  # ][ #  # ]
     108                 :            :             }
     109         [ #  # ]:          0 :             catch( const uno::Exception & ex )
     110                 :            :             {
     111                 :            :                 ASSERT_EXCEPTION( ex );
     112                 :            :             }
     113         [ +  - ]:         12 :         }
     114                 :         12 :     }
     115                 :         12 : }
     116                 :            : 
     117                 :         36 : ::com::sun::star::uno::Any WrappedStockProperty::getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& /*xInnerPropertyState*/ ) const
     118                 :            :                         throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
     119                 :            : {
     120                 :         36 :     return m_aDefaultValue;
     121                 :            : }
     122                 :            : 
     123                 :            : //-------------------------------------------------------------------------------------
     124                 :            : 
     125                 :            : class WrappedVolumeProperty : public WrappedStockProperty
     126                 :            : {
     127                 :            : public:
     128                 :            :     explicit WrappedVolumeProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact );
     129                 :            :     virtual ~WrappedVolumeProperty();
     130                 :            : 
     131                 :            :     ::com::sun::star::uno::Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
     132                 :            :                             throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
     133                 :            : 
     134                 :            :     uno::Reference< chart2::XChartTypeTemplate > getNewTemplate( sal_Bool bNewValue, const rtl::OUString& rCurrentTemplate, const Reference< lang::XMultiServiceFactory >& xFactory ) const;
     135                 :            : };
     136                 :            : 
     137                 :         33 : WrappedVolumeProperty::WrappedVolumeProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
     138 [ +  - ][ +  - ]:         33 :         : WrappedStockProperty( "Volume", uno::makeAny(sal_False) , spChart2ModelContact )
     139                 :            : {
     140                 :         33 : }
     141                 :         33 : WrappedVolumeProperty::~WrappedVolumeProperty()
     142                 :            : {
     143         [ -  + ]:         66 : }
     144                 :            : 
     145                 :         24 : ::com::sun::star::uno::Any WrappedVolumeProperty::getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& /*xInnerPropertySet*/ ) const
     146                 :            :                         throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
     147                 :            : {
     148         [ +  - ]:         24 :     Reference< chart2::XChartDocument > xChartDoc( m_spChart2ModelContact->getChart2Document() );
     149         [ +  - ]:         24 :     Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
     150 [ +  - ][ +  - ]:         24 :     if( xDiagram.is() && xChartDoc.is() )
                 [ +  - ]
     151                 :            :     {
     152                 :            :         ::std::vector< uno::Reference< chart2::XDataSeries > > aSeriesVector(
     153         [ +  - ]:         24 :             DiagramHelper::getDataSeriesFromDiagram( xDiagram ) );
     154         [ +  + ]:         24 :         if( aSeriesVector.size() > 0 )
     155                 :            :         {
     156 [ +  - ][ +  - ]:         18 :             Reference< lang::XMultiServiceFactory > xFact( xChartDoc->getChartTypeManager(), uno::UNO_QUERY );
                 [ +  - ]
     157                 :            :             DiagramHelper::tTemplateWithServiceName aTemplateAndService =
     158         [ +  - ]:         18 :                     DiagramHelper::getTemplateForDiagram( xDiagram, xFact );
     159                 :            : 
     160         [ -  + ]:         36 :             if(    aTemplateAndService.second == "com.sun.star.chart2.template.StockVolumeLowHighClose"
           [ +  -  -  + ]
     161                 :         18 :                 || aTemplateAndService.second == "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" )
     162         [ #  # ]:          0 :                 m_aOuterValue <<= sal_Bool(sal_True);
     163 [ -  + ][ #  # ]:         18 :             else if( !aTemplateAndService.second.isEmpty() || !m_aOuterValue.hasValue() )
                 [ +  - ]
     164 [ +  - ][ +  - ]:         18 :                 m_aOuterValue <<= sal_Bool(sal_False);
     165                 :            :         }
     166         [ -  + ]:          6 :         else if(!m_aOuterValue.hasValue())
     167         [ #  # ]:         24 :             m_aOuterValue <<= sal_Bool(sal_False);
     168                 :            :     }
     169                 :         24 :     return m_aOuterValue;
     170                 :            : }
     171                 :            : 
     172                 :          6 : uno::Reference< chart2::XChartTypeTemplate > WrappedVolumeProperty::getNewTemplate( sal_Bool bNewValue, const rtl::OUString& rCurrentTemplate, const Reference< lang::XMultiServiceFactory >& xFactory ) const
     173                 :            : {
     174                 :          6 :     uno::Reference< chart2::XChartTypeTemplate > xTemplate(0);
     175                 :            : 
     176         [ -  + ]:          6 :     if(!xFactory.is())
     177                 :          0 :         return xTemplate;
     178                 :            : 
     179         [ -  + ]:          6 :     if( bNewValue ) //add volume
     180                 :            :     {
     181         [ #  # ]:          0 :         if( rCurrentTemplate == "com.sun.star.chart2.template.StockLowHighClose" )
     182 [ #  # ][ #  # ]:          0 :             xTemplate.set( xFactory->createInstance( "com.sun.star.chart2.template.StockVolumeLowHighClose" ), uno::UNO_QUERY );
                 [ #  # ]
     183         [ #  # ]:          0 :         else if( rCurrentTemplate == "com.sun.star.chart2.template.StockOpenLowHighClose" )
     184 [ #  # ][ #  # ]:          0 :             xTemplate.set( xFactory->createInstance( "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" ), uno::UNO_QUERY );
                 [ #  # ]
     185                 :            :     }
     186                 :            :     else //remove volume
     187                 :            :     {
     188         [ -  + ]:          6 :         if( rCurrentTemplate == "com.sun.star.chart2.template.StockVolumeLowHighClose" )
     189 [ #  # ][ #  # ]:          0 :             xTemplate.set( xFactory->createInstance( "com.sun.star.chart2.template.StockLowHighClose" ), uno::UNO_QUERY );
                 [ #  # ]
     190         [ -  + ]:          6 :         else if( rCurrentTemplate == "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" )
     191 [ #  # ][ #  # ]:          0 :             xTemplate.set( xFactory->createInstance( "com.sun.star.chart2.template.StockOpenLowHighClose" ), uno::UNO_QUERY );
                 [ #  # ]
     192                 :            :     }
     193                 :          6 :     return xTemplate;
     194                 :            : }
     195                 :            : 
     196                 :            : //-------------------------------------------------------------------------------------
     197                 :            : 
     198                 :            : class WrappedUpDownProperty : public WrappedStockProperty
     199                 :            : {
     200                 :            : public:
     201                 :            :     explicit WrappedUpDownProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact );
     202                 :            :     virtual ~WrappedUpDownProperty();
     203                 :            : 
     204                 :            :     ::com::sun::star::uno::Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
     205                 :            :                             throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
     206                 :            : 
     207                 :            :     uno::Reference< chart2::XChartTypeTemplate > getNewTemplate( sal_Bool bNewValue, const rtl::OUString& rCurrentTemplate, const Reference< lang::XMultiServiceFactory >& xFactory ) const;
     208                 :            : };
     209                 :         33 : WrappedUpDownProperty::WrappedUpDownProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
     210 [ +  - ][ +  - ]:         33 :         : WrappedStockProperty( "UpDown", uno::makeAny(sal_False) , spChart2ModelContact )
     211                 :            : {
     212                 :         33 : }
     213                 :         33 : WrappedUpDownProperty::~WrappedUpDownProperty()
     214                 :            : {
     215         [ -  + ]:         66 : }
     216                 :         18 : ::com::sun::star::uno::Any WrappedUpDownProperty::getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& /*xInnerPropertySet*/ ) const
     217                 :            :                         throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
     218                 :            : {
     219         [ +  - ]:         18 :     Reference< chart2::XChartDocument > xChartDoc( m_spChart2ModelContact->getChart2Document() );
     220         [ +  - ]:         18 :     Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
     221 [ +  - ][ +  - ]:         18 :     if( xDiagram.is() && xChartDoc.is() )
                 [ +  - ]
     222                 :            :     {
     223                 :            :         ::std::vector< uno::Reference< chart2::XDataSeries > > aSeriesVector(
     224         [ +  - ]:         18 :             DiagramHelper::getDataSeriesFromDiagram( xDiagram ) );
     225         [ +  - ]:         18 :         if( aSeriesVector.size() > 0 )
     226                 :            :         {
     227 [ +  - ][ +  - ]:         18 :             Reference< lang::XMultiServiceFactory > xFact( xChartDoc->getChartTypeManager(), uno::UNO_QUERY );
                 [ +  - ]
     228                 :            :             DiagramHelper::tTemplateWithServiceName aTemplateAndService =
     229         [ +  - ]:         18 :                     DiagramHelper::getTemplateForDiagram( xDiagram, xFact );
     230                 :            : 
     231         [ -  + ]:         36 :             if(    aTemplateAndService.second == "com.sun.star.chart2.template.StockOpenLowHighClose"
           [ +  -  -  + ]
     232                 :         18 :                 || aTemplateAndService.second == "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" )
     233         [ #  # ]:          0 :                 m_aOuterValue <<= sal_Bool(sal_True);
     234 [ -  + ][ #  # ]:         18 :             else if( !aTemplateAndService.second.isEmpty() || !m_aOuterValue.hasValue() )
                 [ +  - ]
     235 [ +  - ][ +  - ]:         18 :                 m_aOuterValue <<= sal_Bool(sal_False);
     236                 :            :         }
     237         [ #  # ]:          0 :         else if(!m_aOuterValue.hasValue())
     238         [ #  # ]:         18 :             m_aOuterValue <<= sal_Bool(sal_False);
     239                 :            :     }
     240                 :         18 :     return m_aOuterValue;
     241                 :            : }
     242                 :          6 : uno::Reference< chart2::XChartTypeTemplate > WrappedUpDownProperty::getNewTemplate( sal_Bool bNewValue, const rtl::OUString& rCurrentTemplate, const Reference< lang::XMultiServiceFactory >& xFactory ) const
     243                 :            : {
     244                 :          6 :     uno::Reference< chart2::XChartTypeTemplate > xTemplate(0);
     245         [ -  + ]:          6 :     if( bNewValue ) //add open series
     246                 :            :     {
     247         [ #  # ]:          0 :         if( rCurrentTemplate == "com.sun.star.chart2.template.StockLowHighClose" )
     248 [ #  # ][ #  # ]:          0 :             xTemplate.set( xFactory->createInstance( "com.sun.star.chart2.template.StockOpenLowHighClose" ), uno::UNO_QUERY );
                 [ #  # ]
     249         [ #  # ]:          0 :         else if( rCurrentTemplate == "com.sun.star.chart2.template.StockVolumeLowHighClose" )
     250 [ #  # ][ #  # ]:          0 :             xTemplate.set( xFactory->createInstance( "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" ), uno::UNO_QUERY );
                 [ #  # ]
     251                 :            :     }
     252                 :            :     else //remove open series
     253                 :            :     {
     254         [ -  + ]:          6 :         if( rCurrentTemplate == "com.sun.star.chart2.template.StockOpenLowHighClose" )
     255 [ #  # ][ #  # ]:          0 :             xTemplate.set( xFactory->createInstance( "com.sun.star.chart2.template.StockLowHighClose" ), uno::UNO_QUERY );
                 [ #  # ]
     256         [ -  + ]:          6 :         else if( rCurrentTemplate == "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" )
     257 [ #  # ][ #  # ]:          0 :             xTemplate.set( xFactory->createInstance( "com.sun.star.chart2.template.StockVolumeLowHighClose" ), uno::UNO_QUERY );
                 [ #  # ]
     258                 :            :     }
     259                 :          6 :     return xTemplate;
     260                 :            : }
     261                 :            : 
     262                 :            : namespace
     263                 :            : {
     264                 :            : enum
     265                 :            : {
     266                 :            :     //spline properties
     267                 :            :       PROP_CHART_STOCK_VOLUME = FAST_PROPERTY_ID_START_CHART_STOCK_PROP
     268                 :            :     , PROP_CHART_STOCK_UPDOWN
     269                 :            : };
     270                 :            : 
     271                 :            : }//anonymous namespace
     272                 :            : 
     273                 :            : //-----------------------------------------------------------------------------
     274                 :         10 : void WrappedStockProperties::addProperties( ::std::vector< Property > & rOutProperties )
     275                 :            : {
     276                 :            :     rOutProperties.push_back(
     277                 :            :         Property( "Volume",
     278                 :            :                   PROP_CHART_STOCK_VOLUME,
     279         [ +  - ]:         10 :                   ::getCppuType( reinterpret_cast< sal_Bool * >(0)),
     280                 :            :                   beans::PropertyAttribute::BOUND
     281                 :            :                   | beans::PropertyAttribute::MAYBEDEFAULT
     282         [ +  - ]:         10 :                   | beans::PropertyAttribute::MAYBEVOID ));
     283                 :            :     rOutProperties.push_back(
     284                 :            :         Property( "UpDown",
     285                 :            :                   PROP_CHART_STOCK_UPDOWN,
     286         [ +  - ]:         10 :                   ::getCppuType( reinterpret_cast< sal_Bool * >(0)),
     287                 :            :                   beans::PropertyAttribute::BOUND
     288                 :            :                   | beans::PropertyAttribute::MAYBEDEFAULT
     289         [ +  - ]:         10 :                   | beans::PropertyAttribute::MAYBEVOID ));
     290                 :         10 : }
     291                 :            : 
     292                 :            : //-----------------------------------------------------------------------------
     293                 :         33 : void WrappedStockProperties::addWrappedProperties( std::vector< WrappedProperty* >& rList
     294                 :            :                                     , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
     295                 :            : {
     296 [ +  - ][ +  - ]:         33 :     rList.push_back( new WrappedVolumeProperty( spChart2ModelContact ) );
                 [ +  - ]
     297 [ +  - ][ +  - ]:         33 :     rList.push_back( new WrappedUpDownProperty( spChart2ModelContact ) );
                 [ +  - ]
     298                 :         33 : }
     299                 :            : 
     300                 :            : } //namespace wrapper
     301                 :            : } //namespace chart
     302                 :            : //.............................................................................
     303                 :            : 
     304                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10