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

Generated by: LCOV version 1.10