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

Generated by: LCOV version 1.10