LibreOffice Module chart2 (master) 1
RegressionCurveItemConverter.cxx
Go to the documentation of this file.
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
23#include "SchWhichPairs.hxx"
25#include <DataSeries.hxx>
26
27#include <com/sun/star/chart2/XRegressionCurve.hpp>
28#include <osl/diagnose.h>
29
30#include <svl/eitem.hxx>
31#include <svl/intitem.hxx>
32#include <svl/stritem.hxx>
33#include <utility>
34
35using namespace ::com::sun::star;
36
37namespace
38{
39template <class T, class D>
40bool lclConvertToPropertySet(const SfxItemSet& rItemSet, sal_uInt16 nWhichId, const uno::Reference<beans::XPropertySet>& xProperties, const OUString& aPropertyID)
41{
42 OSL_ASSERT(xProperties.is());
43 if( xProperties.is() )
44 {
45 T aValue = static_cast<T>(static_cast<const D&>(rItemSet.Get( nWhichId )).GetValue());
46 T aOldValue = aValue;
47 bool aSuccess = xProperties->getPropertyValue( aPropertyID ) >>= aOldValue;
48 if (!aSuccess || aOldValue != aValue)
49 {
50 xProperties->setPropertyValue( aPropertyID , uno::Any( aValue ));
51 return true;
52 }
53 }
54 return false;
55}
56
57template <class T, class D>
58void lclConvertToItemSet(SfxItemSet& rItemSet, sal_uInt16 nWhichId, const uno::Reference<beans::XPropertySet>& xProperties, const OUString& aPropertyID)
59{
60 OSL_ASSERT(xProperties.is());
61 if( xProperties.is() )
62 {
63 T aValue = static_cast<T>(static_cast<const D&>(rItemSet.Get( nWhichId )).GetValue());
64 if(xProperties->getPropertyValue( aPropertyID ) >>= aValue)
65 {
66 rItemSet.Put(D( nWhichId, aValue ));
67 }
68 }
69}
70
71void lclConvertToItemSetDouble(SfxItemSet& rItemSet, TypedWhichId<SvxDoubleItem> nWhichId, const uno::Reference<beans::XPropertySet>& xProperties, const OUString& aPropertyID)
72{
73 OSL_ASSERT(xProperties.is());
74 if( xProperties.is() )
75 {
76 double aValue = rItemSet.Get( nWhichId ).GetValue();
77 if(xProperties->getPropertyValue( aPropertyID ) >>= aValue)
78 {
79 rItemSet.Put(SvxDoubleItem( aValue, nWhichId ));
80 }
81 }
82}
83
84} // anonymous namespace
85
86namespace chart::wrapper
87{
88
90 const uno::Reference< beans::XPropertySet >& rPropertySet,
92 SfxItemPool& rItemPool,
93 SdrModel& rDrawModel,
94 const uno::Reference< lang::XMultiServiceFactory > & xNamedPropertyContainerFactory ) :
95 ItemConverter( rPropertySet, rItemPool ),
96 m_spGraphicConverter( std::make_shared<GraphicPropertyItemConverter>(
97 rPropertySet, rItemPool, rDrawModel,
98 xNamedPropertyContainerFactory,
100 m_xCurveContainer(std::move( xContainer ))
101{}
102
104{}
105
107{
108 m_spGraphicConverter->FillItemSet( rOutItemSet );
109
110 // own items
111 ItemConverter::FillItemSet( rOutItemSet );
112}
113
115{
116 bool bResult = m_spGraphicConverter->ApplyItemSet( rItemSet );
117
118 // own items
119 return ItemConverter::ApplyItemSet( rItemSet ) || bResult;
120}
121
123{
124 // must span all used items!
126}
127
129 tWhichIdType /* nWhichId */, tPropertyNameWithMemberId & /* rOutProperty */ ) const
130{
131 // No own (non-special) properties
132 return false;
133}
134
136 sal_uInt16 nWhichId, const SfxItemSet & rItemSet )
137{
139 bool bChanged = false;
140
141 OSL_ASSERT(xCurve.is());
142 if(!xCurve.is())
143 return false;
144
145 switch( nWhichId )
146 {
148 {
150 SvxChartRegress eNewRegress = static_cast< const SvxChartRegressItem & >(
151 rItemSet.Get( nWhichId )).GetValue();
152 if( eRegress != eNewRegress )
153 {
154 // note that changing the regression type changes the object
155 // for which this converter was created. Not optimal, but
156 // currently the only way to handle the type in the
157 // regression curve properties dialog
159 eNewRegress,
161 xCurve);
162 uno::Reference<beans::XPropertySet> xProperties( xCurve, uno::UNO_QUERY );
163 resetPropertySet( xProperties );
164 bChanged = true;
165 }
166 }
167 break;
168
170 {
171 uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
172 bChanged = lclConvertToPropertySet<sal_Int32, SfxInt32Item>(rItemSet, nWhichId, xProperties, "PolynomialDegree");
173 }
174 break;
175
177 {
178 uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
179 bChanged = lclConvertToPropertySet<sal_Int32, SfxInt32Item>(rItemSet, nWhichId, xProperties, "MovingAveragePeriod");
180 }
181 break;
182
184 {
185 uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
186 bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties, "ExtrapolateForward");
187 }
188 break;
189
191 {
192 uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
193 bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties, "ExtrapolateBackward");
194 }
195 break;
196
198 {
199 uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
200 bChanged = lclConvertToPropertySet<bool, SfxBoolItem>(rItemSet, nWhichId, xProperties, "ForceIntercept");
201 }
202 break;
203
205 {
206 uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
207 bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties, "InterceptValue");
208 }
209 break;
210
212 {
213 uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
214 bChanged = lclConvertToPropertySet<OUString, SfxStringItem>(rItemSet, nWhichId, xProperties, "CurveName");
215 }
216 break;
217
219 {
220 uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
221 bChanged = lclConvertToPropertySet<sal_Int32, SfxInt32Item>(rItemSet, nWhichId, xProperties, "MovingAverageType");
222 }
223 break;
224
226 {
227 uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties());
228 bChanged = lclConvertToPropertySet<bool, SfxBoolItem>(rItemSet, nWhichId, xEqProp, "ShowEquation");
229 }
230 break;
231
233 {
234 uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties());
235 bChanged = lclConvertToPropertySet<OUString, SfxStringItem>(rItemSet, nWhichId, xEqProp, "XName");
236 }
237 break;
238
240 {
241 uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties());
242 bChanged = lclConvertToPropertySet<OUString, SfxStringItem>(rItemSet, nWhichId, xEqProp, "YName");
243 }
244 break;
245
247 {
248 uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties());
249 bChanged = lclConvertToPropertySet<bool, SfxBoolItem>(rItemSet, nWhichId, xEqProp, "ShowCorrelationCoefficient");
250 }
251 break;
252
253 }
254 return bChanged;
255}
256
257void RegressionCurveItemConverter::FillSpecialItem(sal_uInt16 nWhichId, SfxItemSet& rOutItemSet ) const
258{
260 OSL_ASSERT(xCurve.is());
261 if(!xCurve.is())
262 return;
263
264 uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
265
266 switch( nWhichId )
267 {
269 {
271 rOutItemSet.Put( SvxChartRegressItem( eRegress, SCHATTR_REGRESSION_TYPE ));
272 }
273 break;
274
276 {
277 lclConvertToItemSet<sal_Int32, SfxInt32Item>(rOutItemSet, nWhichId, xProperties, "PolynomialDegree");
278 }
279 break;
280
282 {
283 lclConvertToItemSet<sal_Int32, SfxInt32Item>(rOutItemSet, nWhichId, xProperties, "MovingAveragePeriod");
284 }
285 break;
286
288 {
289 lclConvertToItemSetDouble(rOutItemSet, SCHATTR_REGRESSION_EXTRAPOLATE_FORWARD, xProperties, "ExtrapolateForward");
290 }
291 break;
292
294 {
295 lclConvertToItemSetDouble(rOutItemSet, SCHATTR_REGRESSION_EXTRAPOLATE_BACKWARD, xProperties, "ExtrapolateBackward");
296 }
297 break;
298
300 {
301 lclConvertToItemSet<bool, SfxBoolItem>(rOutItemSet, nWhichId, xProperties, "ForceIntercept");
302 }
303 break;
304
306 {
307 lclConvertToItemSetDouble(rOutItemSet, SCHATTR_REGRESSION_INTERCEPT_VALUE, xProperties, "InterceptValue");
308 }
309 break;
310
312 {
313 lclConvertToItemSet<OUString, SfxStringItem>(rOutItemSet, nWhichId, xProperties, "CurveName");
314 }
315 break;
316
318 {
319 lclConvertToItemSet<sal_Int32, SfxInt32Item>(rOutItemSet, nWhichId, xProperties, "MovingAverageType");
320 }
321 break;
322
324 {
325 lclConvertToItemSet<bool, SfxBoolItem>(rOutItemSet, nWhichId, xCurve->getEquationProperties(), "ShowEquation");
326 }
327 break;
328
330 {
331 lclConvertToItemSet<OUString, SfxStringItem>(rOutItemSet, nWhichId, xCurve->getEquationProperties(), "XName");
332 }
333 break;
334
336 {
337 lclConvertToItemSet<OUString, SfxStringItem>(rOutItemSet, nWhichId, xCurve->getEquationProperties(), "YName");
338 }
339 break;
340
342 {
343 lclConvertToItemSet<bool, SfxBoolItem>(rOutItemSet, nWhichId, xCurve->getEquationProperties(), "ShowCorrelationCoefficient");
344 }
345 break;
346 }
347}
348
349} // namespace chart::wrapper
350
351/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr TypedWhichId< SvxChartRegressItem > SCHATTR_REGRESSION_TYPE(SCHATTR_REGRESSION_START)
constexpr TypedWhichId< SvxDoubleItem > SCHATTR_REGRESSION_EXTRAPOLATE_FORWARD(SCHATTR_REGRESSION_START+5)
constexpr TypedWhichId< SfxBoolItem > SCHATTR_REGRESSION_SHOW_EQUATION(SCHATTR_REGRESSION_START+1)
constexpr TypedWhichId< SfxBoolItem > SCHATTR_REGRESSION_SET_INTERCEPT(SCHATTR_REGRESSION_START+7)
constexpr TypedWhichId< SfxInt32Item > SCHATTR_REGRESSION_MOVING_TYPE(SCHATTR_REGRESSION_START+12)
constexpr TypedWhichId< SfxStringItem > SCHATTR_REGRESSION_CURVE_NAME(SCHATTR_REGRESSION_START+9)
constexpr TypedWhichId< SfxStringItem > SCHATTR_REGRESSION_YNAME(SCHATTR_REGRESSION_START+11)
constexpr TypedWhichId< SfxInt32Item > SCHATTR_REGRESSION_DEGREE(SCHATTR_REGRESSION_START+3)
constexpr TypedWhichId< SfxBoolItem > SCHATTR_REGRESSION_SHOW_COEFF(SCHATTR_REGRESSION_START+2)
constexpr TypedWhichId< SvxDoubleItem > SCHATTR_REGRESSION_EXTRAPOLATE_BACKWARD(SCHATTR_REGRESSION_START+6)
constexpr TypedWhichId< SfxStringItem > SCHATTR_REGRESSION_XNAME(SCHATTR_REGRESSION_START+10)
constexpr TypedWhichId< SvxDoubleItem > SCHATTR_REGRESSION_INTERCEPT_VALUE(SCHATTR_REGRESSION_START+8)
constexpr TypedWhichId< SfxInt32Item > SCHATTR_REGRESSION_PERIOD(SCHATTR_REGRESSION_START+4)
const WhichRangesContainer nRegressionCurveWhichPairs(svl::Items< SCHATTR_REGRESSION_START, SCHATTR_REGRESSION_END, XATTR_LINE_FIRST, XATTR_LINE_LAST >)
SvxChartRegress
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
This class serves for conversion between properties of an XPropertySet and SfxItems in SfxItemSets.
void resetPropertySet(const css::uno::Reference< css::beans::XPropertySet > &xPropSet)
sets a new property set, that you get with GetPropertySet().
virtual void FillItemSet(SfxItemSet &rOutItemSet) const
applies all properties that can be mapped to items into the given item set.
std::pair< tPropertyNameType, tMemberIdType > tPropertyNameWithMemberId
const css::uno::Reference< css::beans::XPropertySet > & GetPropertySet() const
Returns the XPropertySet that was given in the CTOR and is used to apply items in ApplyItemSet().
virtual bool ApplyItemSet(const SfxItemSet &rItemSet)
applies all properties that are results of a conversion from all items in rItemSet to the internal XP...
virtual const WhichRangesContainer & GetWhichPairs() const override
implement this method to provide an array of which-ranges
virtual void FillItemSet(SfxItemSet &rOutItemSet) const override
applies all properties that can be mapped to items into the given item set.
rtl::Reference< ::chart::DataSeries > m_xCurveContainer
RegressionCurveItemConverter(const css::uno::Reference< css::beans::XPropertySet > &rPropertySet, rtl::Reference< ::chart::DataSeries > xRegCurveCnt, SfxItemPool &rItemPool, SdrModel &rDrawModel, const css::uno::Reference< css::lang::XMultiServiceFactory > &xNamedPropertyContainerFactory)
virtual bool ApplyItemSet(const SfxItemSet &rItemSet) override
applies all properties that are results of a conversion from all items in rItemSet to the internal XP...
virtual bool ApplySpecialItem(sal_uInt16 nWhichId, const SfxItemSet &rItemSet) override
for items that can not be mapped directly to a property.
virtual bool GetItemProperty(tWhichIdType nWhichId, tPropertyNameWithMemberId &rOutProperty) const override
implement this method to return a Property object for a given which id.
virtual void FillSpecialItem(sal_uInt16 nWhichId, SfxItemSet &rOutItemSet) const override
for items that can not be mapped directly to a property.
OOO_DLLPUBLIC_CHARTTOOLS rtl::Reference<::chart::RegressionCurveModel > changeRegressionCurveType(SvxChartRegress eType, css::uno::Reference< css::chart2::XRegressionCurveContainer > const &xRegressionCurveContainer, css::uno::Reference< css::chart2::XRegressionCurve > const &xRegressionCurve)
OOO_DLLPUBLIC_CHARTTOOLS SvxChartRegress getRegressionType(const css::uno::Reference< css::chart2::XRegressionCurve > &xCurve)
std::shared_ptr< T > make_shared(Args &&... args)
const char GetValue[]