2010-10-12 15:59:00 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-06-21 14:30:25 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2007-11-23 10:52:13 +00:00
|
|
|
|
2008-02-18 14:56:00 +00:00
|
|
|
#include "RegressionCurveHelper.hxx"
|
2007-11-23 10:52:13 +00:00
|
|
|
#include "RegressionCurveItemConverter.hxx"
|
|
|
|
#include "SchWhichPairs.hxx"
|
|
|
|
#include "macros.hxx"
|
|
|
|
#include "ItemPropertyMap.hxx"
|
|
|
|
#include "GraphicPropertyItemConverter.hxx"
|
|
|
|
|
|
|
|
#include <com/sun/star/chart2/XRegressionCurve.hpp>
|
|
|
|
|
|
|
|
// for SfxBoolItem
|
2009-10-16 00:05:16 +02:00
|
|
|
#include <svl/eitem.hxx>
|
2013-05-27 08:02:37 +02:00
|
|
|
#include <svl/intitem.hxx>
|
2008-02-18 14:56:00 +00:00
|
|
|
#include <svx/chrtitem.hxx>
|
2007-11-23 10:52:13 +00:00
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
using namespace ::com::sun::star;
|
|
|
|
|
2008-02-18 14:56:00 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
::chart::RegressionCurveHelper::tRegressionType lcl_convertRegressionType( SvxChartRegress eRegress )
|
|
|
|
{
|
|
|
|
::chart::RegressionCurveHelper::tRegressionType eType = ::chart::RegressionCurveHelper::REGRESSION_TYPE_NONE;
|
|
|
|
switch( eRegress )
|
|
|
|
{
|
|
|
|
case CHREGRESS_LINEAR:
|
|
|
|
eType = ::chart::RegressionCurveHelper::REGRESSION_TYPE_LINEAR;
|
|
|
|
break;
|
|
|
|
case CHREGRESS_LOG:
|
|
|
|
eType = ::chart::RegressionCurveHelper::REGRESSION_TYPE_LOG;
|
|
|
|
break;
|
|
|
|
case CHREGRESS_EXP:
|
|
|
|
eType = ::chart::RegressionCurveHelper::REGRESSION_TYPE_EXP;
|
|
|
|
break;
|
|
|
|
case CHREGRESS_POWER:
|
|
|
|
eType = ::chart::RegressionCurveHelper::REGRESSION_TYPE_POWER;
|
|
|
|
break;
|
2013-05-27 08:02:37 +02:00
|
|
|
case CHREGRESS_POLYNOMIAL:
|
|
|
|
eType = ::chart::RegressionCurveHelper::REGRESSION_TYPE_POLYNOMIAL;
|
|
|
|
break;
|
|
|
|
case CHREGRESS_MOVING_AVERAGE:
|
|
|
|
eType = ::chart::RegressionCurveHelper::REGRESSION_TYPE_MOVING_AVERAGE;
|
|
|
|
break;
|
2008-02-18 14:56:00 +00:00
|
|
|
case CHREGRESS_NONE:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return eType;
|
|
|
|
}
|
|
|
|
|
2013-11-21 20:25:53 +01:00
|
|
|
template <class T, class D>
|
|
|
|
bool lclConvertToPropertySet(const SfxItemSet& rItemSet, sal_uInt16 nWhichId, uno::Reference<beans::XPropertySet> xProperties, OUString aPropertyID)
|
|
|
|
{
|
|
|
|
OSL_ASSERT(xProperties.is());
|
|
|
|
if( xProperties.is() )
|
|
|
|
{
|
|
|
|
T aValue = static_cast<T>(static_cast<const D&>(rItemSet.Get( nWhichId )).GetValue());
|
|
|
|
T aOldValue = aValue;
|
|
|
|
bool aSuccess = xProperties->getPropertyValue( aPropertyID ) >>= aOldValue;
|
|
|
|
if (!aSuccess || aOldValue != aValue)
|
|
|
|
{
|
|
|
|
xProperties->setPropertyValue( aPropertyID , uno::makeAny( aValue ));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T, class D>
|
|
|
|
void lclConvertToItemSet(SfxItemSet& rItemSet, sal_uInt16 nWhichId, uno::Reference<beans::XPropertySet> xProperties, OUString aPropertyID)
|
|
|
|
{
|
|
|
|
OSL_ASSERT(xProperties.is());
|
|
|
|
if( xProperties.is() )
|
|
|
|
{
|
|
|
|
T aValue = static_cast<T>(static_cast<const D&>(rItemSet.Get( nWhichId )).GetValue());
|
|
|
|
if(xProperties->getPropertyValue( aPropertyID ) >>= aValue)
|
|
|
|
{
|
|
|
|
rItemSet.Put(D( nWhichId, aValue ));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void lclConvertToItemSetDouble(SfxItemSet& rItemSet, sal_uInt16 nWhichId, uno::Reference<beans::XPropertySet> xProperties, OUString aPropertyID)
|
|
|
|
{
|
|
|
|
OSL_ASSERT(xProperties.is());
|
|
|
|
if( xProperties.is() )
|
|
|
|
{
|
|
|
|
double aValue = static_cast<double>(static_cast<const SvxDoubleItem&>(rItemSet.Get( nWhichId )).GetValue());
|
|
|
|
if(xProperties->getPropertyValue( aPropertyID ) >>= aValue)
|
|
|
|
{
|
|
|
|
rItemSet.Put(SvxDoubleItem( aValue, nWhichId ));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-18 14:56:00 +00:00
|
|
|
} // anonymous namespace
|
|
|
|
|
2007-11-23 10:52:13 +00:00
|
|
|
namespace chart
|
|
|
|
{
|
|
|
|
namespace wrapper
|
|
|
|
{
|
|
|
|
|
|
|
|
RegressionCurveItemConverter::RegressionCurveItemConverter(
|
2013-06-30 13:21:18 +02:00
|
|
|
const uno::Reference< beans::XPropertySet >& rPropertySet,
|
|
|
|
const uno::Reference< chart2::XRegressionCurveContainer >& xContainer,
|
2007-11-23 10:52:13 +00:00
|
|
|
SfxItemPool& rItemPool,
|
|
|
|
SdrModel& rDrawModel,
|
|
|
|
const uno::Reference< lang::XMultiServiceFactory > & xNamedPropertyContainerFactory ) :
|
|
|
|
ItemConverter( rPropertySet, rItemPool ),
|
|
|
|
m_spGraphicConverter( new GraphicPropertyItemConverter(
|
|
|
|
rPropertySet, rItemPool, rDrawModel,
|
|
|
|
xNamedPropertyContainerFactory,
|
2008-02-18 14:56:00 +00:00
|
|
|
GraphicPropertyItemConverter::LINE_PROPERTIES )),
|
2013-06-30 13:21:18 +02:00
|
|
|
m_xCurveContainer( xContainer )
|
2007-11-23 10:52:13 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
RegressionCurveItemConverter::~RegressionCurveItemConverter()
|
|
|
|
{}
|
|
|
|
|
|
|
|
void RegressionCurveItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
|
|
|
|
{
|
|
|
|
m_spGraphicConverter->FillItemSet( rOutItemSet );
|
|
|
|
|
|
|
|
// own items
|
|
|
|
ItemConverter::FillItemSet( rOutItemSet );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RegressionCurveItemConverter::ApplyItemSet( const SfxItemSet & rItemSet )
|
|
|
|
{
|
|
|
|
bool bResult = m_spGraphicConverter->ApplyItemSet( rItemSet );
|
|
|
|
|
|
|
|
// own items
|
|
|
|
return ItemConverter::ApplyItemSet( rItemSet ) || bResult;
|
|
|
|
}
|
|
|
|
|
2011-01-14 15:18:08 +01:00
|
|
|
const sal_uInt16 * RegressionCurveItemConverter::GetWhichPairs() const
|
2007-11-23 10:52:13 +00:00
|
|
|
{
|
|
|
|
// must span all used items!
|
|
|
|
return nRegressionCurveWhichPairs;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RegressionCurveItemConverter::GetItemProperty(
|
|
|
|
tWhichIdType /* nWhichId */, tPropertyNameWithMemberId & /* rOutProperty */ ) const
|
|
|
|
{
|
|
|
|
// No own (non-special) properties
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RegressionCurveItemConverter::ApplySpecialItem(
|
2011-01-14 15:18:08 +01:00
|
|
|
sal_uInt16 nWhichId, const SfxItemSet & rItemSet )
|
2007-11-23 10:52:13 +00:00
|
|
|
throw( uno::Exception )
|
|
|
|
{
|
2008-02-18 14:56:00 +00:00
|
|
|
uno::Reference< chart2::XRegressionCurve > xCurve( GetPropertySet(), uno::UNO_QUERY );
|
2007-11-23 10:52:13 +00:00
|
|
|
bool bChanged = false;
|
|
|
|
|
2013-11-21 20:25:53 +01:00
|
|
|
OSL_ASSERT(xCurve.is());
|
|
|
|
if(!xCurve.is())
|
2013-11-20 22:40:51 +01:00
|
|
|
return false;
|
|
|
|
|
2007-11-23 10:52:13 +00:00
|
|
|
switch( nWhichId )
|
|
|
|
{
|
2008-03-06 15:50:42 +00:00
|
|
|
case SCHATTR_REGRESSION_TYPE:
|
2008-02-18 14:56:00 +00:00
|
|
|
{
|
2013-11-20 22:40:51 +01:00
|
|
|
SvxChartRegress eRegress = static_cast< SvxChartRegress >(
|
|
|
|
static_cast< sal_Int32 >( RegressionCurveHelper::getRegressionType( xCurve )));
|
|
|
|
SvxChartRegress eNewRegress = static_cast< const SvxChartRegressItem & >(
|
|
|
|
rItemSet.Get( nWhichId )).GetValue();
|
|
|
|
if( eRegress != eNewRegress )
|
2008-02-18 14:56:00 +00:00
|
|
|
{
|
2013-11-20 22:40:51 +01:00
|
|
|
// note that changing the regression type changes the object
|
|
|
|
// for which this converter was created. Not optimal, but
|
|
|
|
// currently the only way to handle the type in the
|
|
|
|
// regression curve properties dialog
|
|
|
|
xCurve = RegressionCurveHelper::changeRegressionCurveType(
|
|
|
|
lcl_convertRegressionType( eNewRegress ),
|
|
|
|
m_xCurveContainer,
|
|
|
|
xCurve,
|
|
|
|
uno::Reference< uno::XComponentContext >());
|
2013-11-21 20:25:53 +01:00
|
|
|
uno::Reference<beans::XPropertySet> xProperties( xCurve, uno::UNO_QUERY );
|
2013-11-20 22:40:51 +01:00
|
|
|
resetPropertySet( xProperties );
|
|
|
|
bChanged = true;
|
2008-02-18 14:56:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-05-27 08:02:37 +02:00
|
|
|
case SCHATTR_REGRESSION_DEGREE:
|
|
|
|
{
|
2013-11-20 22:40:51 +01:00
|
|
|
uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
|
2013-11-21 20:25:53 +01:00
|
|
|
bChanged = lclConvertToPropertySet<sal_Int32, SfxInt32Item>(rItemSet, nWhichId, xProperties, OUString("PolynomialDegree"));
|
2013-05-27 08:02:37 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCHATTR_REGRESSION_PERIOD:
|
|
|
|
{
|
2013-11-20 22:40:51 +01:00
|
|
|
uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
|
2013-11-21 20:25:53 +01:00
|
|
|
bChanged = lclConvertToPropertySet<sal_Int32, SfxInt32Item>(rItemSet, nWhichId, xProperties, "MovingAveragePeriod");
|
2013-05-27 08:02:37 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCHATTR_REGRESSION_EXTRAPOLATE_FORWARD:
|
|
|
|
{
|
2013-11-20 22:40:51 +01:00
|
|
|
uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
|
2013-11-21 20:25:53 +01:00
|
|
|
bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties, "ExtrapolateForward");
|
2013-05-27 08:02:37 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCHATTR_REGRESSION_EXTRAPOLATE_BACKWARD:
|
|
|
|
{
|
2013-11-20 22:40:51 +01:00
|
|
|
uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
|
2013-11-21 20:25:53 +01:00
|
|
|
bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties, "ExtrapolateBackward");
|
2013-05-27 08:02:37 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCHATTR_REGRESSION_SET_INTERCEPT:
|
|
|
|
{
|
2013-11-20 22:40:51 +01:00
|
|
|
uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
|
2013-11-21 20:25:53 +01:00
|
|
|
bChanged = lclConvertToPropertySet<sal_Bool, SfxBoolItem>(rItemSet, nWhichId, xProperties, "ForceIntercept");
|
2013-05-27 08:02:37 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCHATTR_REGRESSION_INTERCEPT_VALUE:
|
|
|
|
{
|
2013-11-20 22:40:51 +01:00
|
|
|
uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
|
2013-11-21 20:25:53 +01:00
|
|
|
bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties, "InterceptValue");
|
2013-05-27 08:02:37 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-11-23 10:52:13 +00:00
|
|
|
case SCHATTR_REGRESSION_SHOW_EQUATION:
|
|
|
|
{
|
2013-11-20 22:40:51 +01:00
|
|
|
uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties());
|
2013-11-21 20:25:53 +01:00
|
|
|
bChanged = lclConvertToPropertySet<sal_Bool, SfxBoolItem>(rItemSet, nWhichId, xEqProp, "ShowEquation");
|
2007-11-23 10:52:13 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCHATTR_REGRESSION_SHOW_COEFF:
|
|
|
|
{
|
2013-11-20 22:40:51 +01:00
|
|
|
uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties());
|
2013-11-21 20:25:53 +01:00
|
|
|
bChanged = lclConvertToPropertySet<sal_Bool, SfxBoolItem>(rItemSet, nWhichId, xEqProp, "ShowCorrelationCoefficient");
|
2007-11-23 10:52:13 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return bChanged;
|
|
|
|
}
|
|
|
|
|
2013-11-21 20:25:53 +01:00
|
|
|
void RegressionCurveItemConverter::FillSpecialItem(sal_uInt16 nWhichId, SfxItemSet& rOutItemSet ) const
|
2007-11-23 10:52:13 +00:00
|
|
|
throw( uno::Exception )
|
|
|
|
{
|
2013-11-21 20:25:53 +01:00
|
|
|
uno::Reference<chart2::XRegressionCurve> xCurve(GetPropertySet(), uno::UNO_QUERY);
|
|
|
|
OSL_ASSERT(xCurve.is());
|
|
|
|
if(!xCurve.is())
|
|
|
|
return;
|
|
|
|
|
|
|
|
uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
|
2008-02-18 14:56:00 +00:00
|
|
|
|
2007-11-23 10:52:13 +00:00
|
|
|
switch( nWhichId )
|
|
|
|
{
|
2008-03-06 15:50:42 +00:00
|
|
|
case SCHATTR_REGRESSION_TYPE:
|
2008-02-18 14:56:00 +00:00
|
|
|
{
|
2013-11-21 20:25:53 +01:00
|
|
|
sal_Int32 aRegressionType = static_cast< sal_Int32 >(RegressionCurveHelper::getRegressionType(xCurve));
|
|
|
|
SvxChartRegress eRegress = static_cast< SvxChartRegress >(aRegressionType);
|
|
|
|
rOutItemSet.Put( SvxChartRegressItem( eRegress, SCHATTR_REGRESSION_TYPE ));
|
2008-02-18 14:56:00 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-05-27 08:02:37 +02:00
|
|
|
case SCHATTR_REGRESSION_DEGREE:
|
|
|
|
{
|
2013-11-21 20:25:53 +01:00
|
|
|
lclConvertToItemSet<sal_Int32, SfxInt32Item>(rOutItemSet, nWhichId, xProperties, "PolynomialDegree");
|
2013-05-27 08:02:37 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCHATTR_REGRESSION_PERIOD:
|
|
|
|
{
|
2013-11-21 20:25:53 +01:00
|
|
|
lclConvertToItemSet<sal_Int32, SfxInt32Item>(rOutItemSet, nWhichId, xProperties, "MovingAveragePeriod");
|
2013-05-27 08:02:37 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCHATTR_REGRESSION_EXTRAPOLATE_FORWARD:
|
|
|
|
{
|
2013-11-21 20:25:53 +01:00
|
|
|
lclConvertToItemSetDouble(rOutItemSet, nWhichId, xProperties, "ExtrapolateForward");
|
2013-05-27 08:02:37 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCHATTR_REGRESSION_EXTRAPOLATE_BACKWARD:
|
|
|
|
{
|
2013-11-21 20:25:53 +01:00
|
|
|
lclConvertToItemSetDouble(rOutItemSet, nWhichId, xProperties, "ExtrapolateBackward");
|
2013-05-27 08:02:37 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-06-28 19:49:25 +02:00
|
|
|
case SCHATTR_REGRESSION_SET_INTERCEPT:
|
|
|
|
{
|
2013-11-21 20:25:53 +01:00
|
|
|
lclConvertToItemSet<sal_Bool, SfxBoolItem>(rOutItemSet, nWhichId, xProperties, "ForceIntercept");
|
2013-06-28 19:49:25 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCHATTR_REGRESSION_INTERCEPT_VALUE:
|
|
|
|
{
|
2013-11-21 20:25:53 +01:00
|
|
|
lclConvertToItemSetDouble(rOutItemSet, nWhichId, xProperties, "InterceptValue");
|
2013-06-28 19:49:25 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-11-23 10:52:13 +00:00
|
|
|
case SCHATTR_REGRESSION_SHOW_EQUATION:
|
|
|
|
{
|
2013-11-21 20:25:53 +01:00
|
|
|
lclConvertToItemSet<sal_Bool, SfxBoolItem>(rOutItemSet, nWhichId, xCurve->getEquationProperties(), "ShowEquation");
|
2007-11-23 10:52:13 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCHATTR_REGRESSION_SHOW_COEFF:
|
|
|
|
{
|
2013-11-21 20:25:53 +01:00
|
|
|
lclConvertToItemSet<sal_Bool, SfxBoolItem>(rOutItemSet, nWhichId, xCurve->getEquationProperties(), "ShowCorrelationCoefficient");
|
2007-11-23 10:52:13 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace wrapper
|
|
|
|
} // namespace chart
|
2010-10-12 15:59:00 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|