fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / controller / itemsetwrapper / RegressionCurveItemConverter.cxx
blobae3ac82a59b7599261230b212c2055a4fa94e475
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "macros.hxx"
24 #include "ItemPropertyMap.hxx"
25 #include "GraphicPropertyItemConverter.hxx"
27 #include <com/sun/star/chart2/XRegressionCurve.hpp>
28 #include <osl/diagnose.h>
30 #include <svl/eitem.hxx>
31 #include <svl/intitem.hxx>
32 #include <svl/stritem.hxx>
34 #include <functional>
35 #include <algorithm>
37 #include <boost/checked_delete.hpp>
39 using namespace ::com::sun::star;
41 namespace
43 template <class T, class D>
44 bool lclConvertToPropertySet(const SfxItemSet& rItemSet, sal_uInt16 nWhichId, uno::Reference<beans::XPropertySet> xProperties, const OUString& aPropertyID)
46 OSL_ASSERT(xProperties.is());
47 if( xProperties.is() )
49 T aValue = static_cast<T>(static_cast<const D&>(rItemSet.Get( nWhichId )).GetValue());
50 T aOldValue = aValue;
51 bool aSuccess = xProperties->getPropertyValue( aPropertyID ) >>= aOldValue;
52 if (!aSuccess || aOldValue != aValue)
54 xProperties->setPropertyValue( aPropertyID , uno::makeAny( aValue ));
55 return true;
58 return false;
61 template <class T, class D>
62 void lclConvertToItemSet(SfxItemSet& rItemSet, sal_uInt16 nWhichId, uno::Reference<beans::XPropertySet> xProperties, const OUString& aPropertyID)
64 OSL_ASSERT(xProperties.is());
65 if( xProperties.is() )
67 T aValue = static_cast<T>(static_cast<const D&>(rItemSet.Get( nWhichId )).GetValue());
68 if(xProperties->getPropertyValue( aPropertyID ) >>= aValue)
70 rItemSet.Put(D( nWhichId, aValue ));
75 void lclConvertToItemSetDouble(SfxItemSet& rItemSet, sal_uInt16 nWhichId, uno::Reference<beans::XPropertySet> xProperties, const OUString& aPropertyID)
77 OSL_ASSERT(xProperties.is());
78 if( xProperties.is() )
80 double aValue = static_cast<double>(static_cast<const SvxDoubleItem&>(rItemSet.Get( nWhichId )).GetValue());
81 if(xProperties->getPropertyValue( aPropertyID ) >>= aValue)
83 rItemSet.Put(SvxDoubleItem( aValue, nWhichId ));
88 } // anonymous namespace
90 namespace chart
92 namespace wrapper
95 RegressionCurveItemConverter::RegressionCurveItemConverter(
96 const uno::Reference< beans::XPropertySet >& rPropertySet,
97 const uno::Reference< chart2::XRegressionCurveContainer >& xContainer,
98 SfxItemPool& rItemPool,
99 SdrModel& rDrawModel,
100 const uno::Reference< lang::XMultiServiceFactory > & xNamedPropertyContainerFactory ) :
101 ItemConverter( rPropertySet, rItemPool ),
102 m_spGraphicConverter( new GraphicPropertyItemConverter(
103 rPropertySet, rItemPool, rDrawModel,
104 xNamedPropertyContainerFactory,
105 GraphicPropertyItemConverter::LINE_PROPERTIES )),
106 m_xCurveContainer( xContainer )
109 RegressionCurveItemConverter::~RegressionCurveItemConverter()
112 void RegressionCurveItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
114 m_spGraphicConverter->FillItemSet( rOutItemSet );
116 // own items
117 ItemConverter::FillItemSet( rOutItemSet );
120 bool RegressionCurveItemConverter::ApplyItemSet( const SfxItemSet & rItemSet )
122 bool bResult = m_spGraphicConverter->ApplyItemSet( rItemSet );
124 // own items
125 return ItemConverter::ApplyItemSet( rItemSet ) || bResult;
128 const sal_uInt16 * RegressionCurveItemConverter::GetWhichPairs() const
130 // must span all used items!
131 return nRegressionCurveWhichPairs;
134 bool RegressionCurveItemConverter::GetItemProperty(
135 tWhichIdType /* nWhichId */, tPropertyNameWithMemberId & /* rOutProperty */ ) const
137 // No own (non-special) properties
138 return false;
141 bool RegressionCurveItemConverter::ApplySpecialItem(
142 sal_uInt16 nWhichId, const SfxItemSet & rItemSet )
143 throw( uno::Exception )
145 uno::Reference< chart2::XRegressionCurve > xCurve( GetPropertySet(), uno::UNO_QUERY );
146 bool bChanged = false;
148 OSL_ASSERT(xCurve.is());
149 if(!xCurve.is())
150 return false;
152 switch( nWhichId )
154 case SCHATTR_REGRESSION_TYPE:
156 SvxChartRegress eRegress = RegressionCurveHelper::getRegressionType(xCurve);
157 SvxChartRegress eNewRegress = static_cast< const SvxChartRegressItem & >(
158 rItemSet.Get( nWhichId )).GetValue();
159 if( eRegress != eNewRegress )
161 // note that changing the regression type changes the object
162 // for which this converter was created. Not optimal, but
163 // currently the only way to handle the type in the
164 // regression curve properties dialog
165 xCurve = RegressionCurveHelper::changeRegressionCurveType(
166 eNewRegress,
167 m_xCurveContainer,
168 xCurve,
169 uno::Reference< uno::XComponentContext >());
170 uno::Reference<beans::XPropertySet> xProperties( xCurve, uno::UNO_QUERY );
171 resetPropertySet( xProperties );
172 bChanged = true;
175 break;
177 case SCHATTR_REGRESSION_DEGREE:
179 uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
180 bChanged = lclConvertToPropertySet<sal_Int32, SfxInt32Item>(rItemSet, nWhichId, xProperties, OUString("PolynomialDegree"));
182 break;
184 case SCHATTR_REGRESSION_PERIOD:
186 uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
187 bChanged = lclConvertToPropertySet<sal_Int32, SfxInt32Item>(rItemSet, nWhichId, xProperties, "MovingAveragePeriod");
189 break;
191 case SCHATTR_REGRESSION_EXTRAPOLATE_FORWARD:
193 uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
194 bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties, "ExtrapolateForward");
196 break;
198 case SCHATTR_REGRESSION_EXTRAPOLATE_BACKWARD:
200 uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
201 bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties, "ExtrapolateBackward");
203 break;
205 case SCHATTR_REGRESSION_SET_INTERCEPT:
207 uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
208 bChanged = lclConvertToPropertySet<sal_Bool, SfxBoolItem>(rItemSet, nWhichId, xProperties, "ForceIntercept");
210 break;
212 case SCHATTR_REGRESSION_INTERCEPT_VALUE:
214 uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
215 bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties, "InterceptValue");
217 break;
219 case SCHATTR_REGRESSION_CURVE_NAME:
221 uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
222 bChanged = lclConvertToPropertySet<OUString, SfxStringItem>(rItemSet, nWhichId, xProperties, "CurveName");
224 break;
226 case SCHATTR_REGRESSION_SHOW_EQUATION:
228 uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties());
229 bChanged = lclConvertToPropertySet<sal_Bool, SfxBoolItem>(rItemSet, nWhichId, xEqProp, "ShowEquation");
231 break;
233 case SCHATTR_REGRESSION_SHOW_COEFF:
235 uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties());
236 bChanged = lclConvertToPropertySet<sal_Bool, SfxBoolItem>(rItemSet, nWhichId, xEqProp, "ShowCorrelationCoefficient");
238 break;
241 return bChanged;
244 void RegressionCurveItemConverter::FillSpecialItem(sal_uInt16 nWhichId, SfxItemSet& rOutItemSet ) const
245 throw( uno::Exception )
247 uno::Reference<chart2::XRegressionCurve> xCurve(GetPropertySet(), uno::UNO_QUERY);
248 OSL_ASSERT(xCurve.is());
249 if(!xCurve.is())
250 return;
252 uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
254 switch( nWhichId )
256 case SCHATTR_REGRESSION_TYPE:
258 SvxChartRegress eRegress = RegressionCurveHelper::getRegressionType(xCurve);
259 rOutItemSet.Put( SvxChartRegressItem( eRegress, SCHATTR_REGRESSION_TYPE ));
261 break;
263 case SCHATTR_REGRESSION_DEGREE:
265 lclConvertToItemSet<sal_Int32, SfxInt32Item>(rOutItemSet, nWhichId, xProperties, "PolynomialDegree");
267 break;
269 case SCHATTR_REGRESSION_PERIOD:
271 lclConvertToItemSet<sal_Int32, SfxInt32Item>(rOutItemSet, nWhichId, xProperties, "MovingAveragePeriod");
273 break;
275 case SCHATTR_REGRESSION_EXTRAPOLATE_FORWARD:
277 lclConvertToItemSetDouble(rOutItemSet, nWhichId, xProperties, "ExtrapolateForward");
279 break;
281 case SCHATTR_REGRESSION_EXTRAPOLATE_BACKWARD:
283 lclConvertToItemSetDouble(rOutItemSet, nWhichId, xProperties, "ExtrapolateBackward");
285 break;
287 case SCHATTR_REGRESSION_SET_INTERCEPT:
289 lclConvertToItemSet<sal_Bool, SfxBoolItem>(rOutItemSet, nWhichId, xProperties, "ForceIntercept");
291 break;
293 case SCHATTR_REGRESSION_INTERCEPT_VALUE:
295 lclConvertToItemSetDouble(rOutItemSet, nWhichId, xProperties, "InterceptValue");
297 break;
299 case SCHATTR_REGRESSION_CURVE_NAME:
301 lclConvertToItemSet<OUString, SfxStringItem>(rOutItemSet, nWhichId, xProperties, "CurveName");
303 break;
305 case SCHATTR_REGRESSION_SHOW_EQUATION:
307 lclConvertToItemSet<sal_Bool, SfxBoolItem>(rOutItemSet, nWhichId, xCurve->getEquationProperties(), "ShowEquation");
309 break;
311 case SCHATTR_REGRESSION_SHOW_COEFF:
313 lclConvertToItemSet<sal_Bool, SfxBoolItem>(rOutItemSet, nWhichId, xCurve->getEquationProperties(), "ShowCorrelationCoefficient");
315 break;
319 } // namespace wrapper
320 } // namespace chart
322 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */