LCOV - code coverage report
Current view: top level - chart2/source/model/template - PieChartType.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 69 77 89.6 %
Date: 2014-04-11 Functions: 17 22 77.3 %
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 "PieChartType.hxx"
      21             : #include "PropertyHelper.hxx"
      22             : #include "macros.hxx"
      23             : #include "PolarCoordinateSystem.hxx"
      24             : #include "AxisHelper.hxx"
      25             : #include "servicenames_charttypes.hxx"
      26             : #include "ContainerHelper.hxx"
      27             : #include "AxisIndexDefines.hxx"
      28             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      29             : #include <com/sun/star/chart2/AxisType.hpp>
      30             : 
      31             : using namespace ::com::sun::star;
      32             : 
      33             : using ::com::sun::star::beans::Property;
      34             : using ::com::sun::star::uno::Sequence;
      35             : using ::com::sun::star::uno::Reference;
      36             : using ::com::sun::star::uno::Any;
      37             : using ::osl::MutexGuard;
      38             : 
      39             : namespace
      40             : {
      41             : 
      42             : enum
      43             : {
      44             :     PROP_PIECHARTTYPE_USE_RINGS,
      45             :     PROP_PIECHARTTYPE_3DRELATIVEHEIGHT
      46             : };
      47             : 
      48           6 : static void lcl_AddPropertiesToVector(
      49             :     ::std::vector< Property > & rOutProperties )
      50             : {
      51             :     rOutProperties.push_back(
      52             :         Property( "UseRings",
      53             :                   PROP_PIECHARTTYPE_USE_RINGS,
      54           6 :                   ::getBooleanCppuType(),
      55             :                   beans::PropertyAttribute::BOUND
      56          12 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
      57             :     rOutProperties.push_back(
      58             :         Property( "3DRelativeHeight",
      59             :                   PROP_PIECHARTTYPE_3DRELATIVEHEIGHT,
      60           6 :                   ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
      61           6 :                   beans::PropertyAttribute::MAYBEVOID ));
      62           6 : }
      63             : 
      64             : struct StaticPieChartTypeDefaults_Initializer
      65             : {
      66           6 :     ::chart::tPropertyValueMap* operator()()
      67             :     {
      68           6 :         static ::chart::tPropertyValueMap aStaticDefaults;
      69           6 :         lcl_AddDefaultsToMap( aStaticDefaults );
      70           6 :         return &aStaticDefaults;
      71             :     }
      72             : private:
      73           6 :     void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
      74             :     {
      75           6 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_PIECHARTTYPE_USE_RINGS, false );
      76           6 :         ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_PIECHARTTYPE_3DRELATIVEHEIGHT, 100 );
      77           6 :     }
      78             : };
      79             : 
      80             : struct StaticPieChartTypeDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticPieChartTypeDefaults_Initializer >
      81             : {
      82             : };
      83             : 
      84             : struct StaticPieChartTypeInfoHelper_Initializer
      85             : {
      86           6 :     ::cppu::OPropertyArrayHelper* operator()()
      87             :     {
      88           6 :         static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
      89           6 :         return &aPropHelper;
      90             :     }
      91             : 
      92             : private:
      93           6 :     Sequence< Property > lcl_GetPropertySequence()
      94             :     {
      95           6 :         ::std::vector< ::com::sun::star::beans::Property > aProperties;
      96           6 :         lcl_AddPropertiesToVector( aProperties );
      97             : 
      98             :         ::std::sort( aProperties.begin(), aProperties.end(),
      99           6 :                      ::chart::PropertyNameLess() );
     100             : 
     101           6 :         return ::chart::ContainerHelper::ContainerToSequence( aProperties );
     102             :     }
     103             : 
     104             : };
     105             : 
     106             : struct StaticPieChartTypeInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticPieChartTypeInfoHelper_Initializer >
     107             : {
     108             : };
     109             : 
     110             : struct StaticPieChartTypeInfo_Initializer
     111             : {
     112           3 :     uno::Reference< beans::XPropertySetInfo >* operator()()
     113             :     {
     114             :         static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
     115           3 :             ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticPieChartTypeInfoHelper::get() ) );
     116           3 :         return &xPropertySetInfo;
     117             :     }
     118             : };
     119             : 
     120             : struct StaticPieChartTypeInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticPieChartTypeInfo_Initializer >
     121             : {
     122             : };
     123             : 
     124             : } // anonymous namespace
     125             : 
     126             : namespace chart
     127             : {
     128             : 
     129        5360 : PieChartType::PieChartType(
     130             :     const uno::Reference< uno::XComponentContext > & xContext,
     131             :     sal_Bool bUseRings  /* = sal_False */) :
     132        5360 :         ChartType( xContext )
     133             : {
     134        5360 :     if( bUseRings )
     135           0 :         setFastPropertyValue_NoBroadcast( PROP_PIECHARTTYPE_USE_RINGS, uno::makeAny( bUseRings ));
     136        5360 : }
     137             : 
     138           0 : PieChartType::PieChartType( const PieChartType & rOther ) :
     139           0 :         ChartType( rOther )
     140             : {
     141           0 : }
     142             : 
     143       10720 : PieChartType::~PieChartType()
     144       10720 : {}
     145             : 
     146             : // ____ XCloneable ____
     147           0 : uno::Reference< util::XCloneable > SAL_CALL PieChartType::createClone()
     148             :     throw (uno::RuntimeException, std::exception)
     149             : {
     150           0 :     return uno::Reference< util::XCloneable >( new PieChartType( *this ));
     151             : }
     152             : 
     153             : // ____ XChartType ____
     154       21589 : OUString SAL_CALL PieChartType::getChartType()
     155             :     throw (uno::RuntimeException, std::exception)
     156             : {
     157       21589 :     return CHART2_SERVICE_NAME_CHARTTYPE_PIE;
     158             : }
     159             : 
     160             : Reference< chart2::XCoordinateSystem > SAL_CALL
     161          15 :     PieChartType::createCoordinateSystem( ::sal_Int32 DimensionCount )
     162             :     throw (lang::IllegalArgumentException,
     163             :            uno::RuntimeException, std::exception)
     164             : {
     165             :     Reference< chart2::XCoordinateSystem > xResult(
     166             :         new PolarCoordinateSystem(
     167          15 :             GetComponentContext(), DimensionCount, /* bSwapXAndYAxis */ sal_False ));
     168             : 
     169          49 :     for( sal_Int32 i=0; i<DimensionCount; ++i )
     170             :     {
     171          34 :         Reference< chart2::XAxis > xAxis( xResult->getAxisByDimension( i, MAIN_AXIS_INDEX ) );
     172          34 :         if( !xAxis.is() )
     173             :         {
     174             :             OSL_FAIL("a created coordinate system should have an axis for each dimension");
     175           0 :             continue;
     176             :         }
     177             : 
     178             :         //hhhh todo make axis invisible
     179             : 
     180          68 :         chart2::ScaleData aScaleData = xAxis->getScaleData();
     181          34 :         aScaleData.Scaling = AxisHelper::createLinearScaling();
     182          34 :         aScaleData.AxisType = chart2::AxisType::REALNUMBER;
     183             : 
     184          34 :         if( i == 0 )
     185          15 :             aScaleData.Orientation = chart2::AxisOrientation_REVERSE;
     186             :         else
     187          19 :             aScaleData.Orientation = chart2::AxisOrientation_MATHEMATICAL;
     188             : 
     189             :         //remove explicit scalings from all axes
     190          34 :         AxisHelper::removeExplicitScaling( aScaleData );
     191             : 
     192          34 :         xAxis->setScaleData( aScaleData );
     193          34 :     }
     194             : 
     195          15 :     return xResult;
     196             : }
     197             : 
     198          36 : uno::Sequence< OUString > PieChartType::getSupportedPropertyRoles()
     199             :     throw (uno::RuntimeException, std::exception)
     200             : {
     201          36 :     uno::Sequence< OUString > aPropRoles(2);
     202          36 :     aPropRoles[0] = "FillColor";
     203          36 :     aPropRoles[1] = "BorderColor";
     204             : 
     205          36 :     return aPropRoles;
     206             : }
     207             : 
     208             : // ____ OPropertySet ____
     209        8909 : uno::Any PieChartType::GetDefaultValue( sal_Int32 nHandle ) const
     210             :     throw(beans::UnknownPropertyException)
     211             : {
     212        8909 :     const tPropertyValueMap& rStaticDefaults = *StaticPieChartTypeDefaults::get();
     213        8909 :     tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
     214        8909 :     if( aFound == rStaticDefaults.end() )
     215           0 :         return uno::Any();
     216        8909 :     return (*aFound).second;
     217             : }
     218             : 
     219             : // ____ OPropertySet ____
     220       15999 : ::cppu::IPropertyArrayHelper & SAL_CALL PieChartType::getInfoHelper()
     221             : {
     222       15999 :     return *StaticPieChartTypeInfoHelper::get();
     223             : }
     224             : 
     225             : // ____ XPropertySet ____
     226          13 : uno::Reference< beans::XPropertySetInfo > SAL_CALL PieChartType::getPropertySetInfo()
     227             :     throw (uno::RuntimeException, std::exception)
     228             : {
     229          13 :     return *StaticPieChartTypeInfo::get();
     230             : }
     231             : 
     232           6 : uno::Sequence< OUString > PieChartType::getSupportedServiceNames_Static()
     233             : {
     234           6 :     uno::Sequence< OUString > aServices( 3 );
     235           6 :     aServices[ 0 ] = CHART2_SERVICE_NAME_CHARTTYPE_PIE;
     236           6 :     aServices[ 1 ] = "com.sun.star.chart2.ChartType";
     237           6 :     aServices[ 2 ] = "com.sun.star.beans.PropertySet";
     238           6 :     return aServices;
     239             : }
     240             : 
     241             : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     242         107 : APPHELPER_XSERVICEINFO_IMPL( PieChartType,
     243             :                              OUString("com.sun.star.comp.chart.PieChartType") );
     244             : 
     245             : } //  namespace chart
     246             : 
     247             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10