LCOV - code coverage report
Current view: top level - chart2/source/view/axes - VAxisBase.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 97 110 88.2 %
Date: 2012-08-25 Functions: 14 17 82.4 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 81 144 56.2 %

           Branch data     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 "VAxisBase.hxx"
      22                 :            : #include "ShapeFactory.hxx"
      23                 :            : #include "CommonConverters.hxx"
      24                 :            : #include "Tickmarks.hxx"
      25                 :            : #include "macros.hxx"
      26                 :            : 
      27                 :            : #include <memory>
      28                 :            : #include <boost/scoped_ptr.hpp>
      29                 :            : 
      30                 :            : //.............................................................................
      31                 :            : namespace chart
      32                 :            : {
      33                 :            : //.............................................................................
      34                 :            : using namespace ::com::sun::star;
      35                 :            : using namespace ::com::sun::star::chart2;
      36                 :            : using ::com::sun::star::uno::Reference;
      37                 :            : 
      38                 :       1938 : VAxisBase::VAxisBase( sal_Int32 nDimensionIndex, sal_Int32 nDimensionCount
      39                 :            :                      , const AxisProperties& rAxisProperties
      40                 :            :                      , const uno::Reference< util::XNumberFormatsSupplier >& xNumberFormatsSupplier )
      41                 :            :             : VAxisOrGridBase( nDimensionIndex, nDimensionCount )
      42                 :            :             , m_xNumberFormatsSupplier( xNumberFormatsSupplier )
      43                 :            :             , m_aAxisProperties( rAxisProperties )
      44                 :            :             , m_bUseTextLabels( false )
      45                 :            :             , m_bReCreateAllTickInfos( true )
      46                 :            :             , m_bRecordMaximumTextSize(false)
      47                 :            :             , m_nMaximumTextWidthSoFar(0)
      48 [ +  - ][ +  - ]:       1938 :             , m_nMaximumTextHeightSoFar(0)
         [ +  - ][ +  - ]
      49                 :            : {
      50                 :       1938 : }
      51                 :            : 
      52 [ +  - ][ +  - ]:       1938 : VAxisBase::~VAxisBase()
      53                 :            : {
      54         [ -  + ]:       1938 : }
      55                 :            : 
      56                 :      14761 : sal_Int32 VAxisBase::getDimensionCount()
      57                 :            : {
      58                 :      14761 :     return m_nDimension;
      59                 :            : }
      60                 :            : 
      61                 :       1938 : void VAxisBase::initAxisLabelProperties( const ::com::sun::star::awt::Size& rFontReferenceSize
      62                 :            :                   , const ::com::sun::star::awt::Rectangle& rMaximumSpaceForLabels )
      63                 :            : {
      64                 :       1938 :     m_aAxisLabelProperties.m_aFontReferenceSize = rFontReferenceSize;
      65                 :       1938 :     m_aAxisLabelProperties.m_aMaximumSpaceForLabels = rMaximumSpaceForLabels;
      66                 :            : 
      67         [ +  + ]:       1938 :     if( !m_aAxisProperties.m_bDisplayLabels )
      68                 :        157 :         return;
      69                 :            : 
      70         [ +  + ]:       1781 :     if( AxisType::SERIES==m_aAxisProperties.m_nAxisType )
      71                 :            :     {
      72         [ +  - ]:         14 :         if( m_aAxisProperties.m_xAxisTextProvider.is() )
      73         [ +  - ]:         14 :             m_aTextLabels = m_aAxisProperties.m_xAxisTextProvider->getTextualData();
      74                 :            : 
      75                 :         14 :         m_bUseTextLabels = true;
      76         [ +  + ]:         14 :         if( m_aTextLabels.getLength() == 1 )
      77                 :            :         {
      78                 :            :             //don't show a single series name
      79                 :          5 :             m_aAxisProperties.m_bDisplayLabels = false;
      80                 :          5 :             return;
      81                 :            :         }
      82                 :            :     }
      83         [ +  + ]:       1767 :     else if( AxisType::CATEGORY==m_aAxisProperties.m_nAxisType )
      84                 :            :     {
      85         [ +  - ]:        962 :         if( m_aAxisProperties.m_pExplicitCategoriesProvider )
      86         [ +  - ]:        962 :             m_aTextLabels = m_aAxisProperties.m_pExplicitCategoriesProvider->getSimpleCategories();
      87                 :            : 
      88                 :        962 :         m_bUseTextLabels = true;
      89                 :            :     }
      90                 :            : 
      91                 :       1776 :     m_aAxisLabelProperties.nNumberFormatKey = m_aAxisProperties.m_nNumberFormatKey;
      92                 :       1776 :     m_aAxisLabelProperties.init(m_aAxisProperties.m_xAxisModel);
      93 [ #  # ][ -  + ]:       1776 :     if( m_aAxisProperties.m_bComplexCategories && AxisType::CATEGORY == m_aAxisProperties.m_nAxisType )
      94                 :       1938 :         m_aAxisLabelProperties.eStaggering = SIDE_BY_SIDE;
      95                 :            : }
      96                 :            : 
      97                 :       4249 : bool VAxisBase::isDateAxis() const
      98                 :            : {
      99                 :       4249 :     return AxisType::DATE == m_aScale.AxisType;
     100                 :            : }
     101                 :      18167 : bool VAxisBase::isComplexCategoryAxis() const
     102                 :            : {
     103 [ -  + ][ #  # ]:      18167 :     return m_aAxisProperties.m_bComplexCategories && m_bUseTextLabels;
     104                 :            : }
     105                 :            : 
     106                 :      15991 : void VAxisBase::recordMaximumTextSize( const Reference< drawing::XShape >& xShape, double fRotationAngleDegree )
     107                 :            : {
     108 [ +  + ][ +  - ]:      15991 :     if( m_bRecordMaximumTextSize && xShape.is() )
                 [ +  + ]
     109                 :            :     {
     110                 :            :         awt::Size aSize( ShapeFactory::getSizeAfterRotation(
     111         [ +  - ]:       6651 :                             xShape, fRotationAngleDegree ) );
     112                 :            : 
     113         [ +  - ]:       6651 :         m_nMaximumTextWidthSoFar = std::max( m_nMaximumTextWidthSoFar, aSize.Width );
     114         [ +  - ]:       6651 :         m_nMaximumTextHeightSoFar = std::max( m_nMaximumTextHeightSoFar, aSize.Height );
     115                 :            :     }
     116                 :      15991 : }
     117                 :            : 
     118                 :          0 : sal_Int32 VAxisBase::estimateMaximumAutoMainIncrementCount()
     119                 :            : {
     120                 :          0 :     return 10;
     121                 :            : }
     122                 :            : 
     123                 :        962 : void VAxisBase::setExrtaLinePositionAtOtherAxis( const double& fCrossingAt )
     124                 :            : {
     125         [ -  + ]:        962 :     if( m_aAxisProperties.m_pfExrtaLinePositionAtOtherAxis )
     126                 :          0 :         delete m_aAxisProperties.m_pfExrtaLinePositionAtOtherAxis;
     127                 :        962 :     m_aAxisProperties.m_pfExrtaLinePositionAtOtherAxis = new double(fCrossingAt);
     128                 :        962 : }
     129                 :            : 
     130                 :       5814 : sal_Bool VAxisBase::isAnythingToDraw()
     131                 :            : {
     132         [ -  + ]:       5814 :     if( !m_aAxisProperties.m_xAxisModel.is() )
     133                 :          0 :         return false;
     134                 :            : 
     135                 :            :     OSL_ENSURE(m_pShapeFactory&&m_xLogicTarget.is()&&m_xFinalTarget.is(),"Axis is not proper initialized");
     136 [ +  - ][ +  - ]:       5814 :     if(!(m_pShapeFactory&&m_xLogicTarget.is()&&m_xFinalTarget.is()))
         [ -  + ][ -  + ]
     137                 :          0 :         return false;
     138                 :            : 
     139         [ +  - ]:       5814 :     uno::Reference< beans::XPropertySet > xProps( m_aAxisProperties.m_xAxisModel, uno::UNO_QUERY );
     140         [ +  - ]:       5814 :     if( xProps.is() )
     141                 :            :     {
     142                 :       5814 :         sal_Bool bShow = sal_False;
     143 [ +  - ][ +  - ]:       5814 :         xProps->getPropertyValue( C2U( "Show" ) ) >>= bShow;
                 [ +  - ]
     144         [ +  + ]:       5814 :         if( !bShow )
     145                 :       5814 :             return false;
     146                 :            :     }
     147                 :       5814 :     return true;
     148                 :            : }
     149                 :            : 
     150                 :       3876 : void VAxisBase::setExplicitScaleAndIncrement(
     151                 :            :               const ExplicitScaleData& rScale
     152                 :            :             , const ExplicitIncrementData& rIncrement )
     153                 :            :             throw (uno::RuntimeException)
     154                 :            : {
     155                 :       3876 :     m_bReCreateAllTickInfos = true;
     156                 :       3876 :     m_aScale = rScale;
     157                 :       3876 :     m_aIncrement = rIncrement;
     158                 :       3876 : }
     159                 :            : 
     160                 :       3640 : void VAxisBase::createAllTickInfos( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos )
     161                 :            : {
     162         [ +  - ]:       3640 :     boost::scoped_ptr< TickFactory > apTickFactory( this->createTickFactory() );
     163         [ +  + ]:       3640 :     if( m_aScale.ShiftedCategoryPosition )
     164         [ +  - ]:       1808 :         apTickFactory->getAllTicksShifted( rAllTickInfos );
     165                 :            :     else
     166 [ +  - ][ +  - ]:       3640 :         apTickFactory->getAllTicks( rAllTickInfos );
     167                 :       3640 : }
     168                 :            : 
     169                 :       5814 : bool VAxisBase::prepareShapeCreation()
     170                 :            : {
     171                 :            :     //returns true if all is ready for further shape creation and any shapes need to be created
     172         [ +  + ]:       5814 :     if( !isAnythingToDraw() )
     173                 :        354 :         return false;
     174                 :            : 
     175         [ +  + ]:       5460 :     if( m_bReCreateAllTickInfos )
     176                 :            :     {
     177                 :            :         //-----------------------------------------
     178                 :            :         //create all scaled tickmark values
     179                 :       3640 :         removeTextShapesFromTicks();
     180                 :            : 
     181                 :       3640 :         createAllTickInfos(m_aAllTickInfos);
     182                 :       3640 :         m_bReCreateAllTickInfos = false;
     183                 :            :     }
     184                 :            : 
     185         [ +  + ]:       5460 :     if( m_xGroupShape_Shapes.is() )
     186                 :       3640 :         return true;
     187                 :            : 
     188                 :            :     //-----------------------------------------
     189                 :            :     //create named group shape
     190 [ +  + ][ +  - ]:       1820 :     m_xGroupShape_Shapes = this->createGroupShape( m_xLogicTarget, m_nDimension==2 ? m_aCID : C2U(""));
                 [ +  - ]
     191                 :            : 
     192         [ +  + ]:       1820 :     if( m_aAxisProperties.m_bDisplayLabels )
     193 [ +  - ][ +  - ]:       1681 :         m_xTextTarget = m_pShapeFactory->createGroup2D( m_xFinalTarget, m_aCID );
     194                 :            : 
     195                 :       5814 :     return true;
     196                 :            : }
     197                 :            : 
     198                 :        971 : sal_Int32 VAxisBase::getIndexOfLongestLabel( const uno::Sequence< rtl::OUString >& rLabels )
     199                 :            : {
     200                 :        971 :     sal_Int32 nRet = 0;
     201                 :        971 :     sal_Int32 nLength = 0;
     202                 :        971 :     sal_Int32 nN = 0;
     203         [ +  + ]:       5316 :     for( nN=0; nN<rLabels.getLength(); nN++ )
     204                 :            :     {
     205                 :            :         //todo: get real text width (without creating shape) instead of character count
     206         [ +  + ]:       4345 :         if( rLabels[nN].getLength() > nLength )
     207                 :            :         {
     208                 :        975 :             nLength = rLabels[nN].getLength();
     209                 :        975 :             nRet = nN;
     210                 :            :         }
     211                 :            :     }
     212                 :        971 :     return nRet;
     213                 :            : }
     214                 :            : 
     215                 :       5321 : void VAxisBase::removeTextShapesFromTicks()
     216                 :            : {
     217         [ +  + ]:       5321 :     if( m_xTextTarget.is() )
     218                 :            :     {
     219                 :       3362 :        ::std::vector< ::std::vector< TickInfo > >::iterator aDepthIter = m_aAllTickInfos.begin();
     220         [ +  - ]:       3362 :         const ::std::vector< ::std::vector< TickInfo > >::const_iterator aDepthEnd  = m_aAllTickInfos.end();
     221 [ +  - ][ +  + ]:      10086 :         for( ; aDepthIter != aDepthEnd; ++aDepthIter )
     222                 :            :         {
     223                 :       6724 :             ::std::vector< TickInfo >::iterator       aTickIter = (*aDepthIter).begin();
     224         [ +  - ]:       6724 :             const ::std::vector< TickInfo >::const_iterator aTickEnd  = (*aDepthIter).end();
     225 [ +  - ][ +  + ]:      45926 :             for( ; aTickIter != aTickEnd; ++aTickIter )
     226                 :            :             {
     227                 :      39202 :                 TickInfo& rTickInfo = (*aTickIter);
     228         [ +  + ]:      39202 :                 if(rTickInfo.xTextShape.is())
     229                 :            :                 {
     230 [ +  - ][ +  - ]:       6651 :                     m_xTextTarget->remove(rTickInfo.xTextShape);
     231         [ +  - ]:       6651 :                     rTickInfo.xTextShape = NULL;
     232                 :            :                 }
     233                 :            :             }
     234                 :            :         }
     235                 :            :     }
     236                 :       5321 : }
     237                 :            : 
     238                 :          0 : void VAxisBase::updateUnscaledValuesAtTicks( TickIter& rIter )
     239                 :            : {
     240         [ #  # ]:          0 :     Reference< XScaling > xInverseScaling( NULL );
     241         [ #  # ]:          0 :     if( m_aScale.Scaling.is() )
     242 [ #  # ][ #  # ]:          0 :         xInverseScaling = m_aScale.Scaling->getInverseScaling();
                 [ #  # ]
     243                 :            : 
     244 [ #  # ][ #  # ]:          0 :     for( TickInfo* pTickInfo = rIter.firstInfo()
                 [ #  # ]
     245                 :          0 :         ; pTickInfo; pTickInfo = rIter.nextInfo() )
     246                 :            :     {
     247                 :            :         //xxxxx pTickInfo->updateUnscaledValue( xInverseScaling );
     248                 :          0 :     }
     249                 :          0 : }
     250                 :            : 
     251                 :            : //.............................................................................
     252                 :            : } //namespace chart
     253                 :            : //.............................................................................
     254                 :            : 
     255                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10