LCOV - code coverage report
Current view: top level - chart2/source/controller/itemsetwrapper - RegressionCurveItemConverter.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 129 0.0 %
Date: 2014-04-14 Functions: 0 18 0.0 %
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 "RegressionCurveHelper.hxx"
      21             : #include "RegressionCurveItemConverter.hxx"
      22             : #include "SchWhichPairs.hxx"
      23             : #include "macros.hxx"
      24             : #include "ItemPropertyMap.hxx"
      25             : #include "GraphicPropertyItemConverter.hxx"
      26             : 
      27             : #include <com/sun/star/chart2/XRegressionCurve.hpp>
      28             : 
      29             : // for SfxBoolItem
      30             : #include <svl/eitem.hxx>
      31             : #include <svl/intitem.hxx>
      32             : #include <svl/stritem.hxx>
      33             : #include <svx/chrtitem.hxx>
      34             : 
      35             : #include <functional>
      36             : #include <algorithm>
      37             : 
      38             : using namespace ::com::sun::star;
      39             : 
      40             : namespace
      41             : {
      42             : 
      43           0 : ::chart::RegressionCurveHelper::tRegressionType lcl_convertRegressionType( SvxChartRegress eRegress )
      44             : {
      45           0 :     ::chart::RegressionCurveHelper::tRegressionType eType = ::chart::RegressionCurveHelper::REGRESSION_TYPE_NONE;
      46           0 :     switch( eRegress )
      47             :     {
      48             :         case CHREGRESS_LINEAR:
      49           0 :             eType = ::chart::RegressionCurveHelper::REGRESSION_TYPE_LINEAR;
      50           0 :             break;
      51             :         case CHREGRESS_LOG:
      52           0 :             eType = ::chart::RegressionCurveHelper::REGRESSION_TYPE_LOG;
      53           0 :             break;
      54             :         case CHREGRESS_EXP:
      55           0 :             eType = ::chart::RegressionCurveHelper::REGRESSION_TYPE_EXP;
      56           0 :             break;
      57             :         case CHREGRESS_POWER:
      58           0 :             eType = ::chart::RegressionCurveHelper::REGRESSION_TYPE_POWER;
      59           0 :             break;
      60             :         case CHREGRESS_POLYNOMIAL:
      61           0 :             eType = ::chart::RegressionCurveHelper::REGRESSION_TYPE_POLYNOMIAL;
      62           0 :             break;
      63             :         case CHREGRESS_MOVING_AVERAGE:
      64           0 :             eType = ::chart::RegressionCurveHelper::REGRESSION_TYPE_MOVING_AVERAGE;
      65           0 :             break;
      66             :         case CHREGRESS_NONE:
      67           0 :             break;
      68             :     }
      69           0 :     return eType;
      70             : }
      71             : 
      72             : template <class T, class D>
      73           0 : bool lclConvertToPropertySet(const SfxItemSet& rItemSet, sal_uInt16 nWhichId, uno::Reference<beans::XPropertySet> xProperties, const OUString& aPropertyID)
      74             : {
      75             :     OSL_ASSERT(xProperties.is());
      76           0 :     if( xProperties.is() )
      77             :     {
      78           0 :         T aValue = static_cast<T>(static_cast<const D&>(rItemSet.Get( nWhichId )).GetValue());
      79           0 :         T aOldValue = aValue;
      80           0 :         bool aSuccess = xProperties->getPropertyValue( aPropertyID ) >>= aOldValue;
      81           0 :         if (!aSuccess || aOldValue != aValue)
      82             :         {
      83           0 :             xProperties->setPropertyValue( aPropertyID , uno::makeAny( aValue ));
      84           0 :             return true;
      85           0 :         }
      86             :     }
      87           0 :     return false;
      88             : }
      89             : 
      90             : template <class T, class D>
      91           0 : void lclConvertToItemSet(SfxItemSet& rItemSet, sal_uInt16 nWhichId, uno::Reference<beans::XPropertySet> xProperties, const OUString& aPropertyID)
      92             : {
      93             :     OSL_ASSERT(xProperties.is());
      94           0 :     if( xProperties.is() )
      95             :     {
      96           0 :         T aValue = static_cast<T>(static_cast<const D&>(rItemSet.Get( nWhichId )).GetValue());
      97           0 :         if(xProperties->getPropertyValue( aPropertyID ) >>= aValue)
      98             :         {
      99           0 :             rItemSet.Put(D( nWhichId, aValue ));
     100           0 :         }
     101             :     }
     102           0 : }
     103             : 
     104           0 : void lclConvertToItemSetDouble(SfxItemSet& rItemSet, sal_uInt16 nWhichId, uno::Reference<beans::XPropertySet> xProperties, const OUString& aPropertyID)
     105             : {
     106             :     OSL_ASSERT(xProperties.is());
     107           0 :     if( xProperties.is() )
     108             :     {
     109           0 :         double aValue = static_cast<double>(static_cast<const SvxDoubleItem&>(rItemSet.Get( nWhichId )).GetValue());
     110           0 :         if(xProperties->getPropertyValue( aPropertyID ) >>= aValue)
     111             :         {
     112           0 :             rItemSet.Put(SvxDoubleItem( aValue, nWhichId ));
     113             :         }
     114             :     }
     115           0 : }
     116             : 
     117             : } // anonymous namespace
     118             : 
     119             : namespace chart
     120             : {
     121             : namespace wrapper
     122             : {
     123             : 
     124           0 : RegressionCurveItemConverter::RegressionCurveItemConverter(
     125             :     const uno::Reference< beans::XPropertySet >& rPropertySet,
     126             :     const uno::Reference< chart2::XRegressionCurveContainer >& xContainer,
     127             :     SfxItemPool& rItemPool,
     128             :     SdrModel& rDrawModel,
     129             :     const uno::Reference< lang::XMultiServiceFactory > & xNamedPropertyContainerFactory ) :
     130             :         ItemConverter( rPropertySet, rItemPool ),
     131             :         m_spGraphicConverter( new GraphicPropertyItemConverter(
     132             :                                   rPropertySet, rItemPool, rDrawModel,
     133             :                                   xNamedPropertyContainerFactory,
     134           0 :                                   GraphicPropertyItemConverter::LINE_PROPERTIES )),
     135           0 :         m_xCurveContainer( xContainer )
     136           0 : {}
     137             : 
     138           0 : RegressionCurveItemConverter::~RegressionCurveItemConverter()
     139           0 : {}
     140             : 
     141           0 : void RegressionCurveItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
     142             : {
     143           0 :     m_spGraphicConverter->FillItemSet( rOutItemSet );
     144             : 
     145             :     // own items
     146           0 :     ItemConverter::FillItemSet( rOutItemSet );
     147           0 : }
     148             : 
     149           0 : bool RegressionCurveItemConverter::ApplyItemSet( const SfxItemSet & rItemSet )
     150             : {
     151           0 :     bool bResult = m_spGraphicConverter->ApplyItemSet( rItemSet );
     152             : 
     153             :     // own items
     154           0 :     return ItemConverter::ApplyItemSet( rItemSet ) || bResult;
     155             : }
     156             : 
     157           0 : const sal_uInt16 * RegressionCurveItemConverter::GetWhichPairs() const
     158             : {
     159             :     // must span all used items!
     160           0 :     return nRegressionCurveWhichPairs;
     161             : }
     162             : 
     163           0 : bool RegressionCurveItemConverter::GetItemProperty(
     164             :     tWhichIdType /* nWhichId */, tPropertyNameWithMemberId & /* rOutProperty */ ) const
     165             : {
     166             :     // No own (non-special) properties
     167           0 :     return false;
     168             : }
     169             : 
     170           0 : bool RegressionCurveItemConverter::ApplySpecialItem(
     171             :     sal_uInt16 nWhichId, const SfxItemSet & rItemSet )
     172             :     throw( uno::Exception )
     173             : {
     174           0 :     uno::Reference< chart2::XRegressionCurve > xCurve( GetPropertySet(), uno::UNO_QUERY );
     175           0 :     bool bChanged = false;
     176             : 
     177             :     OSL_ASSERT(xCurve.is());
     178           0 :     if(!xCurve.is())
     179           0 :         return false;
     180             : 
     181           0 :     switch( nWhichId )
     182             :     {
     183             :         case SCHATTR_REGRESSION_TYPE:
     184             :         {
     185             :             SvxChartRegress eRegress = static_cast< SvxChartRegress >(
     186           0 :                 static_cast< sal_Int32 >( RegressionCurveHelper::getRegressionType( xCurve )));
     187             :             SvxChartRegress eNewRegress = static_cast< const SvxChartRegressItem & >(
     188           0 :                 rItemSet.Get( nWhichId )).GetValue();
     189           0 :             if( eRegress != eNewRegress )
     190             :             {
     191             :                 // note that changing the regression type changes the object
     192             :                 // for which this converter was created. Not optimal, but
     193             :                 // currently the only way to handle the type in the
     194             :                 // regression curve properties dialog
     195           0 :                 xCurve = RegressionCurveHelper::changeRegressionCurveType(
     196             :                             lcl_convertRegressionType( eNewRegress ),
     197             :                             m_xCurveContainer,
     198             :                             xCurve,
     199           0 :                             uno::Reference< uno::XComponentContext >());
     200           0 :                 uno::Reference<beans::XPropertySet> xProperties( xCurve, uno::UNO_QUERY );
     201           0 :                 resetPropertySet( xProperties );
     202           0 :                 bChanged = true;
     203             :             }
     204             :         }
     205           0 :         break;
     206             : 
     207             :         case SCHATTR_REGRESSION_DEGREE:
     208             :         {
     209           0 :             uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
     210           0 :             bChanged = lclConvertToPropertySet<sal_Int32, SfxInt32Item>(rItemSet, nWhichId, xProperties, OUString("PolynomialDegree"));
     211             :         }
     212           0 :         break;
     213             : 
     214             :         case SCHATTR_REGRESSION_PERIOD:
     215             :         {
     216           0 :             uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
     217           0 :             bChanged = lclConvertToPropertySet<sal_Int32, SfxInt32Item>(rItemSet, nWhichId, xProperties, "MovingAveragePeriod");
     218             :         }
     219           0 :         break;
     220             : 
     221             :         case SCHATTR_REGRESSION_EXTRAPOLATE_FORWARD:
     222             :         {
     223           0 :             uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
     224           0 :             bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties, "ExtrapolateForward");
     225             :         }
     226           0 :         break;
     227             : 
     228             :         case SCHATTR_REGRESSION_EXTRAPOLATE_BACKWARD:
     229             :         {
     230           0 :             uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
     231           0 :             bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties, "ExtrapolateBackward");
     232             :         }
     233           0 :         break;
     234             : 
     235             :         case SCHATTR_REGRESSION_SET_INTERCEPT:
     236             :         {
     237           0 :             uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
     238           0 :             bChanged = lclConvertToPropertySet<sal_Bool, SfxBoolItem>(rItemSet, nWhichId, xProperties, "ForceIntercept");
     239             :         }
     240           0 :         break;
     241             : 
     242             :         case SCHATTR_REGRESSION_INTERCEPT_VALUE:
     243             :         {
     244           0 :             uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
     245           0 :             bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties, "InterceptValue");
     246             :         }
     247           0 :         break;
     248             : 
     249             :         case SCHATTR_REGRESSION_CURVE_NAME:
     250             :         {
     251           0 :             uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
     252           0 :             bChanged = lclConvertToPropertySet<OUString, SfxStringItem>(rItemSet, nWhichId, xProperties, "CurveName");
     253             :         }
     254           0 :         break;
     255             : 
     256             :         case SCHATTR_REGRESSION_SHOW_EQUATION:
     257             :         {
     258           0 :             uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties());
     259           0 :             bChanged = lclConvertToPropertySet<sal_Bool, SfxBoolItem>(rItemSet, nWhichId, xEqProp, "ShowEquation");
     260             :         }
     261           0 :         break;
     262             : 
     263             :         case SCHATTR_REGRESSION_SHOW_COEFF:
     264             :         {
     265           0 :             uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties());
     266           0 :             bChanged = lclConvertToPropertySet<sal_Bool, SfxBoolItem>(rItemSet, nWhichId, xEqProp, "ShowCorrelationCoefficient");
     267             :         }
     268           0 :         break;
     269             : 
     270             :     }
     271           0 :     return bChanged;
     272             : }
     273             : 
     274           0 : void RegressionCurveItemConverter::FillSpecialItem(sal_uInt16 nWhichId, SfxItemSet& rOutItemSet ) const
     275             :     throw( uno::Exception )
     276             : {
     277           0 :     uno::Reference<chart2::XRegressionCurve> xCurve(GetPropertySet(), uno::UNO_QUERY);
     278             :     OSL_ASSERT(xCurve.is());
     279           0 :     if(!xCurve.is())
     280           0 :         return;
     281             : 
     282           0 :     uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
     283             : 
     284           0 :     switch( nWhichId )
     285             :     {
     286             :         case SCHATTR_REGRESSION_TYPE:
     287             :         {
     288           0 :             sal_Int32 aRegressionType = static_cast< sal_Int32 >(RegressionCurveHelper::getRegressionType(xCurve));
     289           0 :             SvxChartRegress eRegress = static_cast< SvxChartRegress >(aRegressionType);
     290           0 :             rOutItemSet.Put( SvxChartRegressItem( eRegress, SCHATTR_REGRESSION_TYPE ));
     291             :         }
     292           0 :         break;
     293             : 
     294             :         case SCHATTR_REGRESSION_DEGREE:
     295             :         {
     296           0 :             lclConvertToItemSet<sal_Int32, SfxInt32Item>(rOutItemSet, nWhichId, xProperties, "PolynomialDegree");
     297             :         }
     298           0 :         break;
     299             : 
     300             :         case SCHATTR_REGRESSION_PERIOD:
     301             :         {
     302           0 :             lclConvertToItemSet<sal_Int32, SfxInt32Item>(rOutItemSet, nWhichId, xProperties, "MovingAveragePeriod");
     303             :         }
     304           0 :         break;
     305             : 
     306             :         case SCHATTR_REGRESSION_EXTRAPOLATE_FORWARD:
     307             :         {
     308           0 :             lclConvertToItemSetDouble(rOutItemSet, nWhichId, xProperties, "ExtrapolateForward");
     309             :         }
     310           0 :         break;
     311             : 
     312             :         case SCHATTR_REGRESSION_EXTRAPOLATE_BACKWARD:
     313             :         {
     314           0 :             lclConvertToItemSetDouble(rOutItemSet, nWhichId, xProperties, "ExtrapolateBackward");
     315             :         }
     316           0 :         break;
     317             : 
     318             :         case SCHATTR_REGRESSION_SET_INTERCEPT:
     319             :         {
     320           0 :             lclConvertToItemSet<sal_Bool, SfxBoolItem>(rOutItemSet, nWhichId, xProperties, "ForceIntercept");
     321             :         }
     322           0 :         break;
     323             : 
     324             :         case SCHATTR_REGRESSION_INTERCEPT_VALUE:
     325             :         {
     326           0 :             lclConvertToItemSetDouble(rOutItemSet, nWhichId, xProperties, "InterceptValue");
     327             :         }
     328           0 :         break;
     329             : 
     330             :         case SCHATTR_REGRESSION_CURVE_NAME:
     331             :         {
     332           0 :             lclConvertToItemSet<OUString, SfxStringItem>(rOutItemSet, nWhichId, xProperties, "CurveName");
     333             :         }
     334           0 :         break;
     335             : 
     336             :         case SCHATTR_REGRESSION_SHOW_EQUATION:
     337             :         {
     338           0 :             lclConvertToItemSet<sal_Bool, SfxBoolItem>(rOutItemSet, nWhichId, xCurve->getEquationProperties(), "ShowEquation");
     339             :         }
     340           0 :         break;
     341             : 
     342             :         case SCHATTR_REGRESSION_SHOW_COEFF:
     343             :         {
     344           0 :             lclConvertToItemSet<sal_Bool, SfxBoolItem>(rOutItemSet, nWhichId, xCurve->getEquationProperties(), "ShowCorrelationCoefficient");
     345             :         }
     346           0 :         break;
     347           0 :     }
     348             : }
     349             : 
     350             : } //  namespace wrapper
     351             : } //  namespace chart
     352             : 
     353             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10