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

Generated by: LCOV version 1.10