LCOV - code coverage report
Current view: top level - chart2/source/controller/chartapiwrapper - WrappedGapwidthProperty.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 65 69 94.2 %
Date: 2015-06-13 12:38:46 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         910 : 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         910 :             , m_InnerSequencePropertyName( rInnerSequencePropertyName )
      48             : {
      49         910 : }
      50             : 
      51         910 : void WrappedBarPositionProperty_Base::setDimensionAndAxisIndex( sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex )
      52             : {
      53         910 :     m_nDimensionIndex = nDimensionIndex;
      54         910 :     m_nAxisIndex = nAxisIndex;
      55         910 : }
      56             : 
      57         910 : WrappedBarPositionProperty_Base::~WrappedBarPositionProperty_Base()
      58             : {
      59         910 : }
      60             : 
      61          42 : 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          42 :     sal_Int32 nNewValue = 0;
      65          42 :     if( ! (rOuterValue >>= nNewValue) )
      66           0 :         throw lang::IllegalArgumentException( "GapWidth and Overlap property require value of type sal_Int32", 0, 0 );
      67             : 
      68          42 :     m_aOuterValue = rOuterValue;
      69             : 
      70          42 :     Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
      71          42 :     if( !xDiagram.is() )
      72          42 :         return;
      73             : 
      74          42 :     if( m_nDimensionIndex==1 )
      75             :     {
      76          42 :         Sequence< Reference< chart2::XChartType > > aChartTypeList( DiagramHelper::getChartTypesFromDiagram( xDiagram ) );
      77          84 :         for( sal_Int32 nN = 0; nN < aChartTypeList.getLength(); nN++ )
      78             :         {
      79             :             try
      80             :             {
      81          42 :                 Reference< beans::XPropertySet > xProp( aChartTypeList[nN], uno::UNO_QUERY );
      82          42 :                 if( xProp.is() )
      83             :                 {
      84          42 :                     Sequence< sal_Int32 > aBarPositionSequence;
      85          42 :                     xProp->getPropertyValue( m_InnerSequencePropertyName ) >>= aBarPositionSequence;
      86             : 
      87          40 :                     long nOldLength = aBarPositionSequence.getLength();
      88          40 :                     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          40 :                     aBarPositionSequence[m_nAxisIndex] = nNewValue;
      97             : 
      98          40 :                     xProp->setPropertyValue( m_InnerSequencePropertyName, uno::makeAny( aBarPositionSequence ) );
      99          42 :                 }
     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          42 :         }
     108          42 :     }
     109             : }
     110             : 
     111        5086 : Any WrappedBarPositionProperty_Base::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
     112             :                         throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
     113             : {
     114        5086 :     Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
     115        5086 :     if( xDiagram.is() )
     116             :     {
     117        5086 :         bool bInnerValueDetected = false;
     118        5086 :         sal_Int32 nInnerValue = m_nDefaultValue;
     119             : 
     120        5086 :         if( m_nDimensionIndex==1 )
     121             :         {
     122        1958 :             Sequence< Reference< chart2::XChartType > > aChartTypeList( DiagramHelper::getChartTypesFromDiagram( xDiagram ) );
     123        3916 :             for( sal_Int32 nN = 0; nN < aChartTypeList.getLength() && !bInnerValueDetected; nN++ )
     124             :             {
     125             :                 try
     126             :                 {
     127        1958 :                     Reference< beans::XPropertySet > xProp( aChartTypeList[nN], uno::UNO_QUERY );
     128        1958 :                     if( xProp.is() )
     129             :                     {
     130        1958 :                         Sequence< sal_Int32 > aBarPositionSequence;
     131        1958 :                         xProp->getPropertyValue( m_InnerSequencePropertyName ) >>= aBarPositionSequence;
     132        1126 :                         if( m_nAxisIndex < aBarPositionSequence.getLength() )
     133             :                         {
     134        1126 :                             nInnerValue = aBarPositionSequence[m_nAxisIndex];
     135        1126 :                             bInnerValueDetected = true;
     136        1958 :                         }
     137        1958 :                     }
     138             :                 }
     139        1664 :                 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         832 :                     e.Context.is();//to have debug information without compilation warnings
     144             :                 }
     145        1958 :             }
     146             :         }
     147        5086 :         if( bInnerValueDetected )
     148             :         {
     149        1126 :             m_aOuterValue <<= nInnerValue;
     150             :         }
     151             :     }
     152        5086 :     return m_aOuterValue;
     153             : }
     154             : 
     155         455 : WrappedGapwidthProperty::WrappedGapwidthProperty(
     156             :         ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
     157         455 :     : WrappedBarPositionProperty_Base( "GapWidth", "GapwidthSequence", DEFAULT_GAPWIDTH, spChart2ModelContact )
     158             : {
     159         455 : }
     160         910 : WrappedGapwidthProperty::~WrappedGapwidthProperty()
     161             : {
     162         910 : }
     163             : 
     164         455 : WrappedBarOverlapProperty::WrappedBarOverlapProperty(
     165             :         ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
     166         455 :     : WrappedBarPositionProperty_Base( "Overlap", "OverlapSequence", DEFAULT_OVERLAP, spChart2ModelContact )
     167             : {
     168         455 : }
     169         910 : WrappedBarOverlapProperty::~WrappedBarOverlapProperty()
     170             : {
     171         910 : }
     172             : 
     173             : } //  namespace wrapper
     174             : } //  namespace chart
     175             : 
     176             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11