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

Generated by: LCOV version 1.10