LCOV - code coverage report
Current view: top level - chart2/source/model/template - PieChartTypeTemplate.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 176 248 71.0 %
Date: 2014-04-11 Functions: 23 28 82.1 %
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 "PieChartTypeTemplate.hxx"
      21             : #include "macros.hxx"
      22             : #include "CommonConverters.hxx"
      23             : #include "DiagramHelper.hxx"
      24             : #include "servicenames_charttypes.hxx"
      25             : #include "DataSeriesHelper.hxx"
      26             : #include "ContainerHelper.hxx"
      27             : #include "BaseGFXHelper.hxx"
      28             : #include "AxisHelper.hxx"
      29             : #include "ThreeDHelper.hxx"
      30             : #include "PropertyHelper.hxx"
      31             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      32             : #include <com/sun/star/drawing/LineStyle.hpp>
      33             : #include <com/sun/star/drawing/FillStyle.hpp>
      34             : #include <com/sun/star/chart2/XChartTypeContainer.hpp>
      35             : #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
      36             : 
      37             : #include <rtl/math.hxx>
      38             : 
      39             : #include <algorithm>
      40             : 
      41             : using namespace ::com::sun::star;
      42             : 
      43             : using ::com::sun::star::beans::Property;
      44             : using ::com::sun::star::uno::Sequence;
      45             : using ::com::sun::star::uno::Reference;
      46             : using ::com::sun::star::uno::Any;
      47             : using ::osl::MutexGuard;
      48             : 
      49             : namespace
      50             : {
      51             : 
      52             : enum
      53             : {
      54             :     PROP_PIE_TEMPLATE_DEFAULT_OFFSET,
      55             :     PROP_PIE_TEMPLATE_OFFSET_MODE,
      56             :     PROP_PIE_TEMPLATE_DIMENSION,
      57             :     PROP_PIE_TEMPLATE_USE_RINGS
      58             : };
      59             : 
      60           5 : static void lcl_AddPropertiesToVector(
      61             :     ::std::vector< Property > & rOutProperties )
      62             : {
      63             :     rOutProperties.push_back(
      64             :         Property( "OffsetMode",
      65             :                   PROP_PIE_TEMPLATE_OFFSET_MODE,
      66           5 :                   ::getCppuType( reinterpret_cast< const chart2::PieChartOffsetMode * >(0)),
      67             :                   beans::PropertyAttribute::BOUND
      68          10 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
      69             :     rOutProperties.push_back(
      70             :         Property( "DefaultOffset",
      71             :                   PROP_PIE_TEMPLATE_DEFAULT_OFFSET,
      72           5 :                   ::getCppuType( reinterpret_cast< const double * >(0)),
      73             :                   beans::PropertyAttribute::BOUND
      74          10 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
      75             :     rOutProperties.push_back(
      76             :         Property( "Dimension",
      77             :                   PROP_PIE_TEMPLATE_DIMENSION,
      78           5 :                   ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
      79             :                   beans::PropertyAttribute::BOUND
      80          10 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
      81             :     rOutProperties.push_back(
      82             :         Property( "UseRings",
      83             :                   PROP_PIE_TEMPLATE_USE_RINGS,
      84           5 :                   ::getBooleanCppuType(),
      85             :                   beans::PropertyAttribute::BOUND
      86          10 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
      87           5 : }
      88             : 
      89             : struct StaticPieChartTypeTemplateDefaults_Initializer
      90             : {
      91           5 :     ::chart::tPropertyValueMap* operator()()
      92             :     {
      93           5 :         static ::chart::tPropertyValueMap aStaticDefaults;
      94           5 :         lcl_AddDefaultsToMap( aStaticDefaults );
      95           5 :         return &aStaticDefaults;
      96             :     }
      97             : private:
      98           5 :     void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
      99             :     {
     100           5 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_PIE_TEMPLATE_OFFSET_MODE, chart2::PieChartOffsetMode_NONE );
     101           5 :         ::chart::PropertyHelper::setPropertyValueDefault< double >( rOutMap, PROP_PIE_TEMPLATE_DEFAULT_OFFSET, 0.5 );
     102           5 :         ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_PIE_TEMPLATE_DIMENSION, 2 );
     103           5 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_PIE_TEMPLATE_USE_RINGS, false );
     104           5 :     }
     105             : };
     106             : 
     107             : struct StaticPieChartTypeTemplateDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticPieChartTypeTemplateDefaults_Initializer >
     108             : {
     109             : };
     110             : 
     111             : struct StaticPieChartTypeTemplateInfoHelper_Initializer
     112             : {
     113           5 :     ::cppu::OPropertyArrayHelper* operator()()
     114             :     {
     115           5 :         static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
     116           5 :         return &aPropHelper;
     117             :     }
     118             : 
     119             : private:
     120           5 :     uno::Sequence< Property > lcl_GetPropertySequence()
     121             :     {
     122           5 :         ::std::vector< ::com::sun::star::beans::Property > aProperties;
     123           5 :         lcl_AddPropertiesToVector( aProperties );
     124             : 
     125             :         ::std::sort( aProperties.begin(), aProperties.end(),
     126           5 :                      ::chart::PropertyNameLess() );
     127             : 
     128           5 :         return ::chart::ContainerHelper::ContainerToSequence( aProperties );
     129             :     }
     130             : 
     131             : };
     132             : 
     133             : struct StaticPieChartTypeTemplateInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticPieChartTypeTemplateInfoHelper_Initializer >
     134             : {
     135             : };
     136             : 
     137             : struct StaticPieChartTypeTemplateInfo_Initializer
     138             : {
     139           0 :     uno::Reference< beans::XPropertySetInfo >* operator()()
     140             :     {
     141             :         static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
     142           0 :             ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticPieChartTypeTemplateInfoHelper::get() ) );
     143           0 :         return &xPropertySetInfo;
     144             :     }
     145             : };
     146             : 
     147             : struct StaticPieChartTypeTemplateInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticPieChartTypeTemplateInfo_Initializer >
     148             : {
     149             : };
     150             : 
     151             : } // anonymous namespace
     152             : 
     153             : namespace chart
     154             : {
     155             : 
     156        5271 : PieChartTypeTemplate::PieChartTypeTemplate(
     157             :     uno::Reference<
     158             :         uno::XComponentContext > const & xContext,
     159             :     const OUString & rServiceName,
     160             :     chart2::PieChartOffsetMode eMode,
     161             :     bool bRings            /* = false */,
     162             :     sal_Int32 nDim         /* = 2 */    ) :
     163             :         ChartTypeTemplate( xContext, rServiceName ),
     164        5271 :         ::property::OPropertySet( m_aMutex )
     165             : {
     166        5271 :     setFastPropertyValue_NoBroadcast( PROP_PIE_TEMPLATE_OFFSET_MODE,    uno::makeAny( eMode ));
     167        5271 :     setFastPropertyValue_NoBroadcast( PROP_PIE_TEMPLATE_DIMENSION,      uno::makeAny( nDim ));
     168        5271 :     setFastPropertyValue_NoBroadcast( PROP_PIE_TEMPLATE_USE_RINGS,      uno::makeAny( sal_Bool( bRings )));
     169        5271 : }
     170             : 
     171       10542 : PieChartTypeTemplate::~PieChartTypeTemplate()
     172       10542 : {}
     173             : 
     174             : // ____ OPropertySet ____
     175       28366 : uno::Any PieChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle ) const
     176             :     throw(beans::UnknownPropertyException)
     177             : {
     178       28366 :     const tPropertyValueMap& rStaticDefaults = *StaticPieChartTypeTemplateDefaults::get();
     179       28366 :     tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
     180       28366 :     if( aFound == rStaticDefaults.end() )
     181           0 :         return uno::Any();
     182       28366 :     return (*aFound).second;
     183             : }
     184             : 
     185       21117 : ::cppu::IPropertyArrayHelper & SAL_CALL PieChartTypeTemplate::getInfoHelper()
     186             : {
     187       21117 :     return *StaticPieChartTypeTemplateInfoHelper::get();
     188             : }
     189             : 
     190             : // ____ XPropertySet ____
     191           0 : uno::Reference< beans::XPropertySetInfo > SAL_CALL PieChartTypeTemplate::getPropertySetInfo()
     192             :     throw (uno::RuntimeException, std::exception)
     193             : {
     194           0 :     return *StaticPieChartTypeTemplateInfo::get();
     195             : }
     196             : 
     197             : // ____ ChartTypeTemplate ____
     198        5277 : sal_Int32 PieChartTypeTemplate::getDimension() const
     199             : {
     200        5277 :     sal_Int32 nDim = 2;
     201             :     try
     202             :     {
     203             :         // note: UNO-methods are never const
     204             :         const_cast< PieChartTypeTemplate * >( this )->
     205        5277 :             getFastPropertyValue( PROP_PIE_TEMPLATE_DIMENSION ) >>= nDim;
     206             :     }
     207           0 :     catch( const beans::UnknownPropertyException & ex )
     208             :     {
     209             :         ASSERT_EXCEPTION( ex );
     210             :     }
     211             : 
     212        5277 :     return nDim;
     213             : }
     214             : 
     215          22 : sal_Int32 PieChartTypeTemplate::getAxisCountByDimension( sal_Int32 /*nDimension*/ )
     216             : {
     217          22 :     return 0;
     218             : }
     219             : 
     220          11 : void PieChartTypeTemplate::adaptAxes(
     221             :     const uno::Sequence< uno::Reference< chart2::XCoordinateSystem > > & /*rCoordSys*/ )
     222             : {
     223             :     // hide existing axes
     224             :     //hhhh todo
     225          11 : }
     226             : 
     227          11 : void PieChartTypeTemplate::adaptScales(
     228             :     const Sequence< Reference< chart2::XCoordinateSystem > > & aCooSysSeq,
     229             :     const Reference< chart2::data::XLabeledDataSequence > & xCategories //@todo: in future there may be more than one sequence of categories (e.g. charttype with categories at x and y axis )
     230             :     )
     231             : {
     232          11 :     ChartTypeTemplate::adaptScales( aCooSysSeq, xCategories );
     233             : 
     234             :     //remove explicit scalings from radius axis
     235             :     //and ensure correct orientation of scales for donuts
     236             : 
     237          22 :     for( sal_Int32 nCooSysIdx=0; nCooSysIdx<aCooSysSeq.getLength(); ++nCooSysIdx )
     238             :     {
     239             :         try
     240             :         {
     241             :             Reference< chart2::XAxis > xAxis( AxisHelper::getAxis( 1 /*nDimensionIndex*/,0 /*nAxisIndex*/
     242          11 :                     , aCooSysSeq[nCooSysIdx] ) );
     243          11 :             if( xAxis.is() )
     244             :             {
     245          11 :                 chart2::ScaleData aScaleData( xAxis->getScaleData() );
     246          11 :                 AxisHelper::removeExplicitScaling( aScaleData );
     247          11 :                 aScaleData.Orientation = chart2::AxisOrientation_MATHEMATICAL;
     248          11 :                 xAxis->setScaleData( aScaleData );
     249             :             }
     250             : 
     251          22 :             xAxis = AxisHelper::getAxis( 0 /*nDimensionIndex*/,0 /*nAxisIndex*/
     252          22 :                     , aCooSysSeq[nCooSysIdx] );
     253          11 :             if( xAxis.is() )
     254             :             {
     255          11 :                 chart2::ScaleData aScaleData( xAxis->getScaleData() );
     256          11 :                 aScaleData.Orientation = chart2::AxisOrientation_REVERSE;
     257          11 :                 xAxis->setScaleData( aScaleData );
     258          11 :             }
     259             :         }
     260           0 :         catch( const uno::Exception & ex )
     261             :         {
     262             :             ASSERT_EXCEPTION( ex );
     263             :         }
     264             :     }
     265          11 : }
     266             : 
     267          11 : void PieChartTypeTemplate::createChartTypes(
     268             :     const Sequence< Sequence< Reference< chart2::XDataSeries > > > & aSeriesSeq,
     269             :     const Sequence< Reference< chart2::XCoordinateSystem > > & rCoordSys,
     270             :     const Sequence< Reference< chart2::XChartType > >& /* aOldChartTypesSeq */ )
     271             : {
     272          22 :     if( rCoordSys.getLength() == 0 ||
     273          11 :         ! rCoordSys[0].is() )
     274          11 :         return;
     275             : 
     276             :     try
     277             :     {
     278             :         Reference< lang::XMultiServiceFactory > xFact(
     279          11 :             GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW );
     280             : 
     281             :         Reference< chart2::XChartType > xCT(
     282          22 :             xFact->createInstance( CHART2_SERVICE_NAME_CHARTTYPE_PIE ), uno::UNO_QUERY_THROW );
     283          22 :         Reference< beans::XPropertySet > xCTProp( xCT, uno::UNO_QUERY );
     284          11 :         if( xCTProp.is())
     285             :         {
     286          11 :             xCTProp->setPropertyValue(
     287          11 :                 "UseRings", getFastPropertyValue( PROP_PIE_TEMPLATE_USE_RINGS ));
     288             :         }
     289          22 :         Reference< chart2::XChartTypeContainer > xCTCnt( rCoordSys[0], uno::UNO_QUERY_THROW );
     290          11 :         xCTCnt->setChartTypes( Sequence< Reference< chart2::XChartType > >( &xCT, 1 ));
     291             : 
     292          11 :         if( aSeriesSeq.getLength() > 0 )
     293             :         {
     294           2 :             Reference< chart2::XDataSeriesContainer > xDSCnt( xCT, uno::UNO_QUERY_THROW );
     295           4 :             Sequence< Reference< chart2::XDataSeries > > aFlatSeriesSeq( FlattenSequence( aSeriesSeq ));
     296           2 :             xDSCnt->setDataSeries( aFlatSeriesSeq );
     297             : 
     298             :             DataSeriesHelper::setStackModeAtSeries(
     299           4 :                 aFlatSeriesSeq, rCoordSys[0], getStackMode( 0 ));
     300          11 :         }
     301             :     }
     302           0 :     catch( const uno::Exception & ex )
     303             :     {
     304             :         ASSERT_EXCEPTION( ex );
     305             :     }
     306             : }
     307             : 
     308             : // ____ XChartTypeTemplate ____
     309        5260 : sal_Bool SAL_CALL PieChartTypeTemplate::matchesTemplate(
     310             :     const uno::Reference< chart2::XDiagram >& xDiagram,
     311             :     sal_Bool bAdaptProperties )
     312             :     throw (uno::RuntimeException, std::exception)
     313             : {
     314        5260 :     sal_Bool bResult = ChartTypeTemplate::matchesTemplate( xDiagram, bAdaptProperties );
     315             : 
     316        5260 :     sal_Bool bTemplateUsesRings = sal_False;
     317        5260 :     getFastPropertyValue( PROP_PIE_TEMPLATE_USE_RINGS ) >>= bTemplateUsesRings;
     318             :     chart2::PieChartOffsetMode ePieOffsetMode;
     319        5260 :     getFastPropertyValue( PROP_PIE_TEMPLATE_OFFSET_MODE ) >>= ePieOffsetMode;
     320             : 
     321             :     //check offset-mode
     322        5260 :     if( bResult )
     323             :     {
     324             :         try
     325             :         {
     326        1022 :             double fOffset=0.0;
     327        1022 :             bool bAllOffsetsEqual = true;
     328             : 
     329             :             ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec(
     330        1022 :                 DiagramHelper::getDataSeriesFromDiagram( xDiagram ));
     331             : 
     332             :             //check offset of outer series
     333        1022 :             if( !aSeriesVec.empty() )
     334             :             {
     335        1022 :                 sal_Int32 nOuterSeriesIndex = 0; //@todo in future this will depend on Orientation of the radius axis scale
     336        1022 :                 Reference< chart2::XDataSeries > xSeries( aSeriesVec[nOuterSeriesIndex] );
     337        2044 :                 Reference< beans::XPropertySet > xProp( xSeries, uno::UNO_QUERY_THROW );
     338        1022 :                 xProp->getPropertyValue( "Offset") >>= fOffset;
     339             : 
     340             :                 //get AttributedDataPoints
     341        2044 :                 uno::Sequence< sal_Int32 > aAttributedDataPointIndexList;
     342        1022 :                 if( xProp->getPropertyValue( "AttributedDataPoints" ) >>= aAttributedDataPointIndexList )
     343             :                 {
     344        8336 :                     for(sal_Int32 nN=aAttributedDataPointIndexList.getLength();nN--;)
     345             :                     {
     346        6292 :                         uno::Reference< beans::XPropertySet > xPointProp( xSeries->getDataPointByIndex(aAttributedDataPointIndexList[nN]) );
     347        6292 :                         if(xPointProp.is())
     348             :                         {
     349        6292 :                             double fPointOffset=0.0;
     350        6292 :                             if( (xProp->getPropertyValue( "Offset") >>= fPointOffset ) )
     351             :                             {
     352        6292 :                                 if( ! ::rtl::math::approxEqual( fPointOffset, fOffset ) )
     353             :                                 {
     354           0 :                                     bAllOffsetsEqual = false;
     355           0 :                                     break;
     356             :                                 }
     357             :                             }
     358             :                         }
     359        6292 :                     }
     360        1022 :                 }
     361             :             }
     362             : 
     363        1022 :             chart2::PieChartOffsetMode eOffsetMode = chart2::PieChartOffsetMode_NONE;
     364        1022 :             if( bAllOffsetsEqual && fOffset > 0.0 )
     365             :             {
     366         440 :                 eOffsetMode = chart2::PieChartOffsetMode_ALL_EXPLODED;
     367         440 :                 if( bAdaptProperties )
     368         440 :                     setFastPropertyValue_NoBroadcast( PROP_PIE_TEMPLATE_DEFAULT_OFFSET, uno::makeAny( fOffset ));
     369             :             }
     370             : 
     371        1022 :             bResult = ( eOffsetMode == ePieOffsetMode );
     372             :         }
     373           0 :         catch( const uno::Exception & ex )
     374             :         {
     375             :             ASSERT_EXCEPTION( ex );
     376           0 :             bResult = false;
     377             :         }
     378             :     }
     379             : 
     380             :     //check UseRings
     381        5260 :     if( bResult )
     382             :     {
     383             :         uno::Reference< beans::XPropertySet > xCTProp(
     384         627 :             DiagramHelper::getChartTypeByIndex( xDiagram, 0 ), uno::UNO_QUERY_THROW );
     385         627 :         sal_Bool bUseRings = false;
     386         627 :         if( xCTProp->getPropertyValue( "UseRings") >>= bUseRings )
     387             :         {
     388         627 :             bResult = ( bTemplateUsesRings == bUseRings );
     389         627 :         }
     390             :     }
     391             : 
     392        5260 :     return bResult;
     393             : }
     394             : 
     395          17 : Reference< chart2::XChartType > PieChartTypeTemplate::getChartTypeForIndex( sal_Int32 /*nChartTypeIndex*/ )
     396             : {
     397          17 :     Reference< chart2::XChartType > xResult;
     398             : 
     399             :     try
     400             :     {
     401             :         Reference< lang::XMultiServiceFactory > xFact(
     402          17 :             GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW );
     403          17 :         xResult.set( xFact->createInstance(
     404          17 :                          CHART2_SERVICE_NAME_CHARTTYPE_PIE ), uno::UNO_QUERY_THROW );
     405          34 :         Reference< beans::XPropertySet > xCTProp( xResult, uno::UNO_QUERY );
     406          17 :         if( xCTProp.is())
     407             :         {
     408          17 :             xCTProp->setPropertyValue(
     409          17 :                 "UseRings", getFastPropertyValue( PROP_PIE_TEMPLATE_USE_RINGS ));
     410          17 :         }
     411             : 
     412             :     }
     413           0 :     catch( const uno::Exception & ex )
     414             :     {
     415             :         ASSERT_EXCEPTION( ex );
     416             :     }
     417             : 
     418          17 :     return xResult;
     419             : }
     420             : 
     421        5282 : Reference< chart2::XChartType > SAL_CALL PieChartTypeTemplate::getChartTypeForNewSeries(
     422             :         const uno::Sequence< Reference< chart2::XChartType > >& aFormerlyUsedChartTypes )
     423             :     throw (uno::RuntimeException, std::exception)
     424             : {
     425        5282 :     Reference< chart2::XChartType > xResult;
     426             : 
     427             :     try
     428             :     {
     429             :         Reference< lang::XMultiServiceFactory > xFact(
     430        5282 :             GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW );
     431        5282 :         xResult.set( xFact->createInstance(
     432        5282 :                          CHART2_SERVICE_NAME_CHARTTYPE_PIE ), uno::UNO_QUERY_THROW );
     433        5282 :         ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aFormerlyUsedChartTypes, xResult );
     434       10564 :         Reference< beans::XPropertySet > xCTProp( xResult, uno::UNO_QUERY );
     435        5282 :         if( xCTProp.is())
     436             :         {
     437        5282 :             xCTProp->setPropertyValue(
     438        5282 :                 "UseRings", getFastPropertyValue( PROP_PIE_TEMPLATE_USE_RINGS ));
     439        5282 :         }
     440             : 
     441             :     }
     442           0 :     catch( const uno::Exception & ex )
     443             :     {
     444             :         ASSERT_EXCEPTION( ex );
     445             :     }
     446             : 
     447        5282 :     return xResult;
     448             : }
     449             : 
     450           6 : void SAL_CALL PieChartTypeTemplate::applyStyle(
     451             :     const Reference< chart2::XDataSeries >& xSeries,
     452             :     ::sal_Int32 nChartTypeIndex,
     453             :     ::sal_Int32 nSeriesIndex,
     454             :     ::sal_Int32 nSeriesCount )
     455             :     throw (uno::RuntimeException, std::exception)
     456             : {
     457           6 :     ChartTypeTemplate::applyStyle( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount );
     458             : 
     459             :     try
     460             :     {
     461           6 :         uno::Reference< beans::XPropertySet > xProp( xSeries, uno::UNO_QUERY_THROW );
     462             : 
     463           6 :         sal_Bool bTemplateUsesRings = sal_False;
     464           6 :         getFastPropertyValue( PROP_PIE_TEMPLATE_USE_RINGS ) >>= bTemplateUsesRings;
     465           6 :         sal_Int32 nOuterSeriesIndex = 0; //@todo in future this will depend on Orientation of the radius axis scale
     466           6 :         if( nSeriesIndex == nOuterSeriesIndex )
     467             :         {
     468           2 :             const OUString aOffsetPropName( "Offset" );
     469             :             // get offset mode
     470             :             chart2::PieChartOffsetMode ePieOffsetMode;
     471           2 :             this->getFastPropertyValue( PROP_PIE_TEMPLATE_OFFSET_MODE ) >>= ePieOffsetMode;
     472             : 
     473             :             // get default offset
     474           2 :             double fDefaultOffset = 0.5;
     475           2 :             this->getFastPropertyValue( PROP_PIE_TEMPLATE_DEFAULT_OFFSET ) >>= fDefaultOffset;
     476           2 :             double fOffsetToSet = fDefaultOffset;
     477             : 
     478           4 :             uno::Sequence< sal_Int32 > aAttributedDataPointIndexList;
     479           2 :             xProp->getPropertyValue( "AttributedDataPoints" ) >>= aAttributedDataPointIndexList;
     480             : 
     481             :             // determine whether to set the new offset
     482           2 :             bool bSetOffset = ( ePieOffsetMode == chart2::PieChartOffsetMode_ALL_EXPLODED );
     483           4 :             if( !bSetOffset &&
     484           2 :                 (ePieOffsetMode == chart2::PieChartOffsetMode_NONE) )
     485             :             {
     486             :                 // set offset to 0 if the offset was exactly "all exploded"
     487             :                 // before (individual offsets are kept)
     488           2 :                 double fOffset = 0.0;
     489           4 :                 if( (xProp->getPropertyValue( aOffsetPropName ) >>= fOffset) &&
     490           2 :                     ::rtl::math::approxEqual( fOffset, fDefaultOffset ))
     491             :                 {
     492           0 :                     fOffsetToSet = 0.0;
     493           0 :                     bSetOffset = true;
     494           0 :                     for( sal_Int32 nPtIdx=0; nPtIdx<aAttributedDataPointIndexList.getLength(); ++nPtIdx )
     495             :                     {
     496             :                         uno::Reference< beans::XPropertySet > xPointProp(
     497           0 :                             xSeries->getDataPointByIndex( aAttributedDataPointIndexList[ nPtIdx ] ));
     498           0 :                         uno::Reference< beans::XPropertyState > xPointState( xPointProp, uno::UNO_QUERY );
     499           0 :                         double fPointOffset = 0.0;
     500           0 :                         if( xPointState.is() &&
     501           0 :                             (xPointState->getPropertyState( aOffsetPropName ) == beans::PropertyState_DIRECT_VALUE) &&
     502           0 :                             xPointProp.is() &&
     503           0 :                             (xPointProp->getPropertyValue( aOffsetPropName ) >>= fPointOffset ) &&
     504           0 :                             ! ::rtl::math::approxEqual( fPointOffset, fDefaultOffset ) )
     505             :                         {
     506           0 :                             bSetOffset = false;
     507           0 :                             break;
     508             :                         }
     509           0 :                     }
     510             :                 }
     511             :             }
     512             : 
     513           2 :             if( bSetOffset )
     514             :             {
     515             :                 // set the offset to the series and to the attributed data points
     516           0 :                 xProp->setPropertyValue( aOffsetPropName, uno::makeAny( fOffsetToSet ));
     517             : 
     518             :                 // remove hard attributes from data points
     519           0 :                 for( sal_Int32 nPtIdx=0; nPtIdx<aAttributedDataPointIndexList.getLength(); ++nPtIdx )
     520             :                 {
     521             :                     uno::Reference< beans::XPropertyState > xPointState(
     522           0 :                         xSeries->getDataPointByIndex( aAttributedDataPointIndexList[ nPtIdx ] ), uno::UNO_QUERY );
     523           0 :                     if( xPointState.is())
     524           0 :                         xPointState->setPropertyToDefault( aOffsetPropName );
     525           0 :                 }
     526           2 :             }
     527             :         }
     528             : 
     529             :         // line style
     530           6 :         DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, "BorderStyle", uno::makeAny( drawing::LineStyle_NONE ) );
     531             : 
     532             :         // vary colors by point
     533           6 :         xProp->setPropertyValue( "VaryColorsByPoint", uno::makeAny( true ));
     534             :     }
     535           0 :     catch( const uno::Exception & ex )
     536             :     {
     537             :         ASSERT_EXCEPTION( ex );
     538             :     }
     539           6 : }
     540             : 
     541           0 : void SAL_CALL PieChartTypeTemplate::resetStyles( const Reference< chart2::XDiagram >& xDiagram )
     542             :     throw (uno::RuntimeException, std::exception)
     543             : {
     544             :     // reset axes and grids
     545           0 :     Reference< chart2::XCoordinateSystemContainer > xCooSysCnt( xDiagram, uno::UNO_QUERY );
     546           0 :     if( xCooSysCnt.is())
     547             :     {
     548           0 :         Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq( xCooSysCnt->getCoordinateSystems());
     549           0 :         ChartTypeTemplate::createAxes( aCooSysSeq );
     550             : 
     551             :         //reset scale orientation
     552           0 :         for( sal_Int32 nCooSysIdx=0; nCooSysIdx<aCooSysSeq.getLength(); ++nCooSysIdx )
     553             :         {
     554             :             try
     555             :             {
     556             :                 Reference< chart2::XAxis > xAxis( AxisHelper::getAxis( 0 /*nDimensionIndex*/,0 /*nAxisIndex*/
     557           0 :                         , aCooSysSeq[nCooSysIdx] ) );
     558           0 :                 if( xAxis.is() )
     559             :                 {
     560           0 :                     chart2::ScaleData aScaleData( xAxis->getScaleData() );
     561           0 :                     aScaleData.Orientation = chart2::AxisOrientation_MATHEMATICAL;
     562           0 :                     xAxis->setScaleData( aScaleData );
     563             :                 }
     564             : 
     565           0 :                 xAxis = AxisHelper::getAxis( 1, 0, aCooSysSeq[nCooSysIdx] );
     566           0 :                 if( xAxis.is() )
     567             :                 {
     568           0 :                     chart2::ScaleData aScaleData( xAxis->getScaleData() );
     569           0 :                     aScaleData.Orientation = chart2::AxisOrientation_MATHEMATICAL;
     570           0 :                     xAxis->setScaleData( aScaleData );
     571           0 :                 }
     572             :             }
     573           0 :             catch( const uno::Exception & ex )
     574             :             {
     575             :                 ASSERT_EXCEPTION( ex );
     576             :             }
     577           0 :         }
     578             :     }
     579             : 
     580           0 :     ChartTypeTemplate::resetStyles( xDiagram );
     581             : 
     582             :     // vary colors by point,
     583             :     // line style
     584             :     ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec(
     585           0 :         DiagramHelper::getDataSeriesFromDiagram( xDiagram ));
     586           0 :     uno::Any aLineStyleAny( uno::makeAny( drawing::LineStyle_NONE ));
     587           0 :     for( ::std::vector< Reference< chart2::XDataSeries > >::iterator aIt( aSeriesVec.begin());
     588           0 :          aIt != aSeriesVec.end(); ++aIt )
     589             :     {
     590           0 :         Reference< beans::XPropertyState > xState( *aIt, uno::UNO_QUERY );
     591           0 :         if( xState.is())
     592             :         {
     593           0 :             xState->setPropertyToDefault( "VaryColorsByPoint");
     594           0 :             Reference< beans::XPropertySet > xProp( xState, uno::UNO_QUERY );
     595           0 :             if( xProp.is() &&
     596           0 :                 xProp->getPropertyValue( "BorderStyle") == aLineStyleAny )
     597             :             {
     598           0 :                 xState->setPropertyToDefault( "BorderStyle");
     599           0 :             }
     600             :         }
     601           0 :     }
     602             : 
     603             :     //reset scene properties
     604           0 :     ThreeDHelper::setDefaultRotation( uno::Reference< beans::XPropertySet >( xDiagram, uno::UNO_QUERY ), false );
     605           0 : }
     606             : 
     607             : // ____ XChartTypeTemplate ____
     608          11 : void PieChartTypeTemplate::adaptDiagram( const uno::Reference< chart2::XDiagram >& xDiagram )
     609             : {
     610          11 :     if( !xDiagram.is() )
     611          11 :         return;
     612             : 
     613             :     //different default for scene geometry:
     614          11 :     ThreeDHelper::setDefaultRotation( uno::Reference< beans::XPropertySet >( xDiagram, uno::UNO_QUERY ), true );
     615             : }
     616             : 
     617       42858 : IMPLEMENT_FORWARD_XINTERFACE2( PieChartTypeTemplate, ChartTypeTemplate, OPropertySet )
     618           0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( PieChartTypeTemplate, ChartTypeTemplate, OPropertySet )
     619             : 
     620             : } //  namespace chart
     621             : 
     622             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10