LCOV - code coverage report
Current view: top level - chart2/source/controller/chartapiwrapper - WrappedStockProperties.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 89 104 85.6 %
Date: 2014-04-11 Functions: 16 17 94.1 %
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( sal_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         408 : 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         408 :         , m_aDefaultValue(rDefaulValue)
      69             : {
      70         408 : }
      71         396 : WrappedStockProperty::~WrappedStockProperty()
      72             : {
      73         396 : }
      74             : 
      75           8 : 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           8 :     sal_Bool bNewValue = false;
      79           8 :     if( ! (rOuterValue >>= bNewValue) )
      80           0 :         throw lang::IllegalArgumentException( "stock properties require type sal_Bool", 0, 0 );
      81             : 
      82           8 :     m_aOuterValue = rOuterValue;
      83             : 
      84           8 :     Reference< chart2::XChartDocument > xChartDoc( m_spChart2ModelContact->getChart2Document() );
      85          16 :     Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
      86           8 :     sal_Int32 nDimension = ::chart::DiagramHelper::getDimension( xDiagram );
      87           8 :     if( xChartDoc.is() && xDiagram.is() && nDimension==2 )
      88             :     {
      89           8 :         Reference< lang::XMultiServiceFactory > xFactory( xChartDoc->getChartTypeManager(), uno::UNO_QUERY );
      90             :         DiagramHelper::tTemplateWithServiceName aTemplateAndService =
      91          16 :                 DiagramHelper::getTemplateForDiagram( xDiagram, xFactory );
      92             : 
      93             :         uno::Reference< chart2::XChartTypeTemplate > xTemplate =
      94          16 :                 getNewTemplate( bNewValue, aTemplateAndService.second, xFactory );
      95             : 
      96           8 :         if(xTemplate.is())
      97             :         {
      98             :             try
      99             :             {
     100             :                 // locked controllers
     101           2 :                 ControllerLockGuardUNO aCtrlLockGuard( m_spChart2ModelContact->getChartModel() );
     102           2 :                 xTemplate->changeDiagram( xDiagram );
     103             :             }
     104           0 :             catch( const uno::Exception & ex )
     105             :             {
     106             :                 ASSERT_EXCEPTION( ex );
     107             :             }
     108           8 :         }
     109           8 :     }
     110           8 : }
     111             : 
     112         684 : ::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         684 :     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( sal_Bool bNewValue, const OUString& rCurrentTemplate, const Reference< lang::XMultiServiceFactory >& xFactory ) const SAL_OVERRIDE;
     128             : };
     129             : 
     130         204 : WrappedVolumeProperty::WrappedVolumeProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
     131         204 :         : WrappedStockProperty( "Volume", uno::makeAny(sal_False) , spChart2ModelContact )
     132             : {
     133         204 : }
     134         396 : WrappedVolumeProperty::~WrappedVolumeProperty()
     135             : {
     136         396 : }
     137             : 
     138         437 : ::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         437 :     Reference< chart2::XChartDocument > xChartDoc( m_spChart2ModelContact->getChart2Document() );
     142         874 :     Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
     143         437 :     if( xDiagram.is() && xChartDoc.is() )
     144             :     {
     145             :         ::std::vector< uno::Reference< chart2::XDataSeries > > aSeriesVector(
     146         437 :             DiagramHelper::getDataSeriesFromDiagram( xDiagram ) );
     147         437 :         if( aSeriesVector.size() > 0 )
     148             :         {
     149         354 :             Reference< lang::XMultiServiceFactory > xFact( xChartDoc->getChartTypeManager(), uno::UNO_QUERY );
     150             :             DiagramHelper::tTemplateWithServiceName aTemplateAndService =
     151         708 :                     DiagramHelper::getTemplateForDiagram( xDiagram, xFact );
     152             : 
     153         708 :             if(    aTemplateAndService.second == "com.sun.star.chart2.template.StockVolumeLowHighClose"
     154         354 :                 || aTemplateAndService.second == "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" )
     155          24 :                 m_aOuterValue <<= sal_Bool(sal_True);
     156         330 :             else if( !aTemplateAndService.second.isEmpty() || !m_aOuterValue.hasValue() )
     157         684 :                 m_aOuterValue <<= sal_Bool(sal_False);
     158             :         }
     159          83 :         else if(!m_aOuterValue.hasValue())
     160          80 :             m_aOuterValue <<= sal_Bool(sal_False);
     161             :     }
     162         874 :     return m_aOuterValue;
     163             : }
     164             : 
     165           3 : uno::Reference< chart2::XChartTypeTemplate > WrappedVolumeProperty::getNewTemplate( sal_Bool bNewValue, const OUString& rCurrentTemplate, const Reference< lang::XMultiServiceFactory >& xFactory ) const
     166             : {
     167           3 :     uno::Reference< chart2::XChartTypeTemplate > xTemplate(0);
     168             : 
     169           3 :     if(!xFactory.is())
     170           0 :         return xTemplate;
     171             : 
     172           3 :     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           3 :         if( rCurrentTemplate == "com.sun.star.chart2.template.StockVolumeLowHighClose" )
     182           0 :             xTemplate.set( xFactory->createInstance( "com.sun.star.chart2.template.StockLowHighClose" ), uno::UNO_QUERY );
     183           3 :         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           3 :     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( sal_Bool bNewValue, const OUString& rCurrentTemplate, const Reference< lang::XMultiServiceFactory >& xFactory ) const SAL_OVERRIDE;
     199             : };
     200         204 : WrappedUpDownProperty::WrappedUpDownProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
     201         204 :         : WrappedStockProperty( "UpDown", uno::makeAny(sal_False) , spChart2ModelContact )
     202             : {
     203         204 : }
     204         396 : WrappedUpDownProperty::~WrappedUpDownProperty()
     205             : {
     206         396 : }
     207         354 : ::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         354 :     Reference< chart2::XChartDocument > xChartDoc( m_spChart2ModelContact->getChart2Document() );
     211         708 :     Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
     212         354 :     if( xDiagram.is() && xChartDoc.is() )
     213             :     {
     214             :         ::std::vector< uno::Reference< chart2::XDataSeries > > aSeriesVector(
     215         354 :             DiagramHelper::getDataSeriesFromDiagram( xDiagram ) );
     216         354 :         if( aSeriesVector.size() > 0 )
     217             :         {
     218         354 :             Reference< lang::XMultiServiceFactory > xFact( xChartDoc->getChartTypeManager(), uno::UNO_QUERY );
     219             :             DiagramHelper::tTemplateWithServiceName aTemplateAndService =
     220         708 :                     DiagramHelper::getTemplateForDiagram( xDiagram, xFact );
     221             : 
     222         708 :             if(    aTemplateAndService.second == "com.sun.star.chart2.template.StockOpenLowHighClose"
     223         354 :                 || aTemplateAndService.second == "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" )
     224          24 :                 m_aOuterValue <<= sal_Bool(sal_True);
     225         330 :             else if( !aTemplateAndService.second.isEmpty() || !m_aOuterValue.hasValue() )
     226         684 :                 m_aOuterValue <<= sal_Bool(sal_False);
     227             :         }
     228           0 :         else if(!m_aOuterValue.hasValue())
     229           0 :             m_aOuterValue <<= sal_Bool(sal_False);
     230             :     }
     231         708 :     return m_aOuterValue;
     232             : }
     233           5 : uno::Reference< chart2::XChartTypeTemplate > WrappedUpDownProperty::getNewTemplate( sal_Bool bNewValue, const OUString& rCurrentTemplate, const Reference< lang::XMultiServiceFactory >& xFactory ) const
     234             : {
     235           5 :     uno::Reference< chart2::XChartTypeTemplate > xTemplate(0);
     236           5 :     if( bNewValue ) //add open series
     237             :     {
     238           2 :         if( rCurrentTemplate == "com.sun.star.chart2.template.StockLowHighClose" )
     239           2 :             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           3 :         if( rCurrentTemplate == "com.sun.star.chart2.template.StockOpenLowHighClose" )
     246           0 :             xTemplate.set( xFactory->createInstance( "com.sun.star.chart2.template.StockLowHighClose" ), uno::UNO_QUERY );
     247           3 :         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           5 :     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          12 : void WrappedStockProperties::addProperties( ::std::vector< Property > & rOutProperties )
     265             : {
     266             :     rOutProperties.push_back(
     267             :         Property( "Volume",
     268             :                   PROP_CHART_STOCK_VOLUME,
     269          12 :                   ::getCppuType( reinterpret_cast< sal_Bool * >(0)),
     270             :                   beans::PropertyAttribute::BOUND
     271             :                   | beans::PropertyAttribute::MAYBEDEFAULT
     272          24 :                   | beans::PropertyAttribute::MAYBEVOID ));
     273             :     rOutProperties.push_back(
     274             :         Property( "UpDown",
     275             :                   PROP_CHART_STOCK_UPDOWN,
     276          12 :                   ::getCppuType( reinterpret_cast< sal_Bool * >(0)),
     277             :                   beans::PropertyAttribute::BOUND
     278             :                   | beans::PropertyAttribute::MAYBEDEFAULT
     279          24 :                   | beans::PropertyAttribute::MAYBEVOID ));
     280          12 : }
     281             : 
     282         204 : void WrappedStockProperties::addWrappedProperties( std::vector< WrappedProperty* >& rList
     283             :                                     , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
     284             : {
     285         204 :     rList.push_back( new WrappedVolumeProperty( spChart2ModelContact ) );
     286         204 :     rList.push_back( new WrappedUpDownProperty( spChart2ModelContact ) );
     287         204 : }
     288             : 
     289             : } //namespace wrapper
     290             : } //namespace chart
     291             : 
     292             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10