LCOV - code coverage report
Current view: top level - chart2/source/controller/chartapiwrapper - WrappedDataCaptionProperties.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 51 52 98.1 %
Date: 2014-04-11 Functions: 11 11 100.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 "WrappedDataCaptionProperties.hxx"
      21             : #include "WrappedSeriesOrDiagramProperty.hxx"
      22             : #include "macros.hxx"
      23             : #include "FastPropertyIdRanges.hxx"
      24             : #include <com/sun/star/chart2/DataPointLabel.hpp>
      25             : #include <com/sun/star/chart/ChartDataCaption.hpp>
      26             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      27             : 
      28             : using namespace ::com::sun::star;
      29             : using ::com::sun::star::uno::Any;
      30             : using ::com::sun::star::uno::Reference;
      31             : using ::com::sun::star::uno::Sequence;
      32             : using ::com::sun::star::beans::Property;
      33             : 
      34             : namespace chart
      35             : {
      36             : namespace wrapper
      37             : {
      38             : 
      39             : class WrappedDataCaptionProperty : public WrappedSeriesOrDiagramProperty< sal_Int32 >
      40             : {
      41             : public:
      42             :     virtual sal_Int32 getValueFromSeries( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xSeriesPropertySet ) const SAL_OVERRIDE;
      43             :     virtual void setValueToSeries( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xSeriesPropertySet, const sal_Int32& aNewValue ) const SAL_OVERRIDE;
      44             : 
      45             :     explicit WrappedDataCaptionProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact,
      46             :                                          tSeriesOrDiagramPropertyType ePropertyType );
      47             :     virtual ~WrappedDataCaptionProperty();
      48             : };
      49             : 
      50             : namespace
      51             : {
      52             : enum
      53             : {
      54             :     //data caption properties
      55             :     PROP_CHART_DATAPOINT_DATA_CAPTION = FAST_PROPERTY_ID_START_CHART_DATACAPTION_PROP
      56             : };
      57             : 
      58        3460 : sal_Int32 lcl_LabelToCaption( const chart2::DataPointLabel& rLabel )
      59             : {
      60        3460 :     sal_Int32 nCaption=0;
      61             : 
      62        3460 :     if( rLabel.ShowNumber )
      63         410 :         nCaption |= ::com::sun::star::chart::ChartDataCaption::VALUE;
      64        3460 :     if( rLabel.ShowNumberInPercent )
      65         605 :         nCaption |= ::com::sun::star::chart::ChartDataCaption::PERCENT;
      66        3460 :     if( rLabel.ShowCategoryName )
      67         747 :         nCaption |= ::com::sun::star::chart::ChartDataCaption::TEXT;
      68        3460 :     if( rLabel.ShowLegendSymbol )
      69          96 :         nCaption |= ::com::sun::star::chart::ChartDataCaption::SYMBOL;
      70             : 
      71        3460 :     return nCaption;
      72             : }
      73             : 
      74         209 : chart2::DataPointLabel lcl_CaptionToLabel( sal_Int32 nCaption )
      75             : {
      76         209 :     chart2::DataPointLabel aLabel(false,false,false,false);
      77             : 
      78         209 :     if( nCaption & ::com::sun::star::chart::ChartDataCaption::VALUE )
      79          24 :         aLabel.ShowNumber = true;
      80         209 :     if( nCaption & ::com::sun::star::chart::ChartDataCaption::PERCENT )
      81           6 :         aLabel.ShowNumberInPercent = true;
      82         209 :     if( nCaption & ::com::sun::star::chart::ChartDataCaption::TEXT )
      83          10 :         aLabel.ShowCategoryName = true;
      84         209 :     if( nCaption & ::com::sun::star::chart::ChartDataCaption::SYMBOL )
      85           0 :         aLabel.ShowLegendSymbol = true;
      86             : 
      87         209 :     return aLabel;
      88             : }
      89             : 
      90        2058 : void lcl_addWrappedProperties( std::vector< WrappedProperty* >& rList
      91             :                                     , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact
      92             :                                     , tSeriesOrDiagramPropertyType ePropertyType )
      93             : {
      94             :     //if !spChart2ModelContact.get() is then the created properties do belong to a single series or single datapoint
      95             :     //otherwise they do belong to the whole diagram
      96             : 
      97        2058 :     rList.push_back( new WrappedDataCaptionProperty( spChart2ModelContact, ePropertyType ) );
      98        2058 : }
      99             : 
     100             : }//anonymous namespace
     101             : 
     102          25 : void WrappedDataCaptionProperties::addProperties( ::std::vector< Property > & rOutProperties )
     103             : {
     104             :     rOutProperties.push_back(
     105             :         Property( "DataCaption",
     106             :                   PROP_CHART_DATAPOINT_DATA_CAPTION,
     107          25 :                   ::getCppuType( reinterpret_cast< sal_Int32 * >(0)),
     108             :                   beans::PropertyAttribute::BOUND
     109          50 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
     110          25 : }
     111             : 
     112        1854 : void WrappedDataCaptionProperties::addWrappedPropertiesForSeries( std::vector< WrappedProperty* >& rList
     113             :                                     , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
     114             : {
     115        1854 :     lcl_addWrappedProperties( rList, spChart2ModelContact, DATA_SERIES );
     116        1854 : }
     117             : 
     118         204 : void WrappedDataCaptionProperties::addWrappedPropertiesForDiagram( std::vector< WrappedProperty* >& rList
     119             :                                     , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
     120             : {
     121         204 :     lcl_addWrappedProperties( rList, spChart2ModelContact, DIAGRAM );
     122         204 : }
     123             : 
     124        2058 : WrappedDataCaptionProperty::WrappedDataCaptionProperty(
     125             :       ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact
     126             :     , tSeriesOrDiagramPropertyType ePropertyType )
     127             :         : WrappedSeriesOrDiagramProperty< sal_Int32 >( "DataCaption"
     128        2058 :             , uno::makeAny( sal_Int32(0) ), spChart2ModelContact, ePropertyType )
     129             : {
     130        2058 : }
     131        4104 : WrappedDataCaptionProperty::~WrappedDataCaptionProperty()
     132             : {
     133        4104 : }
     134             : 
     135        3460 : sal_Int32 WrappedDataCaptionProperty::getValueFromSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet ) const
     136             : {
     137        3460 :     sal_Int32 aRet = 0;
     138        3460 :     m_aDefaultValue >>= aRet;
     139        3460 :     chart2::DataPointLabel aLabel;
     140        3460 :     if( xSeriesPropertySet.is() && ( xSeriesPropertySet->getPropertyValue("Label") >>= aLabel ) )
     141        3460 :         aRet = lcl_LabelToCaption( aLabel );
     142        3460 :     return aRet;
     143             : }
     144             : 
     145         209 : void WrappedDataCaptionProperty::setValueToSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet, const sal_Int32& nCaption ) const
     146             : {
     147         209 :     if(!xSeriesPropertySet.is())
     148         209 :         return;
     149             : 
     150         209 :     chart2::DataPointLabel aLabel = lcl_CaptionToLabel( nCaption );
     151         209 :     xSeriesPropertySet->setPropertyValue( "Label", uno::makeAny( aLabel ) );
     152             : }
     153             : 
     154             : } //namespace wrapper
     155             : } //namespace chart
     156             : 
     157             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10