1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <RegressionCurveHelper.hxx>
21 #include <RegressionCurveItemConverter.hxx>
22 #include "SchWhichPairs.hxx"
23 #include <ItemPropertyMap.hxx>
24 #include <GraphicPropertyItemConverter.hxx>
26 #include <com/sun/star/chart2/XRegressionCurve.hpp>
27 #include <osl/diagnose.h>
29 #include <svl/eitem.hxx>
30 #include <svl/intitem.hxx>
31 #include <svl/stritem.hxx>
36 using namespace ::com::sun::star
;
40 template <class T
, class D
>
41 bool lclConvertToPropertySet(const SfxItemSet
& rItemSet
, sal_uInt16 nWhichId
, const uno::Reference
<beans::XPropertySet
>& xProperties
, const OUString
& aPropertyID
)
43 OSL_ASSERT(xProperties
.is());
44 if( xProperties
.is() )
46 T aValue
= static_cast<T
>(static_cast<const D
&>(rItemSet
.Get( nWhichId
)).GetValue());
48 bool aSuccess
= xProperties
->getPropertyValue( aPropertyID
) >>= aOldValue
;
49 if (!aSuccess
|| aOldValue
!= aValue
)
51 xProperties
->setPropertyValue( aPropertyID
, uno::Any( aValue
));
58 template <class T
, class D
>
59 void lclConvertToItemSet(SfxItemSet
& rItemSet
, sal_uInt16 nWhichId
, const uno::Reference
<beans::XPropertySet
>& xProperties
, const OUString
& aPropertyID
)
61 OSL_ASSERT(xProperties
.is());
62 if( xProperties
.is() )
64 T aValue
= static_cast<T
>(static_cast<const D
&>(rItemSet
.Get( nWhichId
)).GetValue());
65 if(xProperties
->getPropertyValue( aPropertyID
) >>= aValue
)
67 rItemSet
.Put(D( nWhichId
, aValue
));
72 void lclConvertToItemSetDouble(SfxItemSet
& rItemSet
, sal_uInt16 nWhichId
, const uno::Reference
<beans::XPropertySet
>& xProperties
, const OUString
& aPropertyID
)
74 OSL_ASSERT(xProperties
.is());
75 if( xProperties
.is() )
77 double aValue
= static_cast<const SvxDoubleItem
&>(rItemSet
.Get( nWhichId
)).GetValue();
78 if(xProperties
->getPropertyValue( aPropertyID
) >>= aValue
)
80 rItemSet
.Put(SvxDoubleItem( aValue
, nWhichId
));
85 } // anonymous namespace
92 RegressionCurveItemConverter::RegressionCurveItemConverter(
93 const uno::Reference
< beans::XPropertySet
>& rPropertySet
,
94 const uno::Reference
< chart2::XRegressionCurveContainer
>& xContainer
,
95 SfxItemPool
& rItemPool
,
97 const uno::Reference
< lang::XMultiServiceFactory
> & xNamedPropertyContainerFactory
) :
98 ItemConverter( rPropertySet
, rItemPool
),
99 m_spGraphicConverter( new GraphicPropertyItemConverter(
100 rPropertySet
, rItemPool
, rDrawModel
,
101 xNamedPropertyContainerFactory
,
102 GraphicObjectType::LineProperties
)),
103 m_xCurveContainer( xContainer
)
106 RegressionCurveItemConverter::~RegressionCurveItemConverter()
109 void RegressionCurveItemConverter::FillItemSet( SfxItemSet
& rOutItemSet
) const
111 m_spGraphicConverter
->FillItemSet( rOutItemSet
);
114 ItemConverter::FillItemSet( rOutItemSet
);
117 bool RegressionCurveItemConverter::ApplyItemSet( const SfxItemSet
& rItemSet
)
119 bool bResult
= m_spGraphicConverter
->ApplyItemSet( rItemSet
);
122 return ItemConverter::ApplyItemSet( rItemSet
) || bResult
;
125 const sal_uInt16
* RegressionCurveItemConverter::GetWhichPairs() const
127 // must span all used items!
128 return nRegressionCurveWhichPairs
;
131 bool RegressionCurveItemConverter::GetItemProperty(
132 tWhichIdType
/* nWhichId */, tPropertyNameWithMemberId
& /* rOutProperty */ ) const
134 // No own (non-special) properties
138 bool RegressionCurveItemConverter::ApplySpecialItem(
139 sal_uInt16 nWhichId
, const SfxItemSet
& rItemSet
)
141 uno::Reference
< chart2::XRegressionCurve
> xCurve( GetPropertySet(), uno::UNO_QUERY
);
142 bool bChanged
= false;
144 OSL_ASSERT(xCurve
.is());
150 case SCHATTR_REGRESSION_TYPE
:
152 SvxChartRegress eRegress
= RegressionCurveHelper::getRegressionType(xCurve
);
153 SvxChartRegress eNewRegress
= static_cast< const SvxChartRegressItem
& >(
154 rItemSet
.Get( nWhichId
)).GetValue();
155 if( eRegress
!= eNewRegress
)
157 // note that changing the regression type changes the object
158 // for which this converter was created. Not optimal, but
159 // currently the only way to handle the type in the
160 // regression curve properties dialog
161 xCurve
= RegressionCurveHelper::changeRegressionCurveType(
165 uno::Reference
<beans::XPropertySet
> xProperties( xCurve
, uno::UNO_QUERY
);
166 resetPropertySet( xProperties
);
172 case SCHATTR_REGRESSION_DEGREE
:
174 uno::Reference
< beans::XPropertySet
> xProperties( xCurve
, uno::UNO_QUERY
);
175 bChanged
= lclConvertToPropertySet
<sal_Int32
, SfxInt32Item
>(rItemSet
, nWhichId
, xProperties
, "PolynomialDegree");
179 case SCHATTR_REGRESSION_PERIOD
:
181 uno::Reference
< beans::XPropertySet
> xProperties( xCurve
, uno::UNO_QUERY
);
182 bChanged
= lclConvertToPropertySet
<sal_Int32
, SfxInt32Item
>(rItemSet
, nWhichId
, xProperties
, "MovingAveragePeriod");
186 case SCHATTR_REGRESSION_EXTRAPOLATE_FORWARD
:
188 uno::Reference
< beans::XPropertySet
> xProperties( xCurve
, uno::UNO_QUERY
);
189 bChanged
= lclConvertToPropertySet
<double, SvxDoubleItem
>(rItemSet
, nWhichId
, xProperties
, "ExtrapolateForward");
193 case SCHATTR_REGRESSION_EXTRAPOLATE_BACKWARD
:
195 uno::Reference
< beans::XPropertySet
> xProperties( xCurve
, uno::UNO_QUERY
);
196 bChanged
= lclConvertToPropertySet
<double, SvxDoubleItem
>(rItemSet
, nWhichId
, xProperties
, "ExtrapolateBackward");
200 case SCHATTR_REGRESSION_SET_INTERCEPT
:
202 uno::Reference
< beans::XPropertySet
> xProperties( xCurve
, uno::UNO_QUERY
);
203 bChanged
= lclConvertToPropertySet
<bool, SfxBoolItem
>(rItemSet
, nWhichId
, xProperties
, "ForceIntercept");
207 case SCHATTR_REGRESSION_INTERCEPT_VALUE
:
209 uno::Reference
< beans::XPropertySet
> xProperties( xCurve
, uno::UNO_QUERY
);
210 bChanged
= lclConvertToPropertySet
<double, SvxDoubleItem
>(rItemSet
, nWhichId
, xProperties
, "InterceptValue");
214 case SCHATTR_REGRESSION_CURVE_NAME
:
216 uno::Reference
< beans::XPropertySet
> xProperties( xCurve
, uno::UNO_QUERY
);
217 bChanged
= lclConvertToPropertySet
<OUString
, SfxStringItem
>(rItemSet
, nWhichId
, xProperties
, "CurveName");
221 case SCHATTR_REGRESSION_SHOW_EQUATION
:
223 uno::Reference
< beans::XPropertySet
> xEqProp( xCurve
->getEquationProperties());
224 bChanged
= lclConvertToPropertySet
<bool, SfxBoolItem
>(rItemSet
, nWhichId
, xEqProp
, "ShowEquation");
228 case SCHATTR_REGRESSION_XNAME
:
230 uno::Reference
< beans::XPropertySet
> xEqProp( xCurve
->getEquationProperties());
231 bChanged
= lclConvertToPropertySet
<OUString
, SfxStringItem
>(rItemSet
, nWhichId
, xEqProp
, "XName");
235 case SCHATTR_REGRESSION_YNAME
:
237 uno::Reference
< beans::XPropertySet
> xEqProp( xCurve
->getEquationProperties());
238 bChanged
= lclConvertToPropertySet
<OUString
, SfxStringItem
>(rItemSet
, nWhichId
, xEqProp
, "YName");
242 case SCHATTR_REGRESSION_SHOW_COEFF
:
244 uno::Reference
< beans::XPropertySet
> xEqProp( xCurve
->getEquationProperties());
245 bChanged
= lclConvertToPropertySet
<bool, SfxBoolItem
>(rItemSet
, nWhichId
, xEqProp
, "ShowCorrelationCoefficient");
253 void RegressionCurveItemConverter::FillSpecialItem(sal_uInt16 nWhichId
, SfxItemSet
& rOutItemSet
) const
255 uno::Reference
<chart2::XRegressionCurve
> xCurve(GetPropertySet(), uno::UNO_QUERY
);
256 OSL_ASSERT(xCurve
.is());
260 uno::Reference
< beans::XPropertySet
> xProperties( xCurve
, uno::UNO_QUERY
);
264 case SCHATTR_REGRESSION_TYPE
:
266 SvxChartRegress eRegress
= RegressionCurveHelper::getRegressionType(xCurve
);
267 rOutItemSet
.Put( SvxChartRegressItem( eRegress
, SCHATTR_REGRESSION_TYPE
));
271 case SCHATTR_REGRESSION_DEGREE
:
273 lclConvertToItemSet
<sal_Int32
, SfxInt32Item
>(rOutItemSet
, nWhichId
, xProperties
, "PolynomialDegree");
277 case SCHATTR_REGRESSION_PERIOD
:
279 lclConvertToItemSet
<sal_Int32
, SfxInt32Item
>(rOutItemSet
, nWhichId
, xProperties
, "MovingAveragePeriod");
283 case SCHATTR_REGRESSION_EXTRAPOLATE_FORWARD
:
285 lclConvertToItemSetDouble(rOutItemSet
, nWhichId
, xProperties
, "ExtrapolateForward");
289 case SCHATTR_REGRESSION_EXTRAPOLATE_BACKWARD
:
291 lclConvertToItemSetDouble(rOutItemSet
, nWhichId
, xProperties
, "ExtrapolateBackward");
295 case SCHATTR_REGRESSION_SET_INTERCEPT
:
297 lclConvertToItemSet
<bool, SfxBoolItem
>(rOutItemSet
, nWhichId
, xProperties
, "ForceIntercept");
301 case SCHATTR_REGRESSION_INTERCEPT_VALUE
:
303 lclConvertToItemSetDouble(rOutItemSet
, nWhichId
, xProperties
, "InterceptValue");
307 case SCHATTR_REGRESSION_CURVE_NAME
:
309 lclConvertToItemSet
<OUString
, SfxStringItem
>(rOutItemSet
, nWhichId
, xProperties
, "CurveName");
313 case SCHATTR_REGRESSION_SHOW_EQUATION
:
315 lclConvertToItemSet
<bool, SfxBoolItem
>(rOutItemSet
, nWhichId
, xCurve
->getEquationProperties(), "ShowEquation");
319 case SCHATTR_REGRESSION_XNAME
:
321 lclConvertToItemSet
<OUString
, SfxStringItem
>(rOutItemSet
, nWhichId
, xCurve
->getEquationProperties(), "XName");
325 case SCHATTR_REGRESSION_YNAME
:
327 lclConvertToItemSet
<OUString
, SfxStringItem
>(rOutItemSet
, nWhichId
, xCurve
->getEquationProperties(), "YName");
331 case SCHATTR_REGRESSION_SHOW_COEFF
:
333 lclConvertToItemSet
<bool, SfxBoolItem
>(rOutItemSet
, nWhichId
, xCurve
->getEquationProperties(), "ShowCorrelationCoefficient");
339 } // namespace wrapper
342 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */