LCOV - code coverage report
Current view: top level - chart2/source/controller/chartapiwrapper - WrappedGapwidthProperty.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 65 69 94.2 %
Date: 2014-04-11 Functions: 11 12 91.7 %
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 "WrappedGapwidthProperty.hxx"
      21             : #include "macros.hxx"
      22             : #include "DiagramHelper.hxx"
      23             : 
      24             : using namespace ::com::sun::star;
      25             : using ::com::sun::star::uno::Reference;
      26             : using ::com::sun::star::uno::Sequence;
      27             : using ::com::sun::star::uno::Any;
      28             : 
      29             : namespace chart
      30             : {
      31             : namespace wrapper
      32             : {
      33             : 
      34             : const sal_Int32 DEFAULT_GAPWIDTH = 100;
      35             : const sal_Int32 DEFAULT_OVERLAP = 0;
      36             : 
      37         716 : WrappedBarPositionProperty_Base::WrappedBarPositionProperty_Base(
      38             :                   const OUString& rOuterName
      39             :                 , const OUString& rInnerSequencePropertyName
      40             :                 , sal_Int32 nDefaultValue
      41             :                 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
      42             :             : WrappedDefaultProperty( rOuterName, OUString(), uno::makeAny( nDefaultValue ) )
      43             :             , m_nDimensionIndex(0)
      44             :             , m_nAxisIndex(0)
      45             :             , m_spChart2ModelContact( spChart2ModelContact )
      46             :             , m_nDefaultValue( nDefaultValue )
      47         716 :             , m_InnerSequencePropertyName( rInnerSequencePropertyName )
      48             : {
      49         716 : }
      50             : 
      51         716 : void WrappedBarPositionProperty_Base::setDimensionAndAxisIndex( sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex )
      52             : {
      53         716 :     m_nDimensionIndex = nDimensionIndex;
      54         716 :     m_nAxisIndex = nAxisIndex;
      55         716 : }
      56             : 
      57         704 : WrappedBarPositionProperty_Base::~WrappedBarPositionProperty_Base()
      58             : {
      59         704 : }
      60             : 
      61          48 : void WrappedBarPositionProperty_Base::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
      62             :                 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
      63             : {
      64          48 :     sal_Int32 nNewValue = 0;
      65          48 :     if( ! (rOuterValue >>= nNewValue) )
      66           0 :         throw lang::IllegalArgumentException( "GapWidth and Overlap property require value of type sal_Int32", 0, 0 );
      67             : 
      68          48 :     m_aOuterValue = rOuterValue;
      69             : 
      70          48 :     Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
      71          48 :     if( !xDiagram.is() )
      72          48 :         return;
      73             : 
      74          48 :     if( m_nDimensionIndex==1 )
      75             :     {
      76          48 :         Sequence< Reference< chart2::XChartType > > aChartTypeList( DiagramHelper::getChartTypesFromDiagram( xDiagram ) );
      77          96 :         for( sal_Int32 nN = 0; nN < aChartTypeList.getLength(); nN++ )
      78             :         {
      79             :             try
      80             :             {
      81          48 :                 Reference< beans::XPropertySet > xProp( aChartTypeList[nN], uno::UNO_QUERY );
      82          48 :                 if( xProp.is() )
      83             :                 {
      84          48 :                     Sequence< sal_Int32 > aBarPositionSequence;
      85          48 :                     xProp->getPropertyValue( m_InnerSequencePropertyName ) >>= aBarPositionSequence;
      86             : 
      87          46 :                     long nOldLength = aBarPositionSequence.getLength();
      88          46 :                     if( nOldLength <= m_nAxisIndex  )
      89             :                     {
      90           0 :                         aBarPositionSequence.realloc( m_nAxisIndex+1 );
      91           0 :                         for( sal_Int32 i=nOldLength; i<m_nAxisIndex; i++ )
      92             :                         {
      93           0 :                             aBarPositionSequence[i] = m_nDefaultValue;
      94             :                         }
      95             :                     }
      96          46 :                     aBarPositionSequence[m_nAxisIndex] = nNewValue;
      97             : 
      98          46 :                     xProp->setPropertyValue( m_InnerSequencePropertyName, uno::makeAny( aBarPositionSequence ) );
      99          48 :                 }
     100             :             }
     101           4 :             catch( uno::Exception& e )
     102             :             {
     103             :                 //the above properties are not supported by all charttypes (only by column and bar)
     104             :                 //in that cases this exception is ok
     105           2 :                 e.Context.is();//to have debug information without compilation warnings
     106             :             }
     107          48 :         }
     108          48 :     }
     109             : }
     110             : 
     111        3362 : Any WrappedBarPositionProperty_Base::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
     112             :                         throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
     113             : {
     114        3362 :     Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
     115        3362 :     if( xDiagram.is() )
     116             :     {
     117        3362 :         bool bInnerValueDetected = false;
     118        3362 :         sal_Int32 nInnerValue = m_nDefaultValue;
     119             : 
     120        3362 :         if( m_nDimensionIndex==1 )
     121             :         {
     122        1202 :             Sequence< Reference< chart2::XChartType > > aChartTypeList( DiagramHelper::getChartTypesFromDiagram( xDiagram ) );
     123        2404 :             for( sal_Int32 nN = 0; nN < aChartTypeList.getLength() && !bInnerValueDetected; nN++ )
     124             :             {
     125             :                 try
     126             :                 {
     127        1202 :                     Reference< beans::XPropertySet > xProp( aChartTypeList[nN], uno::UNO_QUERY );
     128        1202 :                     if( xProp.is() )
     129             :                     {
     130        1202 :                         Sequence< sal_Int32 > aBarPositionSequence;
     131        1202 :                         xProp->getPropertyValue( m_InnerSequencePropertyName ) >>= aBarPositionSequence;
     132         746 :                         if( m_nAxisIndex < aBarPositionSequence.getLength() )
     133             :                         {
     134         746 :                             nInnerValue = aBarPositionSequence[m_nAxisIndex];
     135         746 :                             bInnerValueDetected = true;
     136        1202 :                         }
     137        1202 :                     }
     138             :                 }
     139         912 :                 catch( uno::Exception& e )
     140             :                 {
     141             :                     //the above properties are not supported by all charttypes (only by column and bar)
     142             :                     //in that cases this exception is ok
     143         456 :                     e.Context.is();//to have debug information without compilation warnings
     144             :                 }
     145        1202 :             }
     146             :         }
     147        3362 :         if( bInnerValueDetected )
     148             :         {
     149         746 :             m_aOuterValue <<= nInnerValue;
     150             :         }
     151             :     }
     152        3362 :     return m_aOuterValue;
     153             : }
     154             : 
     155         358 : WrappedGapwidthProperty::WrappedGapwidthProperty(
     156             :         ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
     157         358 :     : WrappedBarPositionProperty_Base( "GapWidth", "GapwidthSequence", DEFAULT_GAPWIDTH, spChart2ModelContact )
     158             : {
     159         358 : }
     160         704 : WrappedGapwidthProperty::~WrappedGapwidthProperty()
     161             : {
     162         704 : }
     163             : 
     164         358 : WrappedBarOverlapProperty::WrappedBarOverlapProperty(
     165             :         ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
     166         358 :     : WrappedBarPositionProperty_Base( "Overlap", "OverlapSequence", DEFAULT_OVERLAP, spChart2ModelContact )
     167             : {
     168         358 : }
     169         704 : WrappedBarOverlapProperty::~WrappedBarOverlapProperty()
     170             : {
     171         704 : }
     172             : 
     173             : } //  namespace wrapper
     174             : } //  namespace chart
     175             : 
     176             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10