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

Generated by: LCOV version 1.10