LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/chart2/source/view/axes - VAxisBase.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 96 110 87.3 %
Date: 2013-07-09 Functions: 14 17 82.4 %
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 "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        1044 : 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        1044 :             , m_nMaximumTextHeightSoFar(0)
      49             : {
      50        1044 : }
      51             : 
      52        1044 : VAxisBase::~VAxisBase()
      53             : {
      54        1044 : }
      55             : 
      56        7996 : sal_Int32 VAxisBase::getDimensionCount()
      57             : {
      58        7996 :     return m_nDimension;
      59             : }
      60             : 
      61        1044 : void VAxisBase::initAxisLabelProperties( const ::com::sun::star::awt::Size& rFontReferenceSize
      62             :                   , const ::com::sun::star::awt::Rectangle& rMaximumSpaceForLabels )
      63             : {
      64        1044 :     m_aAxisLabelProperties.m_aFontReferenceSize = rFontReferenceSize;
      65        1044 :     m_aAxisLabelProperties.m_aMaximumSpaceForLabels = rMaximumSpaceForLabels;
      66             : 
      67        1044 :     if( !m_aAxisProperties.m_bDisplayLabels )
      68          83 :         return;
      69             : 
      70         961 :     if( AxisType::SERIES==m_aAxisProperties.m_nAxisType )
      71             :     {
      72           8 :         if( m_aAxisProperties.m_xAxisTextProvider.is() )
      73           8 :             m_aTextLabels = m_aAxisProperties.m_xAxisTextProvider->getTextualData();
      74             : 
      75           8 :         m_bUseTextLabels = true;
      76           8 :         if( m_aTextLabels.getLength() == 1 )
      77             :         {
      78             :             //don't show a single series name
      79           3 :             m_aAxisProperties.m_bDisplayLabels = false;
      80           3 :             return;
      81             :         }
      82             :     }
      83         953 :     else if( AxisType::CATEGORY==m_aAxisProperties.m_nAxisType )
      84             :     {
      85         507 :         if( m_aAxisProperties.m_pExplicitCategoriesProvider )
      86         507 :             m_aTextLabels = m_aAxisProperties.m_pExplicitCategoriesProvider->getSimpleCategories();
      87             : 
      88         507 :         m_bUseTextLabels = true;
      89             :     }
      90             : 
      91         958 :     m_aAxisLabelProperties.nNumberFormatKey = m_aAxisProperties.m_nNumberFormatKey;
      92         958 :     m_aAxisLabelProperties.init(m_aAxisProperties.m_xAxisModel);
      93         958 :     if( m_aAxisProperties.m_bComplexCategories && AxisType::CATEGORY == m_aAxisProperties.m_nAxisType )
      94           0 :         m_aAxisLabelProperties.eStaggering = SIDE_BY_SIDE;
      95             : }
      96             : 
      97        2326 : bool VAxisBase::isDateAxis() const
      98             : {
      99        2326 :     return AxisType::DATE == m_aScale.AxisType;
     100             : }
     101        9954 : bool VAxisBase::isComplexCategoryAxis() const
     102             : {
     103        9954 :     return m_aAxisProperties.m_bComplexCategories && m_bUseTextLabels;
     104             : }
     105             : 
     106        8810 : void VAxisBase::recordMaximumTextSize( const Reference< drawing::XShape >& xShape, double fRotationAngleDegree )
     107             : {
     108        8810 :     if( m_bRecordMaximumTextSize && xShape.is() )
     109             :     {
     110             :         awt::Size aSize( ShapeFactory::getSizeAfterRotation(
     111        3656 :                             xShape, fRotationAngleDegree ) );
     112             : 
     113        3656 :         m_nMaximumTextWidthSoFar = std::max( m_nMaximumTextWidthSoFar, aSize.Width );
     114        3656 :         m_nMaximumTextHeightSoFar = std::max( m_nMaximumTextHeightSoFar, aSize.Height );
     115             :     }
     116        8810 : }
     117             : 
     118           0 : sal_Int32 VAxisBase::estimateMaximumAutoMainIncrementCount()
     119             : {
     120           0 :     return 10;
     121             : }
     122             : 
     123         529 : void VAxisBase::setExrtaLinePositionAtOtherAxis( const double& fCrossingAt )
     124             : {
     125         529 :     if( m_aAxisProperties.m_pfExrtaLinePositionAtOtherAxis )
     126           0 :         delete m_aAxisProperties.m_pfExrtaLinePositionAtOtherAxis;
     127         529 :     m_aAxisProperties.m_pfExrtaLinePositionAtOtherAxis = new double(fCrossingAt);
     128         529 : }
     129             : 
     130        3132 : sal_Bool VAxisBase::isAnythingToDraw()
     131             : {
     132        3132 :     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        3132 :     if(!(m_pShapeFactory&&m_xLogicTarget.is()&&m_xFinalTarget.is()))
     137           0 :         return false;
     138             : 
     139        3132 :     uno::Reference< beans::XPropertySet > xProps( m_aAxisProperties.m_xAxisModel, uno::UNO_QUERY );
     140        3132 :     if( xProps.is() )
     141             :     {
     142        3132 :         sal_Bool bShow = sal_False;
     143        3132 :         xProps->getPropertyValue( "Show" ) >>= bShow;
     144        3132 :         if( !bShow )
     145         138 :             return false;
     146             :     }
     147        2994 :     return true;
     148             : }
     149             : 
     150        2088 : void VAxisBase::setExplicitScaleAndIncrement(
     151             :               const ExplicitScaleData& rScale
     152             :             , const ExplicitIncrementData& rIncrement )
     153             :             throw (uno::RuntimeException)
     154             : {
     155        2088 :     m_bReCreateAllTickInfos = true;
     156        2088 :     m_aScale = rScale;
     157        2088 :     m_aIncrement = rIncrement;
     158        2088 : }
     159             : 
     160        1996 : void VAxisBase::createAllTickInfos( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos )
     161             : {
     162        1996 :     boost::scoped_ptr< TickFactory > apTickFactory( this->createTickFactory() );
     163        1996 :     if( m_aScale.ShiftedCategoryPosition )
     164         972 :         apTickFactory->getAllTicksShifted( rAllTickInfos );
     165             :     else
     166        1024 :         apTickFactory->getAllTicks( rAllTickInfos );
     167        1996 : }
     168             : 
     169        3132 : bool VAxisBase::prepareShapeCreation()
     170             : {
     171             :     //returns true if all is ready for further shape creation and any shapes need to be created
     172        3132 :     if( !isAnythingToDraw() )
     173         138 :         return false;
     174             : 
     175        2994 :     if( m_bReCreateAllTickInfos )
     176             :     {
     177             :         //-----------------------------------------
     178             :         //create all scaled tickmark values
     179        1996 :         removeTextShapesFromTicks();
     180             : 
     181        1996 :         createAllTickInfos(m_aAllTickInfos);
     182        1996 :         m_bReCreateAllTickInfos = false;
     183             :     }
     184             : 
     185        2994 :     if( m_xGroupShape_Shapes.is() )
     186        1996 :         return true;
     187             : 
     188             :     //-----------------------------------------
     189             :     //create named group shape
     190         998 :     m_xGroupShape_Shapes = this->createGroupShape( m_xLogicTarget, m_nDimension==2 ? m_aCID : "");
     191             : 
     192         998 :     if( m_aAxisProperties.m_bDisplayLabels )
     193         925 :         m_xTextTarget = m_pShapeFactory->createGroup2D( m_xFinalTarget, m_aCID );
     194             : 
     195         998 :     return true;
     196             : }
     197             : 
     198         512 : sal_Int32 VAxisBase::getIndexOfLongestLabel( const uno::Sequence< OUString >& rLabels )
     199             : {
     200         512 :     sal_Int32 nRet = 0;
     201         512 :     sal_Int32 nLength = 0;
     202         512 :     sal_Int32 nN = 0;
     203        2720 :     for( nN=0; nN<rLabels.getLength(); nN++ )
     204             :     {
     205             :         //todo: get real text width (without creating shape) instead of character count
     206        2208 :         if( rLabels[nN].getLength() > nLength )
     207             :         {
     208         511 :             nLength = rLabels[nN].getLength();
     209         511 :             nRet = nN;
     210             :         }
     211             :     }
     212         512 :     return nRet;
     213             : }
     214             : 
     215        2931 : void VAxisBase::removeTextShapesFromTicks()
     216             : {
     217        2931 :     if( m_xTextTarget.is() )
     218             :     {
     219        1860 :        ::std::vector< ::std::vector< TickInfo > >::iterator aDepthIter = m_aAllTickInfos.begin();
     220        1860 :         const ::std::vector< ::std::vector< TickInfo > >::const_iterator aDepthEnd  = m_aAllTickInfos.end();
     221        5580 :         for( ; aDepthIter != aDepthEnd; ++aDepthIter )
     222             :         {
     223        3720 :             ::std::vector< TickInfo >::iterator       aTickIter = (*aDepthIter).begin();
     224        3720 :             const ::std::vector< TickInfo >::const_iterator aTickEnd  = (*aDepthIter).end();
     225       24936 :             for( ; aTickIter != aTickEnd; ++aTickIter )
     226             :             {
     227       21216 :                 TickInfo& rTickInfo = (*aTickIter);
     228       21216 :                 if(rTickInfo.xTextShape.is())
     229             :                 {
     230        3676 :                     m_xTextTarget->remove(rTickInfo.xTextShape);
     231        3676 :                     rTickInfo.xTextShape = NULL;
     232             :                 }
     233             :             }
     234             :         }
     235             :     }
     236        2931 : }
     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