LCOV - code coverage report
Current view: top level - chart2/source/model/template - LineChartTypeTemplate.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 117 133 88.0 %
Date: 2014-04-11 Functions: 19 23 82.6 %
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 "LineChartTypeTemplate.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 <unonames.hxx>
      28             : 
      29             : #include <com/sun/star/chart2/SymbolStyle.hpp>
      30             : #include <com/sun/star/chart2/Symbol.hpp>
      31             : #include <com/sun/star/drawing/LineStyle.hpp>
      32             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      33             : 
      34             : #include <algorithm>
      35             : 
      36             : using namespace ::com::sun::star;
      37             : 
      38             : using ::com::sun::star::uno::Reference;
      39             : using ::com::sun::star::uno::Sequence;
      40             : using ::com::sun::star::beans::Property;
      41             : using ::com::sun::star::uno::Any;
      42             : using ::osl::MutexGuard;
      43             : 
      44             : namespace
      45             : {
      46             : 
      47             : enum
      48             : {
      49             :     PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE,
      50             :     PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION,
      51             :     PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER
      52             : 
      53             : };
      54             : 
      55           5 : void lcl_AddPropertiesToVector(
      56             :     ::std::vector< Property > & rOutProperties )
      57             : {
      58             :     rOutProperties.push_back(
      59             :         Property( CHART_UNONAME_CURVE_STYLE,
      60             :                   PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE,
      61           5 :                   ::getCppuType( reinterpret_cast< const chart2::CurveStyle * >(0)),
      62             :                   beans::PropertyAttribute::BOUND
      63          10 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
      64             :     rOutProperties.push_back(
      65             :         Property( CHART_UNONAME_CURVE_RESOLUTION,
      66             :                   PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION,
      67           5 :                   ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
      68             :                   beans::PropertyAttribute::BOUND
      69          10 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
      70             :     rOutProperties.push_back(
      71             :         Property( CHART_UNONAME_SPLINE_ORDER,
      72             :                   PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER,
      73           5 :                   ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
      74             :                   beans::PropertyAttribute::BOUND
      75          10 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
      76           5 : }
      77             : 
      78             : struct StaticLineChartTypeTemplateDefaults_Initializer
      79             : {
      80           5 :     ::chart::tPropertyValueMap* operator()()
      81             :     {
      82           5 :         static ::chart::tPropertyValueMap aStaticDefaults;
      83           5 :         lcl_AddDefaultsToMap( aStaticDefaults );
      84           5 :         return &aStaticDefaults;
      85             :     }
      86             : private:
      87           5 :     void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
      88             :     {
      89           5 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE, chart2::CurveStyle_LINES );
      90           5 :         ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION, 20 );
      91             : 
      92             :         // todo: check whether order 3 means polygons of order 3 or 2. (see
      93             :         // http://www.people.nnov.ru/fractal/Splines/Basis.htm )
      94           5 :         ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER, 3 );
      95           5 :     }
      96             : };
      97             : 
      98             : struct StaticLineChartTypeTemplateDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticLineChartTypeTemplateDefaults_Initializer >
      99             : {
     100             : };
     101             : 
     102             : struct StaticLineChartTypeTemplateInfoHelper_Initializer
     103             : {
     104           5 :     ::cppu::OPropertyArrayHelper* operator()()
     105             :     {
     106           5 :         static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
     107           5 :         return &aPropHelper;
     108             :     }
     109             : 
     110             : private:
     111           5 :     Sequence< Property > lcl_GetPropertySequence()
     112             :     {
     113           5 :         ::std::vector< ::com::sun::star::beans::Property > aProperties;
     114           5 :         lcl_AddPropertiesToVector( aProperties );
     115             : 
     116             :         ::std::sort( aProperties.begin(), aProperties.end(),
     117           5 :                      ::chart::PropertyNameLess() );
     118             : 
     119           5 :         return ::chart::ContainerHelper::ContainerToSequence( aProperties );
     120             :     }
     121             : 
     122             : };
     123             : 
     124             : struct StaticLineChartTypeTemplateInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticLineChartTypeTemplateInfoHelper_Initializer >
     125             : {
     126             : };
     127             : 
     128             : struct StaticLineChartTypeTemplateInfo_Initializer
     129             : {
     130           0 :     uno::Reference< beans::XPropertySetInfo >* operator()()
     131             :     {
     132             :         static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
     133           0 :             ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticLineChartTypeTemplateInfoHelper::get() ) );
     134           0 :         return &xPropertySetInfo;
     135             :     }
     136             : };
     137             : 
     138             : struct StaticLineChartTypeTemplateInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticLineChartTypeTemplateInfo_Initializer >
     139             : {
     140             : };
     141             : 
     142             : } // anonymous namespace
     143             : 
     144             : namespace chart
     145             : {
     146             : 
     147       11225 : LineChartTypeTemplate::LineChartTypeTemplate(
     148             :     uno::Reference<
     149             :         uno::XComponentContext > const & xContext,
     150             :     const OUString & rServiceName,
     151             :     StackMode eStackMode,
     152             :     bool bSymbols,
     153             :     bool bHasLines /* = true */,
     154             :     sal_Int32 nDim /* = 2 */ ) :
     155             :         ChartTypeTemplate( xContext, rServiceName ),
     156             :         ::property::OPropertySet( m_aMutex ),
     157             :         m_eStackMode( eStackMode ),
     158             :         m_bHasSymbols( bSymbols ),
     159             :         m_bHasLines( bHasLines ),
     160       11225 :         m_nDim( nDim )
     161             : {
     162       11225 :     if( nDim == 3 )
     163        2044 :         m_bHasSymbols = false;
     164       11225 : }
     165             : 
     166       22450 : LineChartTypeTemplate::~LineChartTypeTemplate()
     167       22450 : {}
     168             : // ____ OPropertySet ____
     169       34143 : uno::Any LineChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle ) const
     170             :     throw(beans::UnknownPropertyException)
     171             : {
     172       34143 :     const tPropertyValueMap& rStaticDefaults = *StaticLineChartTypeTemplateDefaults::get();
     173       34143 :     tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
     174       34143 :     if( aFound == rStaticDefaults.end() )
     175           0 :         return uno::Any();
     176       34143 :     return (*aFound).second;
     177             : }
     178             : 
     179       33897 : ::cppu::IPropertyArrayHelper & SAL_CALL LineChartTypeTemplate::getInfoHelper()
     180             : {
     181       33897 :     return *StaticLineChartTypeTemplateInfoHelper::get();
     182             : }
     183             : 
     184             : // ____ XPropertySet ____
     185           0 : uno::Reference< beans::XPropertySetInfo > SAL_CALL LineChartTypeTemplate::getPropertySetInfo()
     186             :     throw (uno::RuntimeException, std::exception)
     187             : {
     188           0 :     return *StaticLineChartTypeTemplateInfo::get();
     189             : }
     190             : 
     191       11284 : sal_Int32 LineChartTypeTemplate::getDimension() const
     192             : {
     193       11284 :     return m_nDim;
     194             : }
     195             : 
     196         366 : StackMode LineChartTypeTemplate::getStackMode( sal_Int32 /* nChartTypeIndex */ ) const
     197             : {
     198         366 :     return m_eStackMode;
     199             : }
     200             : 
     201             : // ____ XChartTypeTemplate ____
     202       11210 : sal_Bool SAL_CALL LineChartTypeTemplate::matchesTemplate(
     203             :     const uno::Reference< chart2::XDiagram >& xDiagram,
     204             :     sal_Bool bAdaptProperties )
     205             :     throw (uno::RuntimeException, std::exception)
     206             : {
     207       11210 :     sal_Bool bResult = ChartTypeTemplate::matchesTemplate( xDiagram, bAdaptProperties );
     208             : 
     209             :     // check symbol-style and line-style
     210             :     // for a template with symbols (or with lines) it is ok, if there is at least one series
     211             :     // with symbols (or with lines)
     212       11210 :     if( bResult )
     213             :     {
     214         128 :         bool bSymbolFound = false;
     215         128 :         bool bLineFound = false;
     216             : 
     217             :         ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec(
     218         128 :             DiagramHelper::getDataSeriesFromDiagram( xDiagram ));
     219             : 
     220        1095 :         for( ::std::vector< Reference< chart2::XDataSeries > >::const_iterator aIt =
     221         858 :                  aSeriesVec.begin(); aIt != aSeriesVec.end(); ++aIt )
     222             :         {
     223             :             try
     224             :             {
     225         274 :                 chart2::Symbol aSymbProp;
     226             :                 drawing::LineStyle eLineStyle;
     227         511 :                 Reference< beans::XPropertySet > xProp( *aIt, uno::UNO_QUERY_THROW );
     228             : 
     229        1096 :                 bool bCurrentHasSymbol = (xProp->getPropertyValue( "Symbol") >>= aSymbProp) &&
     230         548 :                     (aSymbProp.Style != chart2::SymbolStyle_NONE);
     231             : 
     232         274 :                 if( bCurrentHasSymbol )
     233         138 :                     bSymbolFound = true;
     234             : 
     235         274 :                 if( bCurrentHasSymbol && (!m_bHasSymbols) )
     236             :                 {
     237          37 :                     bResult = false;
     238          37 :                     break;
     239             :                 }
     240             : 
     241         948 :                 bool bCurrentHasLine = (xProp->getPropertyValue( "LineStyle") >>= eLineStyle) &&
     242         474 :                     ( eLineStyle != drawing::LineStyle_NONE );
     243             : 
     244         237 :                 if( bCurrentHasLine )
     245         219 :                     bLineFound = true;
     246             : 
     247         237 :                 if( bCurrentHasLine && (!m_bHasLines) )
     248             :                 {
     249           0 :                     bResult = false;
     250           0 :                     break;
     251         237 :                 }
     252             :             }
     253           0 :             catch( const uno::Exception & ex )
     254             :             {
     255             :                 ASSERT_EXCEPTION( ex );
     256             :             }
     257             :         }
     258             : 
     259         128 :         if(bResult)
     260             :         {
     261          91 :             if( !bLineFound && m_bHasLines && bSymbolFound )
     262           9 :                 bResult = false;
     263          82 :             else if( !bSymbolFound && m_bHasSymbols && bLineFound )
     264           0 :                 bResult = false;
     265          82 :             else if( !bLineFound && !bSymbolFound )
     266           0 :                 return m_bHasLines && m_bHasSymbols;
     267         128 :         }
     268             :     }
     269             : 
     270             :     // adapt curve style, spline order and resolution
     271       11210 :     if( bResult && bAdaptProperties )
     272             :     {
     273             :         try
     274             :         {
     275             :             uno::Reference< beans::XPropertySet > xChartTypeProp(
     276             :                 DiagramHelper::getChartTypeByIndex( xDiagram, 0 ),
     277          82 :                 uno::UNO_QUERY_THROW );
     278          82 :             setFastPropertyValue_NoBroadcast( PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE, xChartTypeProp->getPropertyValue(CHART_UNONAME_CURVE_STYLE) );
     279          82 :             setFastPropertyValue_NoBroadcast( PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION, xChartTypeProp->getPropertyValue(CHART_UNONAME_CURVE_RESOLUTION) );
     280          82 :             setFastPropertyValue_NoBroadcast( PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER, xChartTypeProp->getPropertyValue(CHART_UNONAME_SPLINE_ORDER) );
     281             :         }
     282           0 :         catch( const uno::Exception & ex )
     283             :         {
     284             :             ASSERT_EXCEPTION( ex );
     285             :         }
     286             :     }
     287             : 
     288       11210 :     return bResult;
     289             : }
     290             : 
     291          44 : Reference< chart2::XChartType > LineChartTypeTemplate::getChartTypeForIndex( sal_Int32 /*nChartTypeIndex*/ )
     292             : {
     293          44 :     Reference< chart2::XChartType > xResult;
     294             : 
     295             :     try
     296             :     {
     297             :         Reference< lang::XMultiServiceFactory > xFact(
     298          44 :             GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW );
     299          44 :         xResult.set( xFact->createInstance(
     300          44 :                          CHART2_SERVICE_NAME_CHARTTYPE_LINE ), uno::UNO_QUERY_THROW );
     301             : 
     302          88 :         Reference< beans::XPropertySet > xCTProp( xResult, uno::UNO_QUERY );
     303          44 :         if( xCTProp.is())
     304             :         {
     305          44 :             xCTProp->setPropertyValue(
     306          44 :                 CHART_UNONAME_CURVE_STYLE, getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE ));
     307          44 :             xCTProp->setPropertyValue(
     308          44 :                 CHART_UNONAME_CURVE_RESOLUTION, getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION ));
     309          44 :             xCTProp->setPropertyValue(
     310          44 :                 CHART_UNONAME_SPLINE_ORDER, getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER ));
     311          44 :         }
     312             :     }
     313           0 :     catch( const uno::Exception & ex )
     314             :     {
     315             :         ASSERT_EXCEPTION( ex );
     316             :     }
     317             : 
     318          44 :     return xResult;
     319             : }
     320             : 
     321       11255 : Reference< chart2::XChartType > SAL_CALL LineChartTypeTemplate::getChartTypeForNewSeries(
     322             :         const uno::Sequence< Reference< chart2::XChartType > >& aFormerlyUsedChartTypes )
     323             :     throw (uno::RuntimeException, std::exception)
     324             : {
     325       11255 :     Reference< chart2::XChartType > xResult;
     326             : 
     327             :     try
     328             :     {
     329             :         Reference< lang::XMultiServiceFactory > xFact(
     330       11255 :             GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW );
     331       11255 :         xResult.set( xFact->createInstance(
     332       11255 :                          CHART2_SERVICE_NAME_CHARTTYPE_LINE ), uno::UNO_QUERY_THROW );
     333             : 
     334       11255 :         ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aFormerlyUsedChartTypes, xResult );
     335             : 
     336       22510 :         Reference< beans::XPropertySet > xCTProp( xResult, uno::UNO_QUERY );
     337       11255 :         if( xCTProp.is())
     338             :         {
     339       11255 :             xCTProp->setPropertyValue(
     340       11255 :                 CHART_UNONAME_CURVE_STYLE, getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE ));
     341       11255 :             xCTProp->setPropertyValue(
     342       11255 :                 CHART_UNONAME_CURVE_RESOLUTION, getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION ));
     343       11255 :             xCTProp->setPropertyValue(
     344       11255 :                 CHART_UNONAME_SPLINE_ORDER, getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER ));
     345       11255 :         }
     346             :     }
     347           0 :     catch( const uno::Exception & ex )
     348             :     {
     349             :         ASSERT_EXCEPTION( ex );
     350             :     }
     351             : 
     352       11255 :     return xResult;
     353             : }
     354             : 
     355          29 : void SAL_CALL LineChartTypeTemplate::applyStyle(
     356             :     const Reference< chart2::XDataSeries >& xSeries,
     357             :     ::sal_Int32 nChartTypeIndex,
     358             :     ::sal_Int32 nSeriesIndex,
     359             :     ::sal_Int32 nSeriesCount )
     360             :     throw (uno::RuntimeException, std::exception)
     361             : {
     362          29 :     ChartTypeTemplate::applyStyle( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount );
     363             : 
     364             :     try
     365             :     {
     366          29 :         Reference< beans::XPropertySet > xProp( xSeries, uno::UNO_QUERY_THROW );
     367             : 
     368          29 :         DataSeriesHelper::switchSymbolsOnOrOff( xProp, m_bHasSymbols, nSeriesIndex );
     369          29 :         DataSeriesHelper::switchLinesOnOrOff( xProp, m_bHasLines );
     370          29 :         DataSeriesHelper::makeLinesThickOrThin( xProp, m_nDim==2 );
     371             :     }
     372           0 :     catch( const uno::Exception & ex )
     373             :     {
     374             :         ASSERT_EXCEPTION( ex );
     375             :     }
     376          29 : }
     377             : 
     378       89966 : IMPLEMENT_FORWARD_XINTERFACE2( LineChartTypeTemplate, ChartTypeTemplate, OPropertySet )
     379           0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( LineChartTypeTemplate, ChartTypeTemplate, OPropertySet )
     380             : 
     381             : } //  namespace chart
     382             : 
     383             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10