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

Generated by: LCOV version 1.10