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

Generated by: LCOV version 1.11