LCOV - code coverage report
Current view: top level - chart2/source/model/template - BarChartTypeTemplate.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 80 109 73.4 %
Date: 2014-04-11 Functions: 18 26 69.2 %
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 "BarChartTypeTemplate.hxx"
      21             : #include "macros.hxx"
      22             : #include "DiagramHelper.hxx"
      23             : #include "servicenames_charttypes.hxx"
      24             : #include "ContainerHelper.hxx"
      25             : #include "DataSeriesHelper.hxx"
      26             : #include "PropertyHelper.hxx"
      27             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      28             : #include <com/sun/star/drawing/LineStyle.hpp>
      29             : #include <com/sun/star/chart2/DataPointGeometry3D.hpp>
      30             : 
      31             : #include <algorithm>
      32             : 
      33             : using namespace ::com::sun::star;
      34             : 
      35             : using ::com::sun::star::uno::Reference;
      36             : using ::com::sun::star::uno::Sequence;
      37             : using ::com::sun::star::beans::Property;
      38             : using ::osl::MutexGuard;
      39             : 
      40             : namespace
      41             : {
      42             : 
      43             : enum
      44             : {
      45             :     PROP_BAR_TEMPLATE_DIMENSION,
      46             :     PROP_BAR_TEMPLATE_GEOMETRY3D
      47             : };
      48             : 
      49           0 : void lcl_AddPropertiesToVector(
      50             :     ::std::vector< Property > & rOutProperties )
      51             : {
      52             :     rOutProperties.push_back(
      53             :         Property( "Dimension",
      54             :                   PROP_BAR_TEMPLATE_DIMENSION,
      55           0 :                   ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
      56             :                   beans::PropertyAttribute::BOUND
      57           0 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
      58             :     rOutProperties.push_back(
      59             :         Property( "Geometry3D",
      60             :                   PROP_BAR_TEMPLATE_GEOMETRY3D,
      61           0 :                   ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
      62             :                   beans::PropertyAttribute::BOUND
      63           0 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
      64           0 : }
      65             : 
      66             : struct StaticBarChartTypeTemplateDefaults_Initializer
      67             : {
      68           3 :     ::chart::tPropertyValueMap* operator()()
      69             :     {
      70           3 :         static ::chart::tPropertyValueMap aStaticDefaults;
      71           3 :         lcl_AddDefaultsToMap( aStaticDefaults );
      72           3 :         return &aStaticDefaults;
      73             :     }
      74             : private:
      75           3 :     void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
      76             :     {
      77           3 :         ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_BAR_TEMPLATE_DIMENSION, 2 );
      78           3 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_BAR_TEMPLATE_GEOMETRY3D, ::chart2::DataPointGeometry3D::CUBOID );
      79           3 :     }
      80             : };
      81             : 
      82             : struct StaticBarChartTypeTemplateDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticBarChartTypeTemplateDefaults_Initializer >
      83             : {
      84             : };
      85             : 
      86             : struct StaticBarChartTypeTemplateInfoHelper_Initializer
      87             : {
      88           0 :     ::cppu::OPropertyArrayHelper* operator()()
      89             :     {
      90           0 :         static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
      91           0 :         return &aPropHelper;
      92             :     }
      93             : 
      94             : private:
      95           0 :     Sequence< Property > lcl_GetPropertySequence()
      96             :     {
      97           0 :         ::std::vector< ::com::sun::star::beans::Property > aProperties;
      98           0 :         lcl_AddPropertiesToVector( aProperties );
      99             : 
     100             :         ::std::sort( aProperties.begin(), aProperties.end(),
     101           0 :                      ::chart::PropertyNameLess() );
     102             : 
     103           0 :         return ::chart::ContainerHelper::ContainerToSequence( aProperties );
     104             :     }
     105             : 
     106             : };
     107             : 
     108             : struct StaticBarChartTypeTemplateInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticBarChartTypeTemplateInfoHelper_Initializer >
     109             : {
     110             : };
     111             : 
     112             : struct StaticBarChartTypeTemplateInfo_Initializer
     113             : {
     114           0 :     uno::Reference< beans::XPropertySetInfo >* operator()()
     115             :     {
     116             :         static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
     117           0 :             ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticBarChartTypeTemplateInfoHelper::get() ) );
     118           0 :         return &xPropertySetInfo;
     119             :     }
     120             : };
     121             : 
     122             : struct StaticBarChartTypeTemplateInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticBarChartTypeTemplateInfo_Initializer >
     123             : {
     124             : };
     125             : 
     126             : } // anonymous namespace
     127             : 
     128             : namespace chart
     129             : {
     130             : 
     131       13356 : BarChartTypeTemplate::BarChartTypeTemplate(
     132             :     Reference<
     133             :         uno::XComponentContext > const & xContext,
     134             :     const OUString & rServiceName,
     135             :     StackMode eStackMode,
     136             :     BarDirection eDirection,
     137             :     sal_Int32 nDim         /* = 2 */ ) :
     138             :         ChartTypeTemplate( xContext, rServiceName ),
     139             :         ::property::OPropertySet( m_aMutex ),
     140             :         m_eStackMode( eStackMode ),
     141             :         m_eBarDirection( eDirection ),
     142       13356 :         m_nDim( nDim )
     143       13356 : {}
     144             : 
     145       26712 : BarChartTypeTemplate::~BarChartTypeTemplate()
     146       26712 : {}
     147             : 
     148       15842 : sal_Int32 BarChartTypeTemplate::getDimension() const
     149             : {
     150       15842 :     return m_nDim;
     151             : }
     152             : 
     153        5658 : StackMode BarChartTypeTemplate::getStackMode( sal_Int32 /* nChartTypeIndex */ ) const
     154             : {
     155        5658 :     return m_eStackMode;
     156             : }
     157             : 
     158         556 : bool BarChartTypeTemplate::isSwapXAndY() const
     159             : {
     160         556 :     return (m_eBarDirection == HORIZONTAL);
     161             : }
     162             : 
     163             : // ____ XChartTypeTemplate ____
     164       13178 : sal_Bool SAL_CALL BarChartTypeTemplate::matchesTemplate(
     165             :     const Reference< chart2::XDiagram >& xDiagram,
     166             :     sal_Bool bAdaptProperties )
     167             :     throw (uno::RuntimeException, std::exception)
     168             : {
     169       13178 :     sal_Bool bResult = ChartTypeTemplate::matchesTemplate( xDiagram, bAdaptProperties );
     170             : 
     171             :     //check BarDirection
     172       13178 :     if( bResult )
     173             :     {
     174        1748 :         bool bFound = false;
     175        1748 :         bool bAmbiguous = false;
     176        1748 :         bool bVertical = DiagramHelper::getVertical( xDiagram, bFound, bAmbiguous );
     177        1748 :         if( m_eBarDirection == HORIZONTAL )
     178        1018 :             bResult = sal_Bool( bVertical );
     179         730 :         else if( m_eBarDirection == VERTICAL )
     180         730 :             bResult = sal_Bool( !bVertical );
     181             :     }
     182             : 
     183             :     // adapt solid-type of template according to values in series
     184       26356 :     if( bAdaptProperties &&
     185       14196 :         bResult &&
     186        1018 :         getDimension() == 3 )
     187             :     {
     188             : 
     189         662 :         bool bGeomFound = false, bGeomAmbiguous = false;
     190         662 :         sal_Int32 aCommonGeom = DiagramHelper::getGeometry3D( xDiagram, bGeomFound, bGeomAmbiguous );
     191             : 
     192         662 :         if( !bGeomAmbiguous )
     193             :         {
     194             :             setFastPropertyValue_NoBroadcast(
     195         662 :                 PROP_BAR_TEMPLATE_GEOMETRY3D, uno::makeAny( aCommonGeom ));
     196             :         }
     197             :     }
     198             : 
     199       13178 :     return bResult;
     200             : }
     201       14382 : Reference< chart2::XChartType > BarChartTypeTemplate::getChartTypeForIndex( sal_Int32 /*nChartTypeIndex*/ )
     202             : {
     203       14382 :     Reference< chart2::XChartType > xResult;
     204             : 
     205             :     try
     206             :     {
     207             :         Reference< lang::XMultiServiceFactory > xFact(
     208       14382 :             GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW );
     209       14382 :         xResult.set( xFact->createInstance(
     210       14382 :                          CHART2_SERVICE_NAME_CHARTTYPE_COLUMN ), uno::UNO_QUERY_THROW );
     211             :     }
     212           0 :     catch( const uno::Exception & ex )
     213             :     {
     214             :         ASSERT_EXCEPTION( ex );
     215             :     }
     216             : 
     217       14382 :     return xResult;
     218             : }
     219             : 
     220       13712 : Reference< chart2::XChartType > SAL_CALL BarChartTypeTemplate::getChartTypeForNewSeries(
     221             :         const uno::Sequence< Reference< chart2::XChartType > >& aFormerlyUsedChartTypes )
     222             :     throw (uno::RuntimeException, std::exception)
     223             : {
     224       13712 :     Reference< chart2::XChartType > xResult( getChartTypeForIndex( 0 ) );
     225       13712 :     ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aFormerlyUsedChartTypes, xResult );
     226       13712 :     return xResult;
     227             : }
     228             : 
     229             : // ____ OPropertySet ____
     230         662 : uno::Any BarChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle ) const
     231             :     throw(beans::UnknownPropertyException)
     232             : {
     233         662 :     const tPropertyValueMap& rStaticDefaults = *StaticBarChartTypeTemplateDefaults::get();
     234         662 :     tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
     235         662 :     if( aFound == rStaticDefaults.end() )
     236           0 :         return uno::Any();
     237         662 :     return (*aFound).second;
     238             : }
     239             : 
     240           0 : ::cppu::IPropertyArrayHelper & SAL_CALL BarChartTypeTemplate::getInfoHelper()
     241             : {
     242           0 :     return *StaticBarChartTypeTemplateInfoHelper::get();
     243             : }
     244             : 
     245             : // ____ XPropertySet ____
     246           0 : Reference< beans::XPropertySetInfo > SAL_CALL BarChartTypeTemplate::getPropertySetInfo()
     247             :     throw (uno::RuntimeException, std::exception)
     248             : {
     249           0 :     return *StaticBarChartTypeTemplateInfo::get();
     250             : }
     251             : 
     252         492 : void SAL_CALL BarChartTypeTemplate::applyStyle(
     253             :     const Reference< chart2::XDataSeries >& xSeries,
     254             :     ::sal_Int32 nChartTypeIndex,
     255             :     ::sal_Int32 nSeriesIndex,
     256             :     ::sal_Int32 nSeriesCount )
     257             :     throw (uno::RuntimeException, std::exception)
     258             : {
     259         492 :     ChartTypeTemplate::applyStyle( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount );
     260         492 :     DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, "BorderStyle", uno::makeAny( drawing::LineStyle_NONE ) );
     261         492 :     if( getDimension() == 3 )
     262             :     {
     263             :         try
     264             :         {
     265             :             //apply Geometry3D
     266           0 :             uno::Any aAGeometry3D;
     267           0 :             this->getFastPropertyValue( aAGeometry3D, PROP_BAR_TEMPLATE_GEOMETRY3D );
     268           0 :             DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, "Geometry3D", aAGeometry3D );
     269             :         }
     270           0 :         catch( const uno::Exception & ex )
     271             :         {
     272             :             ASSERT_EXCEPTION( ex );
     273             :         }
     274             :     }
     275         492 : }
     276             : 
     277           8 : void SAL_CALL BarChartTypeTemplate::resetStyles(
     278             :     const Reference< chart2::XDiagram >& xDiagram )
     279             :     throw (uno::RuntimeException, std::exception)
     280             : {
     281           8 :     ChartTypeTemplate::resetStyles( xDiagram );
     282             :     ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec(
     283           8 :         DiagramHelper::getDataSeriesFromDiagram( xDiagram ));
     284          16 :     uno::Any aLineStyleAny( uno::makeAny( drawing::LineStyle_NONE ));
     285         216 :     for( ::std::vector< Reference< chart2::XDataSeries > >::iterator aIt( aSeriesVec.begin());
     286         144 :          aIt != aSeriesVec.end(); ++aIt )
     287             :     {
     288          64 :         Reference< beans::XPropertyState > xState( *aIt, uno::UNO_QUERY );
     289          64 :         if( xState.is())
     290             :         {
     291          64 :             if( getDimension() == 3 )
     292           0 :                 xState->setPropertyToDefault( "Geometry3D");
     293          64 :             Reference< beans::XPropertySet > xProp( xState, uno::UNO_QUERY );
     294         256 :             if( xProp.is() &&
     295         256 :                 xProp->getPropertyValue( "BorderStyle") == aLineStyleAny )
     296             :             {
     297          61 :                 xState->setPropertyToDefault( "BorderStyle");
     298          64 :             }
     299             :         }
     300          64 :     }
     301             : 
     302          16 :     DiagramHelper::setVertical( xDiagram, false );
     303           8 : }
     304             : 
     305         178 : void BarChartTypeTemplate::createCoordinateSystems(
     306             :     const Reference< chart2::XCoordinateSystemContainer > & xCooSysCnt )
     307             : {
     308         178 :     ChartTypeTemplate::createCoordinateSystems( xCooSysCnt );
     309             : 
     310         178 :     Reference< chart2::XDiagram > xDiagram( xCooSysCnt, uno::UNO_QUERY );
     311         178 :     DiagramHelper::setVertical( xDiagram, m_eBarDirection == HORIZONTAL );
     312         178 : }
     313             : 
     314      108926 : IMPLEMENT_FORWARD_XINTERFACE2( BarChartTypeTemplate, ChartTypeTemplate, OPropertySet )
     315           0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( BarChartTypeTemplate, ChartTypeTemplate, OPropertySet )
     316             : 
     317             : } //  namespace chart
     318             : 
     319             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10