LCOV - code coverage report
Current view: top level - libreoffice/chart2/source/controller/chartapiwrapper - WrappedStockProperties.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 25 104 24.0 %
Date: 2012-12-27 Functions: 10 17 58.8 %
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             : 
      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          80 : 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          80 :         , m_aDefaultValue(rDefaulValue)
      74             : {
      75          80 : }
      76          80 : WrappedStockProperty::~WrappedStockProperty()
      77             : {
      78          80 : }
      79             : 
      80           0 : 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           0 :     sal_Bool bNewValue = false;
      84           0 :     if( ! (rOuterValue >>= bNewValue) )
      85           0 :         throw lang::IllegalArgumentException( "stock properties require type sal_Bool", 0, 0 );
      86             : 
      87           0 :     m_aOuterValue = rOuterValue;
      88             : 
      89           0 :     Reference< chart2::XChartDocument > xChartDoc( m_spChart2ModelContact->getChart2Document() );
      90           0 :     Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
      91           0 :     sal_Int32 nDimension = ::chart::DiagramHelper::getDimension( xDiagram );
      92           0 :     if( xChartDoc.is() && xDiagram.is() && nDimension==2 )
      93             :     {
      94           0 :         Reference< lang::XMultiServiceFactory > xFactory( xChartDoc->getChartTypeManager(), uno::UNO_QUERY );
      95             :         DiagramHelper::tTemplateWithServiceName aTemplateAndService =
      96           0 :                 DiagramHelper::getTemplateForDiagram( xDiagram, xFactory );
      97             : 
      98             :         uno::Reference< chart2::XChartTypeTemplate > xTemplate =
      99           0 :                 getNewTemplate( bNewValue, aTemplateAndService.second, xFactory );
     100             : 
     101           0 :         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           0 :         }
     114           0 :     }
     115           0 : }
     116             : 
     117           0 : ::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           0 :     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          40 : WrappedVolumeProperty::WrappedVolumeProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
     138          40 :         : WrappedStockProperty( "Volume", uno::makeAny(sal_False) , spChart2ModelContact )
     139             : {
     140          40 : }
     141          80 : WrappedVolumeProperty::~WrappedVolumeProperty()
     142             : {
     143          80 : }
     144             : 
     145           0 : ::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           0 :     Reference< chart2::XChartDocument > xChartDoc( m_spChart2ModelContact->getChart2Document() );
     149           0 :     Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
     150           0 :     if( xDiagram.is() && xChartDoc.is() )
     151             :     {
     152             :         ::std::vector< uno::Reference< chart2::XDataSeries > > aSeriesVector(
     153           0 :             DiagramHelper::getDataSeriesFromDiagram( xDiagram ) );
     154           0 :         if( aSeriesVector.size() > 0 )
     155             :         {
     156           0 :             Reference< lang::XMultiServiceFactory > xFact( xChartDoc->getChartTypeManager(), uno::UNO_QUERY );
     157             :             DiagramHelper::tTemplateWithServiceName aTemplateAndService =
     158           0 :                     DiagramHelper::getTemplateForDiagram( xDiagram, xFact );
     159             : 
     160           0 :             if(    aTemplateAndService.second == "com.sun.star.chart2.template.StockVolumeLowHighClose"
     161           0 :                 || aTemplateAndService.second == "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" )
     162           0 :                 m_aOuterValue <<= sal_Bool(sal_True);
     163           0 :             else if( !aTemplateAndService.second.isEmpty() || !m_aOuterValue.hasValue() )
     164           0 :                 m_aOuterValue <<= sal_Bool(sal_False);
     165             :         }
     166           0 :         else if(!m_aOuterValue.hasValue())
     167           0 :             m_aOuterValue <<= sal_Bool(sal_False);
     168             :     }
     169           0 :     return m_aOuterValue;
     170             : }
     171             : 
     172           0 : uno::Reference< chart2::XChartTypeTemplate > WrappedVolumeProperty::getNewTemplate( sal_Bool bNewValue, const rtl::OUString& rCurrentTemplate, const Reference< lang::XMultiServiceFactory >& xFactory ) const
     173             : {
     174           0 :     uno::Reference< chart2::XChartTypeTemplate > xTemplate(0);
     175             : 
     176           0 :     if(!xFactory.is())
     177           0 :         return xTemplate;
     178             : 
     179           0 :     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           0 :         if( rCurrentTemplate == "com.sun.star.chart2.template.StockVolumeLowHighClose" )
     189           0 :             xTemplate.set( xFactory->createInstance( "com.sun.star.chart2.template.StockLowHighClose" ), uno::UNO_QUERY );
     190           0 :         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           0 :     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          40 : WrappedUpDownProperty::WrappedUpDownProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
     210          40 :         : WrappedStockProperty( "UpDown", uno::makeAny(sal_False) , spChart2ModelContact )
     211             : {
     212          40 : }
     213          80 : WrappedUpDownProperty::~WrappedUpDownProperty()
     214             : {
     215          80 : }
     216           0 : ::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           0 :     Reference< chart2::XChartDocument > xChartDoc( m_spChart2ModelContact->getChart2Document() );
     220           0 :     Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
     221           0 :     if( xDiagram.is() && xChartDoc.is() )
     222             :     {
     223             :         ::std::vector< uno::Reference< chart2::XDataSeries > > aSeriesVector(
     224           0 :             DiagramHelper::getDataSeriesFromDiagram( xDiagram ) );
     225           0 :         if( aSeriesVector.size() > 0 )
     226             :         {
     227           0 :             Reference< lang::XMultiServiceFactory > xFact( xChartDoc->getChartTypeManager(), uno::UNO_QUERY );
     228             :             DiagramHelper::tTemplateWithServiceName aTemplateAndService =
     229           0 :                     DiagramHelper::getTemplateForDiagram( xDiagram, xFact );
     230             : 
     231           0 :             if(    aTemplateAndService.second == "com.sun.star.chart2.template.StockOpenLowHighClose"
     232           0 :                 || aTemplateAndService.second == "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" )
     233           0 :                 m_aOuterValue <<= sal_Bool(sal_True);
     234           0 :             else if( !aTemplateAndService.second.isEmpty() || !m_aOuterValue.hasValue() )
     235           0 :                 m_aOuterValue <<= sal_Bool(sal_False);
     236             :         }
     237           0 :         else if(!m_aOuterValue.hasValue())
     238           0 :             m_aOuterValue <<= sal_Bool(sal_False);
     239             :     }
     240           0 :     return m_aOuterValue;
     241             : }
     242           0 : uno::Reference< chart2::XChartTypeTemplate > WrappedUpDownProperty::getNewTemplate( sal_Bool bNewValue, const rtl::OUString& rCurrentTemplate, const Reference< lang::XMultiServiceFactory >& xFactory ) const
     243             : {
     244           0 :     uno::Reference< chart2::XChartTypeTemplate > xTemplate(0);
     245           0 :     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           0 :         if( rCurrentTemplate == "com.sun.star.chart2.template.StockOpenLowHighClose" )
     255           0 :             xTemplate.set( xFactory->createInstance( "com.sun.star.chart2.template.StockLowHighClose" ), uno::UNO_QUERY );
     256           0 :         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           0 :     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           1 : void WrappedStockProperties::addProperties( ::std::vector< Property > & rOutProperties )
     275             : {
     276             :     rOutProperties.push_back(
     277             :         Property( "Volume",
     278             :                   PROP_CHART_STOCK_VOLUME,
     279           1 :                   ::getCppuType( reinterpret_cast< sal_Bool * >(0)),
     280             :                   beans::PropertyAttribute::BOUND
     281             :                   | beans::PropertyAttribute::MAYBEDEFAULT
     282           2 :                   | beans::PropertyAttribute::MAYBEVOID ));
     283             :     rOutProperties.push_back(
     284             :         Property( "UpDown",
     285             :                   PROP_CHART_STOCK_UPDOWN,
     286           1 :                   ::getCppuType( reinterpret_cast< sal_Bool * >(0)),
     287             :                   beans::PropertyAttribute::BOUND
     288             :                   | beans::PropertyAttribute::MAYBEDEFAULT
     289           2 :                   | beans::PropertyAttribute::MAYBEVOID ));
     290           1 : }
     291             : 
     292             : //-----------------------------------------------------------------------------
     293          40 : void WrappedStockProperties::addWrappedProperties( std::vector< WrappedProperty* >& rList
     294             :                                     , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
     295             : {
     296          40 :     rList.push_back( new WrappedVolumeProperty( spChart2ModelContact ) );
     297          40 :     rList.push_back( new WrappedUpDownProperty( spChart2ModelContact ) );
     298          40 : }
     299             : 
     300             : } //namespace wrapper
     301             : } //namespace chart
     302             : //.............................................................................
     303             : 
     304             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10