LCOV - code coverage report
Current view: top level - chart2/source/model/template - ScatterChartType.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 62 86 72.1 %
Date: 2012-08-25 Functions: 14 23 60.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 54 158 34.2 %

           Branch data     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 "ScatterChartType.hxx"
      21                 :            : #include "PropertyHelper.hxx"
      22                 :            : #include "macros.hxx"
      23                 :            : #include "servicenames_charttypes.hxx"
      24                 :            : #include "ContainerHelper.hxx"
      25                 :            : #include "CartesianCoordinateSystem.hxx"
      26                 :            : #include "AxisHelper.hxx"
      27                 :            : #include "AxisIndexDefines.hxx"
      28                 :            : #include <com/sun/star/beans/PropertyAttribute.hpp>
      29                 :            : #include <com/sun/star/chart2/AxisType.hpp>
      30                 :            : #include <com/sun/star/chart2/CurveStyle.hpp>
      31                 :            : 
      32                 :            : using namespace ::com::sun::star;
      33                 :            : 
      34                 :            : using ::rtl::OUString;
      35                 :            : using ::com::sun::star::beans::Property;
      36                 :            : using ::com::sun::star::uno::Sequence;
      37                 :            : using ::com::sun::star::uno::Reference;
      38                 :            : using ::com::sun::star::uno::Any;
      39                 :            : using ::osl::MutexGuard;
      40                 :            : 
      41                 :            : namespace
      42                 :            : {
      43                 :            : 
      44                 :            : enum
      45                 :            : {
      46                 :            :     PROP_SCATTERCHARTTYPE_CURVE_STYLE,
      47                 :            :     PROP_SCATTERCHARTTYPE_CURVE_RESOLUTION,
      48                 :            :     PROP_SCATTERCHARTTYPE_SPLINE_ORDER
      49                 :            : };
      50                 :            : 
      51                 :          2 : void lcl_AddPropertiesToVector(
      52                 :            :     ::std::vector< Property > & rOutProperties )
      53                 :            : {
      54                 :            :     rOutProperties.push_back(
      55                 :            :         Property( C2U( "CurveStyle" ),
      56                 :            :                   PROP_SCATTERCHARTTYPE_CURVE_STYLE,
      57         [ +  - ]:          2 :                   ::getCppuType( reinterpret_cast< const chart2::CurveStyle * >(0)),
      58                 :            :                   beans::PropertyAttribute::BOUND
      59 [ +  - ][ +  - ]:          2 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
      60                 :            : 
      61                 :            :     rOutProperties.push_back(
      62                 :            :         Property( C2U( "CurveResolution" ),
      63                 :            :                   PROP_SCATTERCHARTTYPE_CURVE_RESOLUTION,
      64         [ +  - ]:          2 :                   ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
      65                 :            :                   beans::PropertyAttribute::BOUND
      66 [ +  - ][ +  - ]:          2 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
      67                 :            :     rOutProperties.push_back(
      68                 :            :         Property( C2U( "SplineOrder" ),
      69                 :            :                   PROP_SCATTERCHARTTYPE_SPLINE_ORDER,
      70         [ +  - ]:          2 :                   ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
      71                 :            :                   beans::PropertyAttribute::BOUND
      72 [ +  - ][ +  - ]:          2 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
      73                 :          2 : }
      74                 :            : 
      75                 :            : struct StaticScatterChartTypeDefaults_Initializer
      76                 :            : {
      77                 :          2 :     ::chart::tPropertyValueMap* operator()()
      78                 :            :     {
      79 [ +  - ][ +  - ]:          2 :         static ::chart::tPropertyValueMap aStaticDefaults;
         [ +  - ][ #  # ]
      80                 :          2 :         lcl_AddDefaultsToMap( aStaticDefaults );
      81                 :          2 :         return &aStaticDefaults;
      82                 :            :     }
      83                 :            : private:
      84                 :          2 :     void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
      85                 :            :     {
      86         [ +  - ]:          2 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCATTERCHARTTYPE_CURVE_STYLE, chart2::CurveStyle_LINES );
      87         [ +  - ]:          2 :         ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_SCATTERCHARTTYPE_CURVE_RESOLUTION, 20 );
      88                 :            : 
      89                 :            :         // todo: check whether order 3 means polygons of order 3 or 2. (see
      90                 :            :         // http://www.people.nnov.ru/fractal/Splines/Basis.htm )
      91         [ +  - ]:          2 :         ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_SCATTERCHARTTYPE_SPLINE_ORDER, 3 );
      92                 :          2 :     }
      93                 :            : };
      94                 :            : 
      95                 :            : struct StaticScatterChartTypeDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticScatterChartTypeDefaults_Initializer >
      96                 :            : {
      97                 :            : };
      98                 :            : 
      99                 :            : struct StaticScatterChartTypeInfoHelper_Initializer
     100                 :            : {
     101                 :          2 :     ::cppu::OPropertyArrayHelper* operator()()
     102                 :            :     {
     103 [ +  - ][ +  - ]:          2 :         static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
         [ +  - ][ +  - ]
         [ +  - ][ #  # ]
     104                 :          2 :         return &aPropHelper;
     105                 :            :     }
     106                 :            : 
     107                 :            : private:
     108                 :          2 :     Sequence< Property > lcl_GetPropertySequence()
     109                 :            :     {
     110         [ +  - ]:          2 :         ::std::vector< ::com::sun::star::beans::Property > aProperties;
     111         [ +  - ]:          2 :         lcl_AddPropertiesToVector( aProperties );
     112                 :            : 
     113                 :            :         ::std::sort( aProperties.begin(), aProperties.end(),
     114         [ +  - ]:          2 :                      ::chart::PropertyNameLess() );
     115                 :            : 
     116         [ +  - ]:          2 :         return ::chart::ContainerHelper::ContainerToSequence( aProperties );
     117                 :            :     }
     118                 :            : 
     119                 :            : };
     120                 :            : 
     121                 :            : struct StaticScatterChartTypeInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticScatterChartTypeInfoHelper_Initializer >
     122                 :            : {
     123                 :            : };
     124                 :            : 
     125                 :            : struct StaticScatterChartTypeInfo_Initializer
     126                 :            : {
     127                 :          0 :     uno::Reference< beans::XPropertySetInfo >* operator()()
     128                 :            :     {
     129                 :            :         static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
     130 [ #  # ][ #  # ]:          0 :             ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticScatterChartTypeInfoHelper::get() ) );
         [ #  # ][ #  # ]
                 [ #  # ]
     131                 :          0 :         return &xPropertySetInfo;
     132                 :            :     }
     133                 :            : };
     134                 :            : 
     135                 :            : struct StaticScatterChartTypeInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticScatterChartTypeInfo_Initializer >
     136                 :            : {
     137                 :            : };
     138                 :            : 
     139                 :            : } // anonymous namespace
     140                 :            : 
     141                 :            : namespace chart
     142                 :            : {
     143                 :            : 
     144                 :        100 : ScatterChartType::ScatterChartType(
     145                 :            :     const uno::Reference< uno::XComponentContext > & xContext,
     146                 :            :     chart2::CurveStyle eCurveStyle /* chart2::CurveStyle_LINES */ ,
     147                 :            :     sal_Int32 nResolution /* = 20 */,
     148                 :            :     sal_Int32 nOrder /* = 3 */ ) :
     149                 :        100 :         ChartType( xContext )
     150                 :            : {
     151         [ -  + ]:        100 :     if( eCurveStyle != chart2::CurveStyle_LINES )
     152                 :            :         setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_CURVE_STYLE,
     153 [ #  # ][ #  # ]:          0 :                                           uno::makeAny( eCurveStyle ));
     154         [ -  + ]:        100 :     if( nResolution != 20 )
     155                 :            :         setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_CURVE_RESOLUTION,
     156 [ #  # ][ #  # ]:          0 :                                           uno::makeAny( nResolution ));
     157         [ -  + ]:        100 :     if( nOrder != 3 )
     158                 :            :         setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_SPLINE_ORDER,
     159 [ #  # ][ #  # ]:          0 :                                           uno::makeAny( nOrder ));
     160                 :        100 : }
     161                 :            : 
     162                 :          0 : ScatterChartType::ScatterChartType( const ScatterChartType & rOther ) :
     163                 :          0 :         ChartType( rOther )
     164                 :            : {
     165                 :          0 : }
     166                 :            : 
     167                 :        100 : ScatterChartType::~ScatterChartType()
     168         [ -  + ]:        200 : {}
     169                 :            : 
     170                 :            : // ____ XCloneable ____
     171                 :          0 : uno::Reference< util::XCloneable > SAL_CALL ScatterChartType::createClone()
     172                 :            :     throw (uno::RuntimeException)
     173                 :            : {
     174 [ #  # ][ #  # ]:          0 :     return uno::Reference< util::XCloneable >( new ScatterChartType( *this ));
     175                 :            : }
     176                 :            : 
     177                 :            : // ____ XChartType ____
     178                 :            : Reference< chart2::XCoordinateSystem > SAL_CALL
     179                 :          6 :     ScatterChartType::createCoordinateSystem( ::sal_Int32 DimensionCount )
     180                 :            :     throw (lang::IllegalArgumentException,
     181                 :            :            uno::RuntimeException)
     182                 :            : {
     183                 :            :     Reference< chart2::XCoordinateSystem > xResult(
     184                 :            :         new CartesianCoordinateSystem(
     185 [ +  - ][ +  - ]:          6 :             GetComponentContext(), DimensionCount, /* bSwapXAndYAxis */ sal_False ));
                 [ +  - ]
     186                 :            : 
     187         [ +  + ]:         18 :     for( sal_Int32 i=0; i<DimensionCount; ++i )
     188                 :            :     {
     189 [ +  - ][ +  - ]:         12 :         Reference< chart2::XAxis > xAxis( xResult->getAxisByDimension( i, MAIN_AXIS_INDEX ) );
     190         [ -  + ]:         12 :         if( !xAxis.is() )
     191                 :            :         {
     192                 :            :             OSL_FAIL("a created coordinate system should have an axis for each dimension");
     193                 :          0 :             continue;
     194                 :            :         }
     195                 :            : 
     196 [ +  - ][ +  - ]:         12 :         chart2::ScaleData aScaleData = xAxis->getScaleData();
     197                 :         12 :         aScaleData.Orientation = chart2::AxisOrientation_MATHEMATICAL;
     198 [ +  - ][ +  - ]:         12 :         aScaleData.Scaling = AxisHelper::createLinearScaling();
     199                 :            : 
     200         [ -  + ]:         12 :         if( i == 2  )
     201                 :          0 :             aScaleData.AxisType = chart2::AxisType::SERIES;
     202                 :            :         else
     203                 :         12 :             aScaleData.AxisType = chart2::AxisType::REALNUMBER;
     204                 :            : 
     205 [ +  - ][ +  - ]:         12 :         xAxis->setScaleData( aScaleData );
     206 [ +  - ][ +  - ]:         12 :     }
     207                 :            : 
     208                 :          6 :     return xResult;
     209                 :            : }
     210                 :            : 
     211                 :        400 : ::rtl::OUString SAL_CALL ScatterChartType::getChartType()
     212                 :            :     throw (uno::RuntimeException)
     213                 :            : {
     214                 :        400 :     return CHART2_SERVICE_NAME_CHARTTYPE_SCATTER;
     215                 :            : }
     216                 :            : 
     217                 :          0 : uno::Sequence< ::rtl::OUString > SAL_CALL ScatterChartType::getSupportedMandatoryRoles()
     218                 :            :     throw (uno::RuntimeException)
     219                 :            : {
     220                 :          0 :     uno::Sequence< ::rtl::OUString > aMandRolesSeq(3);
     221 [ #  # ][ #  # ]:          0 :     aMandRolesSeq[0] = C2U( "label" );
     222 [ #  # ][ #  # ]:          0 :     aMandRolesSeq[1] = C2U( "values-x" );
     223 [ #  # ][ #  # ]:          0 :     aMandRolesSeq[2] = C2U( "values-y" );
     224                 :          0 :     return aMandRolesSeq;
     225                 :            : }
     226                 :            : 
     227                 :          0 : uno::Sequence< ::rtl::OUString > SAL_CALL ScatterChartType::getSupportedOptionalRoles()
     228                 :            :     throw (uno::RuntimeException)
     229                 :            : {
     230                 :          0 :     return uno::Sequence< ::rtl::OUString >();
     231                 :            : }
     232                 :            : 
     233                 :            : 
     234                 :            : // ____ OPropertySet ____
     235                 :        318 : uno::Any ScatterChartType::GetDefaultValue( sal_Int32 nHandle ) const
     236                 :            :     throw(beans::UnknownPropertyException)
     237                 :            : {
     238         [ +  - ]:        318 :     const tPropertyValueMap& rStaticDefaults = *StaticScatterChartTypeDefaults::get();
     239         [ +  - ]:        318 :     tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
     240         [ -  + ]:        318 :     if( aFound == rStaticDefaults.end() )
     241                 :          0 :         return uno::Any();
     242                 :        318 :     return (*aFound).second;
     243                 :            : }
     244                 :            : 
     245                 :            : // ____ OPropertySet ____
     246                 :        636 : ::cppu::IPropertyArrayHelper & SAL_CALL ScatterChartType::getInfoHelper()
     247                 :            : {
     248                 :        636 :     return *StaticScatterChartTypeInfoHelper::get();
     249                 :            : }
     250                 :            : 
     251                 :            : // ____ XPropertySet ____
     252                 :          0 : uno::Reference< beans::XPropertySetInfo > SAL_CALL ScatterChartType::getPropertySetInfo()
     253                 :            :     throw (uno::RuntimeException)
     254                 :            : {
     255                 :          0 :     return *StaticScatterChartTypeInfo::get();
     256                 :            : }
     257                 :            : 
     258                 :          2 : uno::Sequence< ::rtl::OUString > ScatterChartType::getSupportedServiceNames_Static()
     259                 :            : {
     260                 :          2 :     uno::Sequence< ::rtl::OUString > aServices( 3 );
     261 [ +  - ][ +  - ]:          2 :     aServices[ 0 ] = CHART2_SERVICE_NAME_CHARTTYPE_SCATTER;
     262 [ +  - ][ +  - ]:          2 :     aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartType" );
     263 [ +  - ][ +  - ]:          2 :     aServices[ 2 ] = C2U( "com.sun.star.beans.PropertySet" );
     264                 :          2 :     return aServices;
     265                 :            : }
     266                 :            : 
     267                 :            : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     268 [ #  # ][ #  # ]:         77 : APPHELPER_XSERVICEINFO_IMPL( ScatterChartType,
         [ #  # ][ #  # ]
                 [ #  # ]
     269                 :            :                              C2U( "com.sun.star.comp.chart.ScatterChartType" ));
     270                 :            : 
     271                 :            : } //  namespace chart
     272                 :            : 
     273                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10