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 "WrappedStatisticProperties.hxx"
21 #include "WrappedSeriesOrDiagramProperty.hxx"
22 #include <FastPropertyIdRanges.hxx>
23 #include <RegressionCurveHelper.hxx>
24 #include <RegressionCurveModel.hxx>
25 #include <ErrorBar.hxx>
26 #include <StatisticsHelper.hxx>
27 #include <unonames.hxx>
28 
29 #include <com/sun/star/beans/PropertyAttribute.hpp>
30 #include <com/sun/star/beans/XPropertySet.hpp>
31 #include <com/sun/star/chart/ChartErrorCategory.hpp>
32 #include <com/sun/star/chart/ErrorBarStyle.hpp>
33 #include <com/sun/star/chart/ChartErrorIndicatorType.hpp>
34 #include <com/sun/star/chart/ChartRegressionCurveType.hpp>
35 #include <com/sun/star/chart2/data/XRangeXMLConversion.hpp>
36 #include <com/sun/star/chart2/XRegressionCurveContainer.hpp>
37 #include <utility>
38 
39 namespace com::sun::star::chart2::data { class XDataProvider; }
40 
41 using namespace ::com::sun::star;
42 using ::com::sun::star::uno::Any;
43 using ::com::sun::star::uno::Reference;
44 using ::com::sun::star::beans::Property;
45 
46 namespace chart::wrapper
47 {
48 
49 namespace
50 {
51 
lcl_getRegressionDefault()52 Any lcl_getRegressionDefault()
53 {
54     Any aRet;
55     aRet <<= css::chart::ChartRegressionCurveType_NONE;
56     return aRet;
57 }
58 
lcl_getRegressionCurveType(SvxChartRegress eRegressionType)59 css::chart::ChartRegressionCurveType lcl_getRegressionCurveType(SvxChartRegress eRegressionType)
60 {
61     css::chart::ChartRegressionCurveType eRet = css::chart::ChartRegressionCurveType_NONE;
62     switch(eRegressionType)
63     {
64         case SvxChartRegress::Linear:
65             eRet = css::chart::ChartRegressionCurveType_LINEAR;
66             break;
67         case SvxChartRegress::Log:
68             eRet = css::chart::ChartRegressionCurveType_LOGARITHM;
69             break;
70         case SvxChartRegress::Exp:
71             eRet = css::chart::ChartRegressionCurveType_EXPONENTIAL;
72             break;
73         case SvxChartRegress::Power:
74             eRet = css::chart::ChartRegressionCurveType_POWER;
75             break;
76         case SvxChartRegress::Polynomial:
77             eRet = css::chart::ChartRegressionCurveType_POLYNOMIAL;
78             break;
79         /*case SvxChartRegress::MovingAverage:
80             eRet = css::chart::ChartRegressionCurveType_MOVING_AVERAGE;
81             break;*/
82         default:
83             eRet = css::chart::ChartRegressionCurveType_NONE;
84             break;
85     }
86     return eRet;
87 }
88 
lcl_getRegressionType(css::chart::ChartRegressionCurveType eRegressionCurveType)89 SvxChartRegress lcl_getRegressionType( css::chart::ChartRegressionCurveType eRegressionCurveType )
90 {
91     SvxChartRegress eRet;
92     switch (eRegressionCurveType)
93     {
94         case css::chart::ChartRegressionCurveType_LINEAR:
95             eRet = SvxChartRegress::Linear;
96             break;
97         case css::chart::ChartRegressionCurveType_LOGARITHM:
98             eRet = SvxChartRegress::Log;
99             break;
100         case css::chart::ChartRegressionCurveType_EXPONENTIAL:
101             eRet = SvxChartRegress::Exp;
102             break;
103         case css::chart::ChartRegressionCurveType_POLYNOMIAL:
104         //case css::chart::ChartRegressionCurveType_MOVING_AVERAGE:
105         case css::chart::ChartRegressionCurveType_POWER:
106             eRet = SvxChartRegress::Power;
107             break;
108         default:
109             eRet = SvxChartRegress::NONE;
110             break;
111     }
112     return eRet;
113 }
114 
lcl_getErrorBarStyle(const uno::Reference<beans::XPropertySet> & xErrorBarProperties)115 sal_Int32 lcl_getErrorBarStyle( const uno::Reference< beans::XPropertySet >& xErrorBarProperties )
116 {
117     sal_Int32 nStyle = css::chart::ErrorBarStyle::NONE;
118     if(xErrorBarProperties.is())
119         xErrorBarProperties->getPropertyValue( u"ErrorBarStyle"_ustr ) >>= nStyle;
120     return nStyle;
121 }
122 
lcl_getDataProviderFromContact(const std::shared_ptr<Chart2ModelContact> & spChart2ModelContact)123 uno::Reference< chart2::data::XDataProvider > lcl_getDataProviderFromContact(
124     const std::shared_ptr< Chart2ModelContact >& spChart2ModelContact )
125 {
126     uno::Reference< chart2::data::XDataProvider > xResult;
127     if( spChart2ModelContact)
128     {
129         rtl::Reference< ChartModel > xChartDoc(
130             spChart2ModelContact->getDocumentModel());
131         if( xChartDoc.is())
132             xResult.set( xChartDoc->getDataProvider());
133     }
134     return xResult;
135 }
136 
lcl_ConvertRangeFromXML(OUString & rInOutRange,const std::shared_ptr<Chart2ModelContact> & spChart2ModelContact)137 void lcl_ConvertRangeFromXML(
138     OUString & rInOutRange,
139     const std::shared_ptr< Chart2ModelContact >& spChart2ModelContact )
140 {
141     if( !rInOutRange.isEmpty())
142     {
143         uno::Reference< chart2::data::XRangeXMLConversion > xConverter(
144             lcl_getDataProviderFromContact( spChart2ModelContact ), uno::UNO_QUERY );
145         if( xConverter.is())
146         {
147             rInOutRange = xConverter->convertRangeFromXML( rInOutRange );
148         }
149     }
150 }
151 
lcl_ConvertRangeToXML(OUString & rInOutRange,const std::shared_ptr<Chart2ModelContact> & spChart2ModelContact)152 void lcl_ConvertRangeToXML(
153     OUString & rInOutRange,
154     const std::shared_ptr< Chart2ModelContact >& spChart2ModelContact )
155 {
156     if( !rInOutRange.isEmpty())
157     {
158         uno::Reference< chart2::data::XRangeXMLConversion > xConverter(
159             lcl_getDataProviderFromContact( spChart2ModelContact ), uno::UNO_QUERY );
160         if( xConverter.is())
161         {
162             rInOutRange = xConverter->convertRangeToXML( rInOutRange );
163         }
164     }
165 }
166 
167 template< typename PROPERTYTYPE >
168 class WrappedStatisticProperty : public WrappedSeriesOrDiagramProperty< PROPERTYTYPE >
169 {
170 public:
WrappedStatisticProperty(const OUString & rName,const Any & rDefaulValue,const std::shared_ptr<Chart2ModelContact> & spChart2ModelContact,tSeriesOrDiagramPropertyType ePropertyType)171     explicit WrappedStatisticProperty(
172         const OUString& rName, const Any& rDefaulValue,
173         const std::shared_ptr<Chart2ModelContact>& spChart2ModelContact,
174         tSeriesOrDiagramPropertyType ePropertyType)
175         : WrappedSeriesOrDiagramProperty<PROPERTYTYPE>(rName, rDefaulValue, spChart2ModelContact,
176                                                        ePropertyType)
177     {}
178 
179 protected:
getOrCreateErrorBarProperties(const Reference<beans::XPropertySet> & xSeriesPropertySet)180     static uno::Reference< beans::XPropertySet > getOrCreateErrorBarProperties( const Reference< beans::XPropertySet >& xSeriesPropertySet )
181     {
182         if(!xSeriesPropertySet.is())
183             return nullptr;
184         uno::Reference< beans::XPropertySet > xErrorBarProperties;
185         xSeriesPropertySet->getPropertyValue( CHART_UNONAME_ERRORBAR_Y ) >>= xErrorBarProperties;
186         if( !xErrorBarProperties.is() )
187         {
188             xErrorBarProperties = new ::chart::ErrorBar;
189             //default in new and old api are different
190             xErrorBarProperties->setPropertyValue( u"ShowPositiveError"_ustr , uno::Any(false) );
191             xErrorBarProperties->setPropertyValue( u"ShowNegativeError"_ustr , uno::Any(false) );
192             xErrorBarProperties->setPropertyValue( u"ErrorBarStyle"_ustr , uno::Any(css::chart::ErrorBarStyle::NONE) );
193             xSeriesPropertySet->setPropertyValue( CHART_UNONAME_ERRORBAR_Y , uno::Any( xErrorBarProperties ) );
194         }
195         return xErrorBarProperties;
196     }
197 
198 };
199 
200 //PROP_CHART_STATISTIC_CONST_ERROR_LOW
201 class WrappedConstantErrorLowProperty : public WrappedStatisticProperty< double >
202 {
203 public:
204     virtual double getValueFromSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet ) const override;
205     virtual void setValueToSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet, const double& aNewValue ) const override;
206 
207     explicit WrappedConstantErrorLowProperty( std::shared_ptr< Chart2ModelContact > spChart2ModelContact,
208                                               tSeriesOrDiagramPropertyType ePropertyType );
209 
210 private:
211     mutable Any m_aOuterValue;
212 };
213 
214 }//anonymous namespace
215 
WrappedConstantErrorLowProperty(std::shared_ptr<Chart2ModelContact> spChart2ModelContact,tSeriesOrDiagramPropertyType ePropertyType)216 WrappedConstantErrorLowProperty::WrappedConstantErrorLowProperty(
217     std::shared_ptr< Chart2ModelContact > spChart2ModelContact,
218     tSeriesOrDiagramPropertyType ePropertyType )
219         : WrappedStatisticProperty< double >( u"ConstantErrorLow"_ustr
220             , uno::Any( 0.0 ), std::move(spChart2ModelContact), ePropertyType  )
221 {
222 }
223 
getValueFromSeries(const Reference<beans::XPropertySet> & xSeriesPropertySet) const224 double WrappedConstantErrorLowProperty::getValueFromSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet ) const
225 {
226     double aRet = 0.0;
227     m_aDefaultValue >>= aRet;
228     uno::Reference< beans::XPropertySet > xErrorBarProperties;
229     if( xSeriesPropertySet.is() && ( xSeriesPropertySet->getPropertyValue( CHART_UNONAME_ERRORBAR_Y ) >>= xErrorBarProperties ) && xErrorBarProperties.is())
230     {
231         if( lcl_getErrorBarStyle( xErrorBarProperties ) == css::chart::ErrorBarStyle::ABSOLUTE )
232             xErrorBarProperties->getPropertyValue( u"NegativeError"_ustr ) >>= aRet;
233         else
234             m_aOuterValue >>= aRet;
235     }
236     return aRet;
237 }
238 
setValueToSeries(const Reference<beans::XPropertySet> & xSeriesPropertySet,const double & aNewValue) const239 void WrappedConstantErrorLowProperty::setValueToSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet, const double& aNewValue ) const
240 {
241     uno::Reference< beans::XPropertySet > xErrorBarProperties( getOrCreateErrorBarProperties(xSeriesPropertySet) );
242     if( xErrorBarProperties.is() )
243     {
244         m_aOuterValue <<= aNewValue;
245         if( lcl_getErrorBarStyle( xErrorBarProperties ) == css::chart::ErrorBarStyle::ABSOLUTE )
246         {
247             xErrorBarProperties->setPropertyValue( u"NegativeError"_ustr, m_aOuterValue );
248         }
249     }
250 }
251 
252 namespace {
253 
254 //PROP_CHART_STATISTIC_CONST_ERROR_HIGH
255 class WrappedConstantErrorHighProperty : public WrappedStatisticProperty< double >
256 {
257 public:
258     virtual double getValueFromSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet ) const override;
259     virtual void setValueToSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet, const double& aNewValue ) const override;
260 
261     explicit WrappedConstantErrorHighProperty( std::shared_ptr< Chart2ModelContact > spChart2ModelContact,
262                                                tSeriesOrDiagramPropertyType ePropertyType );
263 
264 private:
265     mutable Any m_aOuterValue;
266 };
267 
268 }
269 
WrappedConstantErrorHighProperty(std::shared_ptr<Chart2ModelContact> spChart2ModelContact,tSeriesOrDiagramPropertyType ePropertyType)270 WrappedConstantErrorHighProperty::WrappedConstantErrorHighProperty(
271     std::shared_ptr< Chart2ModelContact > spChart2ModelContact,
272     tSeriesOrDiagramPropertyType ePropertyType )
273         : WrappedStatisticProperty< double >( u"ConstantErrorHigh"_ustr
274             , uno::Any( 0.0 ), std::move(spChart2ModelContact), ePropertyType  )
275 {
276 }
277 
getValueFromSeries(const Reference<beans::XPropertySet> & xSeriesPropertySet) const278 double WrappedConstantErrorHighProperty::getValueFromSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet ) const
279 {
280     double aRet = 0.0;
281     m_aDefaultValue >>= aRet;
282     uno::Reference< beans::XPropertySet > xErrorBarProperties;
283     if( xSeriesPropertySet.is() && ( xSeriesPropertySet->getPropertyValue( CHART_UNONAME_ERRORBAR_Y ) >>= xErrorBarProperties ) && xErrorBarProperties.is())
284     {
285         if( lcl_getErrorBarStyle( xErrorBarProperties ) == css::chart::ErrorBarStyle::ABSOLUTE )
286             xErrorBarProperties->getPropertyValue( u"PositiveError"_ustr ) >>= aRet;
287         else
288             m_aOuterValue >>= aRet;
289     }
290     return aRet;
291 }
292 
setValueToSeries(const Reference<beans::XPropertySet> & xSeriesPropertySet,const double & aNewValue) const293 void WrappedConstantErrorHighProperty::setValueToSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet, const double& aNewValue ) const
294 {
295     uno::Reference< beans::XPropertySet > xErrorBarProperties( getOrCreateErrorBarProperties(xSeriesPropertySet) );
296     if( xErrorBarProperties.is() )
297     {
298         m_aOuterValue <<= aNewValue;
299         if( lcl_getErrorBarStyle( xErrorBarProperties ) == css::chart::ErrorBarStyle::ABSOLUTE )
300         {
301             xErrorBarProperties->setPropertyValue( u"PositiveError"_ustr , m_aOuterValue );
302         }
303     }
304 }
305 
306 namespace {
307 
308 //PROP_CHART_STATISTIC_MEAN_VALUE
309 class WrappedMeanValueProperty : public WrappedStatisticProperty< bool >
310 {
311 public:
312     virtual bool getValueFromSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet ) const override;
313     virtual void setValueToSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet, const bool& aNewValue ) const override;
314 
315     explicit WrappedMeanValueProperty( std::shared_ptr< Chart2ModelContact > spChart2ModelContact,
316                                        tSeriesOrDiagramPropertyType ePropertyType );
317 };
318 
319 }
320 
WrappedMeanValueProperty(std::shared_ptr<Chart2ModelContact> spChart2ModelContact,tSeriesOrDiagramPropertyType ePropertyType)321 WrappedMeanValueProperty::WrappedMeanValueProperty(
322     std::shared_ptr< Chart2ModelContact > spChart2ModelContact,
323     tSeriesOrDiagramPropertyType ePropertyType )
324         : WrappedStatisticProperty< bool >( u"MeanValue"_ustr, uno::Any( false ), std::move(spChart2ModelContact), ePropertyType  )
325 {
326 }
327 
getValueFromSeries(const Reference<beans::XPropertySet> & xSeriesPropertySet) const328 bool WrappedMeanValueProperty::getValueFromSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet ) const
329 {
330     bool bRet = false;
331     uno::Reference< chart2::XRegressionCurveContainer > xRegCnt( xSeriesPropertySet, uno::UNO_QUERY );
332     if( xRegCnt.is() )
333         bRet = RegressionCurveHelper::hasMeanValueLine( xRegCnt );
334     return bRet;
335 }
336 
setValueToSeries(const Reference<beans::XPropertySet> & xSeriesPropertySet,const bool & aNewValue) const337 void WrappedMeanValueProperty::setValueToSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet, const bool& aNewValue ) const
338 {
339     uno::Reference< chart2::XRegressionCurveContainer > xRegCnt( xSeriesPropertySet, uno::UNO_QUERY );
340     if( xRegCnt.is() )
341     {
342         if(aNewValue)
343             RegressionCurveHelper::addMeanValueLine( xRegCnt, nullptr );
344         else
345             RegressionCurveHelper::removeMeanValueLine( xRegCnt );
346     }
347 }
348 
349 namespace {
350 
351 //PROP_CHART_STATISTIC_ERROR_CATEGORY
352 // deprecated, replaced by ErrorBarStyle
353 class WrappedErrorCategoryProperty : public WrappedStatisticProperty< css::chart::ChartErrorCategory >
354 {
355 public:
356     virtual css::chart::ChartErrorCategory getValueFromSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet ) const override;
357     virtual void setValueToSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet, const css::chart::ChartErrorCategory& aNewValue ) const override;
358 
359     explicit WrappedErrorCategoryProperty( std::shared_ptr< Chart2ModelContact > spChart2ModelContact,
360                                            tSeriesOrDiagramPropertyType ePropertyType );
361 };
362 
363 }
364 
WrappedErrorCategoryProperty(std::shared_ptr<Chart2ModelContact> spChart2ModelContact,tSeriesOrDiagramPropertyType ePropertyType)365 WrappedErrorCategoryProperty::WrappedErrorCategoryProperty(
366     std::shared_ptr< Chart2ModelContact > spChart2ModelContact,
367     tSeriesOrDiagramPropertyType ePropertyType )
368         : WrappedStatisticProperty< css::chart::ChartErrorCategory >( u"ErrorCategory"_ustr
369             , uno::Any( css::chart::ChartErrorCategory_NONE ), std::move(spChart2ModelContact), ePropertyType  )
370 {
371 }
372 
getValueFromSeries(const Reference<beans::XPropertySet> & xSeriesPropertySet) const373 css::chart::ChartErrorCategory WrappedErrorCategoryProperty::getValueFromSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet ) const
374 {
375     css::chart::ChartErrorCategory aRet = css::chart::ChartErrorCategory_NONE;
376     m_aDefaultValue >>= aRet;
377     uno::Reference< beans::XPropertySet > xErrorBarProperties;
378     if( xSeriesPropertySet.is() && ( xSeriesPropertySet->getPropertyValue( CHART_UNONAME_ERRORBAR_Y ) >>= xErrorBarProperties ) && xErrorBarProperties.is())
379     {
380         sal_Int32 nStyle = css::chart::ErrorBarStyle::NONE;
381         xErrorBarProperties->getPropertyValue( u"ErrorBarStyle"_ustr ) >>= nStyle;
382         switch(nStyle)
383         {
384             case css::chart::ErrorBarStyle::NONE:
385                 aRet = css::chart::ChartErrorCategory_NONE;
386                 break;
387             case css::chart::ErrorBarStyle::VARIANCE:
388                 aRet = css::chart::ChartErrorCategory_VARIANCE;
389                 break;
390             case css::chart::ErrorBarStyle::STANDARD_DEVIATION:
391                 aRet = css::chart::ChartErrorCategory_STANDARD_DEVIATION;
392                 break;
393             case css::chart::ErrorBarStyle::ABSOLUTE:
394                 aRet = css::chart::ChartErrorCategory_CONSTANT_VALUE;
395                 break;
396             case css::chart::ErrorBarStyle::RELATIVE:
397                 aRet = css::chart::ChartErrorCategory_PERCENT;
398                 break;
399             case css::chart::ErrorBarStyle::ERROR_MARGIN:
400                 aRet = css::chart::ChartErrorCategory_ERROR_MARGIN;
401                 break;
402             case css::chart::ErrorBarStyle::STANDARD_ERROR:
403                 break;
404             case css::chart::ErrorBarStyle::FROM_DATA:
405                 break;
406             default:
407                 break;
408         }
409     }
410     return aRet;
411 }
setValueToSeries(const Reference<beans::XPropertySet> & xSeriesPropertySet,const css::chart::ChartErrorCategory & aNewValue) const412 void WrappedErrorCategoryProperty::setValueToSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet, const css::chart::ChartErrorCategory& aNewValue ) const
413 {
414     if( !xSeriesPropertySet.is() )
415         return;
416 
417     uno::Reference< beans::XPropertySet > xErrorBarProperties( getOrCreateErrorBarProperties(xSeriesPropertySet) );
418     if( !xErrorBarProperties.is() )
419         return;
420 
421     sal_Int32 nNewStyle = css::chart::ErrorBarStyle::NONE;
422     switch(aNewValue)
423     {
424         case css::chart::ChartErrorCategory_NONE:
425             nNewStyle = css::chart::ErrorBarStyle::NONE;
426             break;
427         case css::chart::ChartErrorCategory_VARIANCE:
428             nNewStyle = css::chart::ErrorBarStyle::VARIANCE;
429             break;
430         case css::chart::ChartErrorCategory_STANDARD_DEVIATION:
431             nNewStyle = css::chart::ErrorBarStyle::STANDARD_DEVIATION;
432             break;
433         case css::chart::ChartErrorCategory_CONSTANT_VALUE:
434             nNewStyle = css::chart::ErrorBarStyle::ABSOLUTE;
435             break;
436         case css::chart::ChartErrorCategory_PERCENT:
437             nNewStyle = css::chart::ErrorBarStyle::RELATIVE;
438             break;
439         case css::chart::ChartErrorCategory_ERROR_MARGIN:
440             nNewStyle = css::chart::ErrorBarStyle::ERROR_MARGIN;
441             break;
442         default:
443             break;
444     }
445     xErrorBarProperties->setPropertyValue( u"ErrorBarStyle"_ustr , uno::Any(nNewStyle) );
446 }
447 
448 namespace {
449 
450 //PROP_CHART_STATISTIC_PERCENT_ERROR
451 class WrappedPercentageErrorProperty : public WrappedStatisticProperty< double >
452 {
453 public:
454     virtual double getValueFromSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet ) const override;
455     virtual void setValueToSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet, const double& aNewValue ) const override;
456 
457     explicit WrappedPercentageErrorProperty( std::shared_ptr< Chart2ModelContact > spChart2ModelContact,
458                                              tSeriesOrDiagramPropertyType ePropertyType );
459 
460 private:
461     mutable Any m_aOuterValue;
462 };
463 
464 }
465 
WrappedPercentageErrorProperty(std::shared_ptr<Chart2ModelContact> spChart2ModelContact,tSeriesOrDiagramPropertyType ePropertyType)466 WrappedPercentageErrorProperty::WrappedPercentageErrorProperty(
467     std::shared_ptr< Chart2ModelContact > spChart2ModelContact,
468     tSeriesOrDiagramPropertyType ePropertyType )
469         : WrappedStatisticProperty< double >( u"PercentageError"_ustr
470             , uno::Any( 0.0 ), std::move(spChart2ModelContact), ePropertyType  )
471 {
472 }
473 
getValueFromSeries(const Reference<beans::XPropertySet> & xSeriesPropertySet) const474 double WrappedPercentageErrorProperty::getValueFromSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet ) const
475 {
476     double aRet = 0.0;
477     m_aDefaultValue >>= aRet;
478     uno::Reference< beans::XPropertySet > xErrorBarProperties;
479     if( xSeriesPropertySet.is() && ( xSeriesPropertySet->getPropertyValue( CHART_UNONAME_ERRORBAR_Y ) >>= xErrorBarProperties ) && xErrorBarProperties.is())
480     {
481         if( lcl_getErrorBarStyle( xErrorBarProperties ) == css::chart::ErrorBarStyle::RELATIVE )
482             xErrorBarProperties->getPropertyValue( u"PositiveError"_ustr ) >>= aRet;
483         else
484             m_aOuterValue >>= aRet;
485     }
486     return aRet;
487 }
setValueToSeries(const Reference<beans::XPropertySet> & xSeriesPropertySet,const double & aNewValue) const488 void WrappedPercentageErrorProperty::setValueToSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet, const double& aNewValue ) const
489 {
490     uno::Reference< beans::XPropertySet > xErrorBarProperties( getOrCreateErrorBarProperties(xSeriesPropertySet) );
491     if( xErrorBarProperties.is() )
492     {
493         m_aOuterValue <<= aNewValue;
494         if( lcl_getErrorBarStyle( xErrorBarProperties ) == css::chart::ErrorBarStyle::RELATIVE )
495         {
496             xErrorBarProperties->setPropertyValue( u"PositiveError"_ustr , m_aOuterValue );
497             xErrorBarProperties->setPropertyValue( u"NegativeError"_ustr , m_aOuterValue );
498         }
499     }
500 }
501 
502 namespace {
503 
504 //PROP_CHART_STATISTIC_ERROR_MARGIN
505 class WrappedErrorMarginProperty : public WrappedStatisticProperty< double >
506 {
507 public:
508     virtual double getValueFromSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet ) const override;
509     virtual void setValueToSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet, const double& aNewValue ) const override;
510 
511     explicit WrappedErrorMarginProperty( std::shared_ptr< Chart2ModelContact > spChart2ModelContact,
512                                          tSeriesOrDiagramPropertyType ePropertyType );
513 
514 private:
515     mutable Any m_aOuterValue;
516 };
517 
518 }
519 
WrappedErrorMarginProperty(std::shared_ptr<Chart2ModelContact> spChart2ModelContact,tSeriesOrDiagramPropertyType ePropertyType)520 WrappedErrorMarginProperty::WrappedErrorMarginProperty(
521     std::shared_ptr< Chart2ModelContact > spChart2ModelContact,
522     tSeriesOrDiagramPropertyType ePropertyType )
523         : WrappedStatisticProperty< double >( u"ErrorMargin"_ustr
524             , uno::Any( 0.0 ), std::move(spChart2ModelContact), ePropertyType  )
525 {
526 }
527 
getValueFromSeries(const Reference<beans::XPropertySet> & xSeriesPropertySet) const528 double WrappedErrorMarginProperty::getValueFromSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet ) const
529 {
530     double aRet = 0.0;
531     m_aDefaultValue >>= aRet;
532     uno::Reference< beans::XPropertySet > xErrorBarProperties;
533     if( xSeriesPropertySet.is() && ( xSeriesPropertySet->getPropertyValue( CHART_UNONAME_ERRORBAR_Y ) >>= xErrorBarProperties ) && xErrorBarProperties.is())
534     {
535         if( lcl_getErrorBarStyle( xErrorBarProperties ) == css::chart::ErrorBarStyle::ERROR_MARGIN )
536             xErrorBarProperties->getPropertyValue( u"PositiveError"_ustr ) >>= aRet;
537         else
538             m_aOuterValue >>= aRet;
539     }
540     return aRet;
541 }
setValueToSeries(const Reference<beans::XPropertySet> & xSeriesPropertySet,const double & aNewValue) const542 void WrappedErrorMarginProperty::setValueToSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet, const double& aNewValue ) const
543 {
544     uno::Reference< beans::XPropertySet > xErrorBarProperties( getOrCreateErrorBarProperties(xSeriesPropertySet) );
545     if( xErrorBarProperties.is() )
546     {
547         m_aOuterValue <<= aNewValue;
548         if( lcl_getErrorBarStyle( xErrorBarProperties ) == css::chart::ErrorBarStyle::ERROR_MARGIN )
549         {
550             xErrorBarProperties->setPropertyValue( u"PositiveError"_ustr , m_aOuterValue );
551             xErrorBarProperties->setPropertyValue( u"NegativeError"_ustr , m_aOuterValue );
552         }
553     }
554 }
555 
556 namespace {
557 
558 //PROP_CHART_STATISTIC_ERROR_INDICATOR
559 class WrappedErrorIndicatorProperty : public WrappedStatisticProperty< css::chart::ChartErrorIndicatorType >
560 {
561 public:
562     virtual css::chart::ChartErrorIndicatorType getValueFromSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet ) const override;
563     virtual void setValueToSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet, const css::chart::ChartErrorIndicatorType& aNewValue ) const override;
564 
565     explicit WrappedErrorIndicatorProperty( std::shared_ptr< Chart2ModelContact > spChart2ModelContact,
566                                             tSeriesOrDiagramPropertyType ePropertyType );
567 };
568 
569 }
570 
WrappedErrorIndicatorProperty(std::shared_ptr<Chart2ModelContact> spChart2ModelContact,tSeriesOrDiagramPropertyType ePropertyType)571 WrappedErrorIndicatorProperty::WrappedErrorIndicatorProperty(
572     std::shared_ptr< Chart2ModelContact > spChart2ModelContact,
573     tSeriesOrDiagramPropertyType ePropertyType )
574         : WrappedStatisticProperty< css::chart::ChartErrorIndicatorType >( u"ErrorIndicator"_ustr
575             , uno::Any( css::chart::ChartErrorIndicatorType_NONE ), std::move(spChart2ModelContact), ePropertyType  )
576 {
577 }
578 
getValueFromSeries(const Reference<beans::XPropertySet> & xSeriesPropertySet) const579 css::chart::ChartErrorIndicatorType WrappedErrorIndicatorProperty::getValueFromSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet ) const
580 {
581     css::chart::ChartErrorIndicatorType aRet = css::chart::ChartErrorIndicatorType_NONE;
582     m_aDefaultValue >>= aRet;
583     uno::Reference< beans::XPropertySet > xErrorBarProperties;
584     if( xSeriesPropertySet.is() && ( xSeriesPropertySet->getPropertyValue( CHART_UNONAME_ERRORBAR_Y ) >>= xErrorBarProperties ) && xErrorBarProperties.is())
585     {
586         bool bPositive = false;
587         bool bNegative = false;
588         xErrorBarProperties->getPropertyValue( u"ShowPositiveError"_ustr ) >>= bPositive;
589         xErrorBarProperties->getPropertyValue( u"ShowNegativeError"_ustr ) >>= bNegative;
590 
591         if( bPositive && bNegative )
592             aRet = css::chart::ChartErrorIndicatorType_TOP_AND_BOTTOM;
593         else if( bPositive && !bNegative )
594             aRet = css::chart::ChartErrorIndicatorType_UPPER;
595         else if( !bPositive && bNegative )
596             aRet = css::chart::ChartErrorIndicatorType_LOWER;
597     }
598     return aRet;
599 }
setValueToSeries(const Reference<beans::XPropertySet> & xSeriesPropertySet,const css::chart::ChartErrorIndicatorType & aNewValue) const600 void WrappedErrorIndicatorProperty::setValueToSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet, const css::chart::ChartErrorIndicatorType& aNewValue ) const
601 {
602     uno::Reference< beans::XPropertySet > xErrorBarProperties( getOrCreateErrorBarProperties(xSeriesPropertySet) );
603     if( !xErrorBarProperties.is() )
604         return;
605 
606     bool bPositive = false;
607     bool bNegative = false;
608     switch( aNewValue )
609     {
610         case css::chart::ChartErrorIndicatorType_TOP_AND_BOTTOM:
611             bPositive = true;
612             bNegative = true;
613             break;
614         case css::chart::ChartErrorIndicatorType_UPPER:
615             bPositive = true;
616             break;
617         case css::chart::ChartErrorIndicatorType_LOWER:
618             bNegative = true;
619             break;
620         default:
621             break;
622     }
623 
624     xErrorBarProperties->setPropertyValue( u"ShowPositiveError"_ustr , uno::Any(bPositive) );
625     xErrorBarProperties->setPropertyValue( u"ShowNegativeError"_ustr , uno::Any(bNegative) );
626 }
627 
628 namespace {
629 
630 //PROP_CHART_STATISTIC_ERROR_BAR_STYLE
631 // this is the new constant group that replaces the deprecated enum ChartErrorCategory
632 class WrappedErrorBarStyleProperty : public WrappedStatisticProperty< sal_Int32 >
633 {
634 public:
635     virtual sal_Int32 getValueFromSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet ) const override;
636     virtual void setValueToSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet, const sal_Int32& nNewValue ) const override;
637 
638     explicit WrappedErrorBarStyleProperty( std::shared_ptr< Chart2ModelContact > spChart2ModelContact1,
639                                            tSeriesOrDiagramPropertyType ePropertyType );
640 };
641 
642 }
643 
WrappedErrorBarStyleProperty(std::shared_ptr<Chart2ModelContact> spChart2ModelContact,tSeriesOrDiagramPropertyType ePropertyType)644 WrappedErrorBarStyleProperty::WrappedErrorBarStyleProperty(
645     std::shared_ptr< Chart2ModelContact > spChart2ModelContact,
646     tSeriesOrDiagramPropertyType ePropertyType )
647         : WrappedStatisticProperty< sal_Int32 >( u"ErrorBarStyle"_ustr
648             , uno::Any( css::chart::ErrorBarStyle::NONE ), std::move(spChart2ModelContact), ePropertyType  )
649 {
650 }
651 
getValueFromSeries(const Reference<beans::XPropertySet> & xSeriesPropertySet) const652 sal_Int32 WrappedErrorBarStyleProperty::getValueFromSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet ) const
653 {
654     sal_Int32 nRet = css::chart::ErrorBarStyle::NONE;
655     m_aDefaultValue >>= nRet;
656     uno::Reference< beans::XPropertySet > xErrorBarProperties;
657     if( xSeriesPropertySet.is() && ( xSeriesPropertySet->getPropertyValue( CHART_UNONAME_ERRORBAR_Y ) >>= xErrorBarProperties ) && xErrorBarProperties.is())
658     {
659         xErrorBarProperties->getPropertyValue( u"ErrorBarStyle"_ustr ) >>= nRet;
660     }
661     return nRet;
662 }
setValueToSeries(const Reference<beans::XPropertySet> & xSeriesPropertySet,const sal_Int32 & nNewValue) const663 void WrappedErrorBarStyleProperty::setValueToSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet, const sal_Int32& nNewValue ) const
664 {
665     if( !xSeriesPropertySet.is() )
666         return;
667 
668     uno::Reference< beans::XPropertySet > xErrorBarProperties( getOrCreateErrorBarProperties(xSeriesPropertySet) );
669     if( xErrorBarProperties.is() )
670     {
671         xErrorBarProperties->setPropertyValue( u"ErrorBarStyle"_ustr , uno::Any( nNewValue ));
672     }
673 }
674 
675 namespace {
676 
677 //PROP_CHART_STATISTIC_ERROR_RANGE_POSITIVE
678 class WrappedErrorBarRangePositiveProperty : public WrappedStatisticProperty< OUString >
679 {
680 public:
681     virtual OUString getValueFromSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet ) const override;
682     virtual void setValueToSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet, const OUString& aNewValue ) const override;
683 
684     explicit WrappedErrorBarRangePositiveProperty( std::shared_ptr< Chart2ModelContact > spChart2ModelContact,
685                                                    tSeriesOrDiagramPropertyType ePropertyType );
686 };
687 
688 }
689 
WrappedErrorBarRangePositiveProperty(std::shared_ptr<Chart2ModelContact> spChart2ModelContact,tSeriesOrDiagramPropertyType ePropertyType)690 WrappedErrorBarRangePositiveProperty::WrappedErrorBarRangePositiveProperty(
691     std::shared_ptr< Chart2ModelContact > spChart2ModelContact,
692     tSeriesOrDiagramPropertyType ePropertyType )
693         : WrappedStatisticProperty< OUString >( u"ErrorBarRangePositive"_ustr
694             , uno::Any( OUString() ), std::move(spChart2ModelContact), ePropertyType  )
695 {
696 }
697 
getValueFromSeries(const Reference<beans::XPropertySet> & xSeriesPropertySet) const698 OUString WrappedErrorBarRangePositiveProperty::getValueFromSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet ) const
699 {
700     OUString aRet;
701     m_aDefaultValue >>= aRet;
702     uno::Reference< chart2::data::XDataSource > xErrorBarDataSource;
703     if( xSeriesPropertySet.is() &&
704         ( xSeriesPropertySet->getPropertyValue( CHART_UNONAME_ERRORBAR_Y ) >>= xErrorBarDataSource ) &&
705         xErrorBarDataSource.is())
706     {
707         uno::Reference< chart2::data::XDataSequence > xSeq(
708             StatisticsHelper::getErrorDataSequenceFromDataSource(
709                 xErrorBarDataSource, true /* positive */ ));
710         if( xSeq.is())
711             aRet = xSeq->getSourceRangeRepresentation();
712         else
713             m_aOuterValue >>= aRet;
714     }
715     lcl_ConvertRangeToXML( aRet, m_spChart2ModelContact );
716     return aRet;
717 }
718 
setValueToSeries(const Reference<beans::XPropertySet> & xSeriesPropertySet,const OUString & aNewValue) const719 void WrappedErrorBarRangePositiveProperty::setValueToSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet, const OUString& aNewValue ) const
720 {
721     uno::Reference< beans::XPropertySet > xErrorBarProperties( getOrCreateErrorBarProperties(xSeriesPropertySet) );
722     if( !xErrorBarProperties.is() )
723         return;
724 
725     uno::Reference< chart2::data::XDataProvider > xDataProvider(
726         lcl_getDataProviderFromContact( m_spChart2ModelContact ));
727     uno::Reference< chart2::data::XDataSource > xDataSource( xErrorBarProperties, uno::UNO_QUERY );
728     if( xDataSource.is() && xDataProvider.is())
729     {
730         OUString aTmp( aNewValue );
731         OUString aXMLRange( aNewValue );
732         lcl_ConvertRangeFromXML( aTmp, m_spChart2ModelContact );
733         StatisticsHelper::setErrorDataSequence(
734             xDataSource, xDataProvider, aTmp, true /* positive */, true /* y-error */, &aXMLRange );
735         m_aOuterValue <<= aTmp;
736     }
737 }
738 
739 namespace {
740 
741 //PROP_CHART_STATISTIC_ERROR_RANGE_NEGATIVE
742 class WrappedErrorBarRangeNegativeProperty : public WrappedStatisticProperty< OUString >
743 {
744 public:
745     virtual OUString getValueFromSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet ) const override;
746     virtual void setValueToSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet, const OUString& aNewValue ) const override;
747 
748     explicit WrappedErrorBarRangeNegativeProperty( std::shared_ptr< Chart2ModelContact > spChart2ModelContact,
749                                                    tSeriesOrDiagramPropertyType ePropertyType );
750 };
751 
752 }
753 
WrappedErrorBarRangeNegativeProperty(std::shared_ptr<Chart2ModelContact> spChart2ModelContact,tSeriesOrDiagramPropertyType ePropertyType)754 WrappedErrorBarRangeNegativeProperty::WrappedErrorBarRangeNegativeProperty(
755     std::shared_ptr< Chart2ModelContact > spChart2ModelContact,
756     tSeriesOrDiagramPropertyType ePropertyType )
757         : WrappedStatisticProperty< OUString >( u"ErrorBarRangeNegative"_ustr
758             , uno::Any( OUString() ), std::move(spChart2ModelContact), ePropertyType  )
759 {
760 }
761 
getValueFromSeries(const Reference<beans::XPropertySet> & xSeriesPropertySet) const762 OUString WrappedErrorBarRangeNegativeProperty::getValueFromSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet ) const
763 {
764     OUString aRet;
765     m_aDefaultValue >>= aRet;
766     uno::Reference< chart2::data::XDataSource > xErrorBarDataSource;
767     if( xSeriesPropertySet.is() &&
768         ( xSeriesPropertySet->getPropertyValue( CHART_UNONAME_ERRORBAR_Y ) >>= xErrorBarDataSource ) &&
769         xErrorBarDataSource.is())
770     {
771         uno::Reference< chart2::data::XDataSequence > xSeq(
772             StatisticsHelper::getErrorDataSequenceFromDataSource(
773                 xErrorBarDataSource, false /* positive */ ));
774         if( xSeq.is())
775             aRet = xSeq->getSourceRangeRepresentation();
776         else
777             m_aOuterValue >>= aRet;
778     }
779     lcl_ConvertRangeToXML( aRet, m_spChart2ModelContact );
780     return aRet;
781 }
782 
setValueToSeries(const Reference<beans::XPropertySet> & xSeriesPropertySet,const OUString & aNewValue) const783 void WrappedErrorBarRangeNegativeProperty::setValueToSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet, const OUString& aNewValue ) const
784 {
785     uno::Reference< beans::XPropertySet > xErrorBarProperties( getOrCreateErrorBarProperties(xSeriesPropertySet) );
786     if( !xErrorBarProperties.is() )
787         return;
788 
789     uno::Reference< chart2::data::XDataProvider > xDataProvider(
790         lcl_getDataProviderFromContact( m_spChart2ModelContact ));
791     uno::Reference< chart2::data::XDataSource > xDataSource( xErrorBarProperties, uno::UNO_QUERY );
792     if( xDataSource.is() && xDataProvider.is())
793     {
794         OUString aTmp( aNewValue );
795         OUString aXMLRange( aNewValue );
796         lcl_ConvertRangeFromXML( aTmp, m_spChart2ModelContact );
797         StatisticsHelper::setErrorDataSequence(
798             xDataSource, xDataProvider, aTmp, false /* positive */, true /* y-error */, &aXMLRange );
799         m_aOuterValue <<= aTmp;
800     }
801 }
802 
803 namespace {
804 
805 //PROP_CHART_STATISTIC_REGRESSION_CURVES
806 class WrappedRegressionCurvesProperty : public WrappedStatisticProperty< css::chart::ChartRegressionCurveType >
807 {
808 public:
809     virtual css::chart::ChartRegressionCurveType getValueFromSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet ) const override;
810     virtual void setValueToSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet, const css::chart::ChartRegressionCurveType & aNewValue ) const override;
811 
812     explicit WrappedRegressionCurvesProperty( std::shared_ptr< Chart2ModelContact > spChart2ModelContact,
813                                               tSeriesOrDiagramPropertyType ePropertyType );
814 };
815 
816 }
817 
WrappedRegressionCurvesProperty(std::shared_ptr<Chart2ModelContact> spChart2ModelContact,tSeriesOrDiagramPropertyType ePropertyType)818 WrappedRegressionCurvesProperty::WrappedRegressionCurvesProperty(
819     std::shared_ptr< Chart2ModelContact > spChart2ModelContact,
820     tSeriesOrDiagramPropertyType ePropertyType )
821         : WrappedStatisticProperty< css::chart::ChartRegressionCurveType >( u"RegressionCurves"_ustr
822         , lcl_getRegressionDefault(), std::move(spChart2ModelContact), ePropertyType  )
823 {
824 }
825 
getValueFromSeries(const Reference<beans::XPropertySet> & xSeriesPropertySet) const826 css::chart::ChartRegressionCurveType WrappedRegressionCurvesProperty::getValueFromSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet ) const
827 {
828     css::chart::ChartRegressionCurveType aRet;
829     m_aDefaultValue >>= aRet;
830     uno::Reference< chart2::XRegressionCurveContainer > xRegCnt( xSeriesPropertySet, uno::UNO_QUERY );
831     if( xRegCnt.is() )
832     {
833         aRet = lcl_getRegressionCurveType(
834             RegressionCurveHelper::getFirstRegressTypeNotMeanValueLine( xRegCnt ) );
835     }
836     return aRet;
837 }
setValueToSeries(const Reference<beans::XPropertySet> & xSeriesPropertySet,const css::chart::ChartRegressionCurveType & aNewValue) const838 void WrappedRegressionCurvesProperty::setValueToSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet, const css::chart::ChartRegressionCurveType& aNewValue ) const
839 {
840     uno::Reference< chart2::XRegressionCurveContainer > xRegressionCurveContainer( xSeriesPropertySet, uno::UNO_QUERY );
841     if (!xRegressionCurveContainer)
842         return;
843     rtl::Reference< ::chart::RegressionCurveModel> xRegressionCurve = RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegressionCurveContainer );
844     if( xRegressionCurve.is() )
845     {
846         SvxChartRegress eNewRegressionType = lcl_getRegressionType( aNewValue );
847 
848         RegressionCurveHelper::changeRegressionCurveType(
849                         eNewRegressionType,
850                         xRegressionCurveContainer,
851                         xRegressionCurve);
852     }
853 }
854 
855 namespace {
856 
857 //PROP_CHART_STATISTIC_REGRESSION_PROPERTIES
858 //PROP_CHART_STATISTIC_ERROR_PROPERTIES
859 //PROP_CHART_STATISTIC_MEAN_VALUE_PROPERTIES
860 class WrappedStatisticPropertySetProperty : public WrappedStatisticProperty< Reference< beans::XPropertySet > >
861 {
862 public:
863     virtual Reference< beans::XPropertySet > getValueFromSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet ) const override;
864     // properties are read-only, so this method should never be called
865     virtual void setValueToSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet, const Reference< beans::XPropertySet > & xNewValue ) const override;
866 
867     enum PropertySetType
868     {
869         PROPERTY_SET_TYPE_REGRESSION,
870         PROPERTY_SET_TYPE_ERROR_BAR,
871         PROPERTY_SET_TYPE_MEAN_VALUE
872     };
873 
874     explicit WrappedStatisticPropertySetProperty(
875         PropertySetType ePropertySetType, std::shared_ptr< Chart2ModelContact > spChart2ModelContact,
876         tSeriesOrDiagramPropertyType ePropertyType );
877 
878 private:
879     PropertySetType m_eType;
880 };
881 
882 }
883 
WrappedStatisticPropertySetProperty(PropertySetType ePropertySetType,std::shared_ptr<Chart2ModelContact> spChart2ModelContact,tSeriesOrDiagramPropertyType ePropertyType)884 WrappedStatisticPropertySetProperty::WrappedStatisticPropertySetProperty(
885     PropertySetType ePropertySetType
886     , std::shared_ptr< Chart2ModelContact > spChart2ModelContact
887     , tSeriesOrDiagramPropertyType ePropertyType )
888         : WrappedStatisticProperty< Reference< beans::XPropertySet > >(
889             (ePropertySetType == PROPERTY_SET_TYPE_REGRESSION)
890             ? u"DataRegressionProperties"_ustr
891             : (ePropertySetType == PROPERTY_SET_TYPE_ERROR_BAR)
892               ? u"DataErrorProperties"_ustr
893               : u"DataMeanValueProperties"_ustr
894             , uno::Any(), std::move(spChart2ModelContact), ePropertyType  )
895         , m_eType( ePropertySetType )
896 {
897 }
898 
getValueFromSeries(const Reference<beans::XPropertySet> & xSeriesPropertySet) const899 Reference< beans::XPropertySet > WrappedStatisticPropertySetProperty::getValueFromSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet ) const
900 {
901     Reference< beans::XPropertySet > xResult;
902     uno::Reference< chart2::XRegressionCurveContainer > xRegCnt( xSeriesPropertySet, uno::UNO_QUERY );
903 
904     switch( m_eType )
905     {
906         case PROPERTY_SET_TYPE_REGRESSION:
907             if( xRegCnt.is() )
908                 xResult = RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegCnt );
909             break;
910         case PROPERTY_SET_TYPE_ERROR_BAR:
911             if( xSeriesPropertySet.is())
912                 xSeriesPropertySet->getPropertyValue( CHART_UNONAME_ERRORBAR_Y ) >>= xResult;
913             break;
914         case PROPERTY_SET_TYPE_MEAN_VALUE:
915             if( xRegCnt.is() )
916                 xResult = RegressionCurveHelper::getMeanValueLine( xRegCnt );
917             break;
918     }
919 
920     return xResult;
921 }
922 
setValueToSeries(const Reference<beans::XPropertySet> &,const Reference<beans::XPropertySet> &) const923 void WrappedStatisticPropertySetProperty::setValueToSeries(
924     const Reference< beans::XPropertySet >& /* xSeriesPropertySet */
925     , const Reference< beans::XPropertySet >& /* xNewValue */ ) const
926 {
927 }
928 
929 namespace
930 {
931 enum
932 {
933     //statistic properties
934     PROP_CHART_STATISTIC_CONST_ERROR_LOW = FAST_PROPERTY_ID_START_CHART_STATISTIC_PROP,
935     PROP_CHART_STATISTIC_CONST_ERROR_HIGH,
936     PROP_CHART_STATISTIC_MEAN_VALUE,
937     PROP_CHART_STATISTIC_ERROR_CATEGORY,
938     PROP_CHART_STATISTIC_ERROR_BAR_STYLE,
939     PROP_CHART_STATISTIC_PERCENT_ERROR,
940     PROP_CHART_STATISTIC_ERROR_MARGIN,
941     PROP_CHART_STATISTIC_ERROR_INDICATOR,
942     PROP_CHART_STATISTIC_ERROR_RANGE_POSITIVE,
943     PROP_CHART_STATISTIC_ERROR_RANGE_NEGATIVE,
944     PROP_CHART_STATISTIC_REGRESSION_CURVES,
945     PROP_CHART_STATISTIC_REGRESSION_PROPERTIES,
946     PROP_CHART_STATISTIC_ERROR_PROPERTIES,
947     PROP_CHART_STATISTIC_MEAN_VALUE_PROPERTIES
948 };
949 
950 /** @parameter bDataSeriesProperty if true, this property is for a single data
951                series, if false, it is for the whole diagram, i.e. for all
952                series
953  */
lcl_addWrappedProperties(std::vector<std::unique_ptr<WrappedProperty>> & rList,const std::shared_ptr<Chart2ModelContact> & spChart2ModelContact,tSeriesOrDiagramPropertyType ePropertyType)954 void lcl_addWrappedProperties( std::vector< std::unique_ptr<WrappedProperty> >& rList
955             , const std::shared_ptr< Chart2ModelContact >& spChart2ModelContact
956             , tSeriesOrDiagramPropertyType ePropertyType )
957 {
958     rList.emplace_back( new WrappedConstantErrorLowProperty( spChart2ModelContact, ePropertyType ) );
959     rList.emplace_back( new WrappedConstantErrorHighProperty( spChart2ModelContact, ePropertyType ) );
960     rList.emplace_back( new WrappedMeanValueProperty( spChart2ModelContact, ePropertyType ) );
961     rList.emplace_back( new WrappedErrorCategoryProperty( spChart2ModelContact, ePropertyType ) );
962     rList.emplace_back( new WrappedErrorBarStyleProperty( spChart2ModelContact, ePropertyType ) );
963     rList.emplace_back( new WrappedPercentageErrorProperty( spChart2ModelContact, ePropertyType ) );
964     rList.emplace_back( new WrappedErrorMarginProperty( spChart2ModelContact, ePropertyType ) );
965     rList.emplace_back( new WrappedErrorIndicatorProperty( spChart2ModelContact, ePropertyType ) );
966     rList.emplace_back( new WrappedErrorBarRangePositiveProperty( spChart2ModelContact, ePropertyType ) );
967     rList.emplace_back( new WrappedErrorBarRangeNegativeProperty( spChart2ModelContact, ePropertyType ) );
968     rList.emplace_back( new WrappedRegressionCurvesProperty( spChart2ModelContact, ePropertyType ) );
969     rList.emplace_back( new WrappedStatisticPropertySetProperty(
970                          WrappedStatisticPropertySetProperty::PROPERTY_SET_TYPE_REGRESSION, spChart2ModelContact, ePropertyType ) );
971     rList.emplace_back( new WrappedStatisticPropertySetProperty(
972                          WrappedStatisticPropertySetProperty::PROPERTY_SET_TYPE_ERROR_BAR,  spChart2ModelContact, ePropertyType ) );
973     rList.emplace_back( new WrappedStatisticPropertySetProperty(
974                          WrappedStatisticPropertySetProperty::PROPERTY_SET_TYPE_MEAN_VALUE, spChart2ModelContact, ePropertyType ) );
975 }
976 
977 }//anonymous namespace
978 
addProperties(std::vector<Property> & rOutProperties)979 void WrappedStatisticProperties::addProperties( std::vector< Property > & rOutProperties )
980 {
981     rOutProperties.emplace_back( "ConstantErrorLow",
982                   PROP_CHART_STATISTIC_CONST_ERROR_LOW,
983                   cppu::UnoType<double>::get(),
984                   beans::PropertyAttribute::BOUND
985                   | beans::PropertyAttribute::MAYBEDEFAULT );
986     rOutProperties.emplace_back( "ConstantErrorHigh",
987                   PROP_CHART_STATISTIC_CONST_ERROR_HIGH,
988                   cppu::UnoType<double>::get(),
989                   beans::PropertyAttribute::BOUND
990                   | beans::PropertyAttribute::MAYBEDEFAULT );
991     rOutProperties.emplace_back( "MeanValue",
992                   PROP_CHART_STATISTIC_MEAN_VALUE,
993                   cppu::UnoType<bool>::get(),
994                   beans::PropertyAttribute::BOUND
995                   | beans::PropertyAttribute::MAYBEDEFAULT );
996     rOutProperties.emplace_back( "ErrorCategory",
997                   PROP_CHART_STATISTIC_ERROR_CATEGORY,
998                   cppu::UnoType<css::chart::ChartErrorCategory>::get(),
999                   beans::PropertyAttribute::BOUND
1000                   | beans::PropertyAttribute::MAYBEDEFAULT );
1001     rOutProperties.emplace_back( "ErrorBarStyle",
1002                   PROP_CHART_STATISTIC_ERROR_BAR_STYLE,
1003                   cppu::UnoType<sal_Int32>::get(),
1004                   beans::PropertyAttribute::BOUND
1005                   | beans::PropertyAttribute::MAYBEDEFAULT );
1006     rOutProperties.emplace_back( "PercentageError",
1007                   PROP_CHART_STATISTIC_PERCENT_ERROR,
1008                   cppu::UnoType<double>::get(),
1009                   beans::PropertyAttribute::BOUND
1010                   | beans::PropertyAttribute::MAYBEDEFAULT );
1011     rOutProperties.emplace_back( "ErrorMargin",
1012                   PROP_CHART_STATISTIC_ERROR_MARGIN,
1013                   cppu::UnoType<double>::get(),
1014                   beans::PropertyAttribute::BOUND
1015                   | beans::PropertyAttribute::MAYBEDEFAULT );
1016     rOutProperties.emplace_back( "ErrorIndicator",
1017                   PROP_CHART_STATISTIC_ERROR_INDICATOR,
1018                   cppu::UnoType<css::chart::ChartErrorIndicatorType>::get(),
1019                   beans::PropertyAttribute::BOUND
1020                   | beans::PropertyAttribute::MAYBEDEFAULT );
1021     rOutProperties.emplace_back( "ErrorBarRangePositive",
1022                   PROP_CHART_STATISTIC_ERROR_RANGE_POSITIVE,
1023                   cppu::UnoType<OUString>::get(),
1024                   beans::PropertyAttribute::BOUND
1025                   | beans::PropertyAttribute::MAYBEDEFAULT );
1026     rOutProperties.emplace_back( "ErrorBarRangeNegative",
1027                   PROP_CHART_STATISTIC_ERROR_RANGE_NEGATIVE,
1028                   cppu::UnoType<OUString>::get(),
1029                   beans::PropertyAttribute::BOUND
1030                   | beans::PropertyAttribute::MAYBEDEFAULT );
1031     rOutProperties.emplace_back( "RegressionCurves",
1032                   PROP_CHART_STATISTIC_REGRESSION_CURVES,
1033                   cppu::UnoType<css::chart::ChartRegressionCurveType>::get(),
1034                   beans::PropertyAttribute::BOUND
1035                   | beans::PropertyAttribute::MAYBEDEFAULT );
1036 
1037     rOutProperties.emplace_back( "DataRegressionProperties",
1038                   PROP_CHART_STATISTIC_REGRESSION_PROPERTIES,
1039                   cppu::UnoType<beans::XPropertySet>::get(),
1040                   beans::PropertyAttribute::BOUND
1041                   | beans::PropertyAttribute::READONLY
1042                   | beans::PropertyAttribute::MAYBEVOID );
1043     rOutProperties.emplace_back( "DataErrorProperties",
1044                   PROP_CHART_STATISTIC_ERROR_PROPERTIES,
1045                   cppu::UnoType<beans::XPropertySet>::get(),
1046                   beans::PropertyAttribute::BOUND
1047                   | beans::PropertyAttribute::READONLY
1048                   | beans::PropertyAttribute::MAYBEVOID );
1049     rOutProperties.emplace_back( "DataMeanValueProperties",
1050                   PROP_CHART_STATISTIC_MEAN_VALUE_PROPERTIES,
1051                   cppu::UnoType<beans::XPropertySet>::get(),
1052                   beans::PropertyAttribute::BOUND
1053                   | beans::PropertyAttribute::READONLY
1054                   | beans::PropertyAttribute::MAYBEVOID );
1055 }
1056 
addWrappedPropertiesForSeries(std::vector<std::unique_ptr<WrappedProperty>> & rList,const std::shared_ptr<Chart2ModelContact> & spChart2ModelContact)1057 void WrappedStatisticProperties::addWrappedPropertiesForSeries( std::vector< std::unique_ptr<WrappedProperty> >& rList
1058                                     , const std::shared_ptr< Chart2ModelContact >& spChart2ModelContact )
1059 {
1060     lcl_addWrappedProperties( rList, spChart2ModelContact, DATA_SERIES );
1061 }
1062 
addWrappedPropertiesForDiagram(std::vector<std::unique_ptr<WrappedProperty>> & rList,const std::shared_ptr<Chart2ModelContact> & spChart2ModelContact)1063 void WrappedStatisticProperties::addWrappedPropertiesForDiagram( std::vector< std::unique_ptr<WrappedProperty> >& rList
1064                                     , const std::shared_ptr< Chart2ModelContact >& spChart2ModelContact )
1065 {
1066     lcl_addWrappedProperties( rList, spChart2ModelContact, DIAGRAM  );
1067 }
1068 
1069 } //namespace chart
1070 
1071 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
1072