LCOV - code coverage report
Current view: top level - chart2/source/controller/chartapiwrapper - WrappedDataCaptionProperties.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 52 53 98.1 %
Date: 2014-11-03 Functions: 13 13 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       10348 : sal_Int32 lcl_LabelToCaption( const chart2::DataPointLabel& rLabel )
      61             : {
      62       10348 :     sal_Int32 nCaption=0;
      63             : 
      64       10348 :     if( rLabel.ShowNumber )
      65        2956 :         nCaption |= ::com::sun::star::chart::ChartDataCaption::VALUE;
      66       10348 :     if( rLabel.ShowNumberInPercent )
      67        1150 :         nCaption |= ::com::sun::star::chart::ChartDataCaption::PERCENT;
      68       10348 :     if( rLabel.ShowCategoryName )
      69        1434 :         nCaption |= ::com::sun::star::chart::ChartDataCaption::TEXT;
      70       10348 :     if( rLabel.ShowLegendSymbol )
      71         192 :         nCaption |= ::com::sun::star::chart::ChartDataCaption::SYMBOL;
      72             : 
      73       10348 :     return nCaption;
      74             : }
      75             : 
      76         674 : chart2::DataPointLabel lcl_CaptionToLabel( sal_Int32 nCaption )
      77             : {
      78         674 :     chart2::DataPointLabel aLabel(false,false,false,false);
      79             : 
      80         674 :     if( nCaption & ::com::sun::star::chart::ChartDataCaption::VALUE )
      81         168 :         aLabel.ShowNumber = true;
      82         674 :     if( nCaption & ::com::sun::star::chart::ChartDataCaption::PERCENT )
      83          12 :         aLabel.ShowNumberInPercent = true;
      84         674 :     if( nCaption & ::com::sun::star::chart::ChartDataCaption::TEXT )
      85          20 :         aLabel.ShowCategoryName = true;
      86         674 :     if( nCaption & ::com::sun::star::chart::ChartDataCaption::SYMBOL )
      87           0 :         aLabel.ShowLegendSymbol = true;
      88             : 
      89         674 :     return aLabel;
      90             : }
      91             : 
      92        5846 : 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        5846 :     rList.push_back( new WrappedDataCaptionProperty( spChart2ModelContact, ePropertyType ) );
     100        5846 : }
     101             : 
     102             : }//anonymous namespace
     103             : 
     104          56 : void WrappedDataCaptionProperties::addProperties( ::std::vector< Property > & rOutProperties )
     105             : {
     106             :     rOutProperties.push_back(
     107             :         Property( "DataCaption",
     108             :                   PROP_CHART_DATAPOINT_DATA_CAPTION,
     109          56 :                   cppu::UnoType<sal_Int32>::get(),
     110             :                   beans::PropertyAttribute::BOUND
     111         112 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
     112          56 : }
     113             : 
     114        5266 : void WrappedDataCaptionProperties::addWrappedPropertiesForSeries( std::vector< WrappedProperty* >& rList
     115             :                                     , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
     116             : {
     117        5266 :     lcl_addWrappedProperties( rList, spChart2ModelContact, DATA_SERIES );
     118        5266 : }
     119             : 
     120         580 : void WrappedDataCaptionProperties::addWrappedPropertiesForDiagram( std::vector< WrappedProperty* >& rList
     121             :                                     , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
     122             : {
     123         580 :     lcl_addWrappedProperties( rList, spChart2ModelContact, DIAGRAM );
     124         580 : }
     125             : 
     126        5846 : WrappedDataCaptionProperty::WrappedDataCaptionProperty(
     127             :       ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact
     128             :     , tSeriesOrDiagramPropertyType ePropertyType )
     129             :         : WrappedSeriesOrDiagramProperty< sal_Int32 >( "DataCaption"
     130        5846 :             , uno::makeAny( sal_Int32(0) ), spChart2ModelContact, ePropertyType )
     131             : {
     132        5846 : }
     133       11692 : WrappedDataCaptionProperty::~WrappedDataCaptionProperty()
     134             : {
     135       11692 : }
     136             : 
     137       10348 : sal_Int32 WrappedDataCaptionProperty::getValueFromSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet ) const
     138             : {
     139       10348 :     sal_Int32 aRet = 0;
     140       10348 :     m_aDefaultValue >>= aRet;
     141       10348 :     chart2::DataPointLabel aLabel;
     142       10348 :     if( xSeriesPropertySet.is() && ( xSeriesPropertySet->getPropertyValue(CHART_UNONAME_LABEL) >>= aLabel ) )
     143       10348 :         aRet = lcl_LabelToCaption( aLabel );
     144       10348 :     return aRet;
     145             : }
     146             : 
     147         674 : void WrappedDataCaptionProperty::setValueToSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet, const sal_Int32& nCaption ) const
     148             : {
     149         674 :     if(!xSeriesPropertySet.is())
     150         674 :         return;
     151             : 
     152         674 :     chart2::DataPointLabel aLabel = lcl_CaptionToLabel( nCaption );
     153         674 :     xSeriesPropertySet->setPropertyValue( CHART_UNONAME_LABEL, uno::makeAny( aLabel ) );
     154             : }
     155             : 
     156             : } //namespace wrapper
     157         102 : } //namespace chart
     158             : 
     159             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10