Debian Codegraph @

chart2/source/controller/itemsetwrapper/StatisticsItemConverter.cxx

raw
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 <StatisticsItemConverter.hxx>
21 #include "SchWhichPairs.hxx"
22 #include <RegressionCurveHelper.hxx>
23 #include <RegressionCurveModel.hxx>
24 #include <ErrorBar.hxx>
25 #include <StatisticsHelper.hxx>
26 #include <ChartModel.hxx>
27 #include <unonames.hxx>
28
29 #include <svl/stritem.hxx>
30 #include <svx/chrtitem.hxx>
31 #include <svl/intitem.hxx>
32 #include <rtl/math.hxx>
33
34 #include <com/sun/star/chart2/XInternalDataProvider.hpp>
35 #include <com/sun/star/chart2/XRegressionCurveContainer.hpp>
36 #include <com/sun/star/chart/ErrorBarStyle.hpp>
37 #include <utility>
38 #include <comphelper/diagnose_ex.hxx>
39
40 using namespace ::com::sun::star;
41
42 namespace
43 {
44
45 uno::Reference< beans::XPropertySet > lcl_GetErrorBar(
46 const uno::Reference< beans::XPropertySet > & xProp, bool bYError )
47 {
48 uno::Reference< beans::XPropertySet > xResult;
49
50 if( xProp.is())
51 try
52 {
53 ( xProp->getPropertyValue( bYError ? CHART_UNONAME_ERRORBAR_Y : CHART_UNONAME_ERRORBAR_X ) >>= xResult );
54 }
55 catch( const uno::Exception & )
56 {
57 DBG_UNHANDLED_EXCEPTION("chart2");
58 }
59
60 return xResult;
61 }
62
63 uno::Reference< beans::XPropertySet > lcl_GetDefaultErrorBar()
64 {
65 return uno::Reference< beans::XPropertySet >( new ::chart::ErrorBar );
66 }
67
68 void lcl_getErrorValues( const uno::Reference< beans::XPropertySet > & xErrorBarProp,
69 double & rOutPosError, double & rOutNegError )
70 {
71 if( ! xErrorBarProp.is())
72 return;
73
74 try
75 {
76 xErrorBarProp->getPropertyValue( u"PositiveError"_ustr ) >>= rOutPosError;
77 xErrorBarProp->getPropertyValue( u"NegativeError"_ustr ) >>= rOutNegError;
78 }
79 catch( const uno::Exception & )
80 {
81 DBG_UNHANDLED_EXCEPTION("chart2");
82 }
83 }
84
85 void lcl_getErrorIndicatorValues(
86 const uno::Reference< beans::XPropertySet > & xErrorBarProp,
87 bool & rOutShowPosError, bool & rOutShowNegError )
88 {
89 if( ! xErrorBarProp.is())
90 return;
91
92 try
93 {
94 xErrorBarProp->getPropertyValue( u"ShowPositiveError"_ustr ) >>= rOutShowPosError;
95 xErrorBarProp->getPropertyValue( u"ShowNegativeError"_ustr ) >>= rOutShowNegError;
96 }
97 catch( const uno::Exception & )
98 {
99 DBG_UNHANDLED_EXCEPTION("chart2");
100 }
101 }
102
103 uno::Reference< beans::XPropertySet > lcl_getEquationProperties(
104 const uno::Reference< beans::XPropertySet > & xSeriesPropSet, const SfxItemSet * pItemSet )
105 {
106 bool bEquationExists = true;
107
108 // ensure that a trendline is on
109 if( pItemSet )
110 {
111 if( const SvxChartRegressItem* pRegressionItem = pItemSet->GetItemIfSet( SCHATTR_REGRESSION_TYPE ) )
112 {
113 SvxChartRegress eRegress = pRegressionItem->GetValue();
114 bEquationExists = ( eRegress != SvxChartRegress::NONE );
115 }
116 }
117
118 if( bEquationExists )
119 {
120 uno::Reference< chart2::XRegressionCurveContainer > xRegCnt( xSeriesPropSet, uno::UNO_QUERY );
121 rtl::Reference< ::chart::RegressionCurveModel > xCurve =
122 ::chart::RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegCnt );
123 if( xCurve.is())
124 {
125 return xCurve->getEquationProperties();
126 }
127 }
128
129 return uno::Reference< beans::XPropertySet >();
130 }
131
132 uno::Reference< beans::XPropertySet > lcl_getCurveProperties(
133 const uno::Reference< beans::XPropertySet > & xSeriesPropSet, const SfxItemSet * pItemSet )
134 {
135 bool bExists = true;
136
137 // ensure that a trendline is on
138 if( pItemSet )
139 {
140 if( const SvxChartRegressItem* pRegressionItem = pItemSet->GetItemIfSet( SCHATTR_REGRESSION_TYPE ) )
141 {
142 SvxChartRegress eRegress = pRegressionItem->GetValue();
143 bExists = ( eRegress != SvxChartRegress::NONE );
144 }
145 }
146
147 if( bExists )
148 {
149 uno::Reference< chart2::XRegressionCurveContainer > xRegCnt( xSeriesPropSet, uno::UNO_QUERY );
150 rtl::Reference< ::chart::RegressionCurveModel > xCurve(
151 ::chart::RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegCnt ));
152 if( xCurve.is())
153 return xCurve;
154 }
155
156 return uno::Reference< beans::XPropertySet >();
157 }
158
159 template <class T, class D>
160 bool lclConvertToPropertySet(const SfxItemSet& rItemSet, sal_uInt16 nWhichId, const uno::Reference<beans::XPropertySet>& xProperties, const OUString& aPropertyID)
161 {
162 OSL_ASSERT(xProperties.is());
163 if( xProperties.is() )
164 {
165 T aValue = static_cast<T>(static_cast<const D&>(rItemSet.Get( nWhichId )).GetValue());
166 T aOldValue = aValue;
167 bool aSuccess = xProperties->getPropertyValue( aPropertyID ) >>= aOldValue;
168 if (!aSuccess || aOldValue != aValue)
169 {
170 xProperties->setPropertyValue( aPropertyID , uno::Any( aValue ));
171 return true;
172 }
173 }
174 return false;
175 }
176
177 template <class T, class D>
178 void lclConvertToItemSet(SfxItemSet& rItemSet, sal_uInt16 nWhichId, const uno::Reference<beans::XPropertySet>& xProperties, const OUString& aPropertyID)
179 {
180 OSL_ASSERT(xProperties.is());
181 if( xProperties.is() )
182 {
183 T aValue = static_cast<T>(static_cast<const D&>(rItemSet.Get( nWhichId )).GetValue());
184 if(xProperties->getPropertyValue( aPropertyID ) >>= aValue)
185 {
186 rItemSet.Put(D( nWhichId, aValue ));
187 }
188 }
189 }
190
191 void lclConvertToItemSetDouble(SfxItemSet& rItemSet, TypedWhichId<SvxDoubleItem> nWhichId, const uno::Reference<beans::XPropertySet>& xProperties, const OUString& aPropertyID)
192 {
193 OSL_ASSERT(xProperties.is());
194 if( xProperties.is() )
195 {
196 double aValue = rItemSet.Get( nWhichId ).GetValue();
197 if(xProperties->getPropertyValue( aPropertyID ) >>= aValue)
198 {
199 rItemSet.Put(SvxDoubleItem( aValue, nWhichId ));
200 }
201 }
202 }
203
204 } // anonymous namespace
205
206 namespace chart::wrapper
207 {
208
209 StatisticsItemConverter::StatisticsItemConverter(
210 rtl::Reference<::chart::ChartModel> xModel,
211 const uno::Reference< beans::XPropertySet > & rPropertySet,
212 SfxItemPool& rItemPool ) :
213 ItemConverter( rPropertySet, rItemPool ),
214 m_xModel(std::move( xModel ))
215 {
216 }
217
218 StatisticsItemConverter::~StatisticsItemConverter()
219 {
220 }
221
222 const WhichRangesContainer& StatisticsItemConverter::GetWhichPairs() const
223 {
224 // must span all used items!
225 return nStatWhichPairs;
226 }
227
228 bool StatisticsItemConverter::GetItemProperty(
229 tWhichIdType /* nWhichId */,
230 tPropertyNameWithMemberId & /* rOutProperty */ ) const
231 {
232 return false;
233 }
234
235 bool StatisticsItemConverter::ApplySpecialItem(
236 sal_uInt16 nWhichId, const SfxItemSet & rItemSet )
237 {
238 bool bChanged = false;
239
240 switch( nWhichId )
241 {
242 case SCHATTR_STAT_AVERAGE:
243 {
244 uno::Reference< chart2::XRegressionCurveContainer > xRegCnt(
245 GetPropertySet(), uno::UNO_QUERY );
246 bool bOldHasMeanValueLine = RegressionCurveHelper::hasMeanValueLine( xRegCnt );
247
248 bool bNewHasMeanValueLine =
249 static_cast< const SfxBoolItem & >( rItemSet.Get( nWhichId )).GetValue();
250
251 if( bOldHasMeanValueLine != bNewHasMeanValueLine )
252 {
253 if( ! bNewHasMeanValueLine )
254 RegressionCurveHelper::removeMeanValueLine( xRegCnt );
255 else
256 RegressionCurveHelper::addMeanValueLine( xRegCnt, GetPropertySet() );
257 bChanged = true;
258 }
259 }
260 break;
261
262 // Attention !!! This case must be passed before SCHATTR_STAT_PERCENT,
263 // SCHATTR_STAT_BIGERROR, SCHATTR_STAT_CONSTPLUS,
264 // SCHATTR_STAT_CONSTMINUS and SCHATTR_STAT_INDICATE
265 case SCHATTR_STAT_KIND_ERROR:
266 {
267 bool bYError =
268 rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
269
270 uno::Reference< beans::XPropertySet > xErrorBarProp(
271 lcl_GetErrorBar( GetPropertySet(), bYError ));
272
273 SvxChartKindError eErrorKind =
274 static_cast< const SvxChartKindErrorItem & >(
275 rItemSet.Get( nWhichId )).GetValue();
276
277 if( !xErrorBarProp.is() && eErrorKind == SvxChartKindError::NONE)
278 {
279 //nothing to do
280 }
281 else
282 {
283 sal_Int32 nStyle = css::chart::ErrorBarStyle::NONE;
284
285 switch( eErrorKind )
286 {
287 case SvxChartKindError::NONE:
288 nStyle = css::chart::ErrorBarStyle::NONE; break;
289 case SvxChartKindError::Variant:
290 nStyle = css::chart::ErrorBarStyle::VARIANCE; break;
291 case SvxChartKindError::Sigma:
292 nStyle = css::chart::ErrorBarStyle::STANDARD_DEVIATION; break;
293 case SvxChartKindError::Percent:
294 nStyle = css::chart::ErrorBarStyle::RELATIVE; break;
295 case SvxChartKindError::BigError:
296 nStyle = css::chart::ErrorBarStyle::ERROR_MARGIN; break;
297 case SvxChartKindError::Const:
298 nStyle = css::chart::ErrorBarStyle::ABSOLUTE; break;
299 case SvxChartKindError::StdError:
300 nStyle = css::chart::ErrorBarStyle::STANDARD_ERROR; break;
301 case SvxChartKindError::Range:
302 nStyle = css::chart::ErrorBarStyle::FROM_DATA; break;
303 }
304
305 if( !xErrorBarProp.is() )
306 {
307 xErrorBarProp = lcl_GetDefaultErrorBar();
308 GetPropertySet()->setPropertyValue( bYError ? CHART_UNONAME_ERRORBAR_Y : CHART_UNONAME_ERRORBAR_X,
309 uno::Any( xErrorBarProp ));
310 }
311
312 xErrorBarProp->setPropertyValue( u"ErrorBarStyle"_ustr , uno::Any( nStyle ));
313 bChanged = true;
314 }
315 }
316 break;
317
318 case SCHATTR_STAT_PERCENT:
319 case SCHATTR_STAT_BIGERROR:
320 {
321 OSL_FAIL( "Deprecated item" );
322 bool bYError =
323 rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
324
325 uno::Reference< beans::XPropertySet > xErrorBarProp(
326 lcl_GetErrorBar( GetPropertySet(), bYError));
327 bool bOldHasErrorBar = xErrorBarProp.is();
328
329 double fValue =
330 static_cast< const SvxDoubleItem & >(
331 rItemSet.Get( nWhichId )).GetValue();
332 double fPos(0.0), fNeg(0.0);
333 lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
334
335 if( bOldHasErrorBar &&
336 ! ( ::rtl::math::approxEqual( fPos, fValue ) &&
337 ::rtl::math::approxEqual( fNeg, fValue )))
338 {
339 xErrorBarProp->setPropertyValue( u"PositiveError"_ustr , uno::Any( fValue ));
340 xErrorBarProp->setPropertyValue( u"NegativeError"_ustr , uno::Any( fValue ));
341 bChanged = true;
342 }
343 }
344 break;
345
346 case SCHATTR_STAT_CONSTPLUS:
347 {
348 bool bYError =
349 rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
350
351 uno::Reference< beans::XPropertySet > xErrorBarProp(
352 lcl_GetErrorBar( GetPropertySet(),bYError));
353 bool bOldHasErrorBar = xErrorBarProp.is();
354
355 double fValue =
356 static_cast< const SvxDoubleItem & >(
357 rItemSet.Get( nWhichId )).GetValue();
358 double fPos(0.0), fNeg(0.0);
359 lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
360
361 if( bOldHasErrorBar &&
362 ! ::rtl::math::approxEqual( fPos, fValue ))
363 {
364 xErrorBarProp->setPropertyValue( u"PositiveError"_ustr , uno::Any( fValue ));
365 bChanged = true;
366 }
367 }
368 break;
369
370 case SCHATTR_STAT_CONSTMINUS:
371 {
372 bool bYError =
373 rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
374 uno::Reference< beans::XPropertySet > xErrorBarProp(
375 lcl_GetErrorBar( GetPropertySet(),bYError));
376 bool bOldHasErrorBar = xErrorBarProp.is();
377
378 double fValue =
379 static_cast< const SvxDoubleItem & >(
380 rItemSet.Get( nWhichId )).GetValue();
381 double fPos(0.0), fNeg(0.0);
382 lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
383
384 if( bOldHasErrorBar &&
385 ! ::rtl::math::approxEqual( fNeg, fValue ))
386 {
387 xErrorBarProp->setPropertyValue( u"NegativeError"_ustr , uno::Any( fValue ));
388 bChanged = true;
389 }
390 }
391 break;
392
393 case SCHATTR_REGRESSION_TYPE:
394 {
395 SvxChartRegress eRegress =
396 static_cast< const SvxChartRegressItem& >(
397 rItemSet.Get( nWhichId )).GetValue();
398
399 uno::Reference< chart2::XRegressionCurve > xCurve( GetPropertySet(), uno::UNO_QUERY );
400 uno::Reference< chart2::XRegressionCurveContainer > xContainer( GetPropertySet(), uno::UNO_QUERY );
401
402 if( eRegress == SvxChartRegress::NONE )
403 {
404 if ( xContainer.is() )
405 {
406 xContainer->removeRegressionCurve( xCurve );
407 bChanged = true;
408 }
409 }
410 else
411 {
412 if ( xCurve.is() )
413 {
414 SvxChartRegress eOldRegress(
415 RegressionCurveHelper::getRegressionType(xCurve));
416
417 if( eOldRegress != eRegress )
418 {
419 xCurve = RegressionCurveHelper::changeRegressionCurveType(
420 eRegress,
421 xContainer,
422 xCurve);
423 uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
424 resetPropertySet( xProperties );
425 bChanged = true;
426 }
427 }
428 }
429 }
430 break;
431
432 case SCHATTR_REGRESSION_DEGREE:
433 {
434 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
435 bChanged = lclConvertToPropertySet<sal_Int32, SfxInt32Item>(rItemSet, nWhichId, xProperties, u"PolynomialDegree"_ustr);
436 }
437 break;
438
439 case SCHATTR_REGRESSION_PERIOD:
440 {
441 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
442 bChanged = lclConvertToPropertySet<sal_Int32, SfxInt32Item>(rItemSet, nWhichId, xProperties, u"MovingAveragePeriod"_ustr);
443 }
444 break;
445
446 case SCHATTR_REGRESSION_MOVING_TYPE:
447 {
448 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
449 bChanged = lclConvertToPropertySet<sal_Int32, SfxInt32Item>(rItemSet, nWhichId, xProperties, u"MovingAverageType"_ustr);
450 }
451 break;
452
453 case SCHATTR_REGRESSION_EXTRAPOLATE_FORWARD:
454 {
455 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
456 bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties, u"ExtrapolateForward"_ustr);
457 }
458 break;
459
460 case SCHATTR_REGRESSION_EXTRAPOLATE_BACKWARD:
461 {
462 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
463 bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties, u"ExtrapolateBackward"_ustr);
464 }
465 break;
466
467 case SCHATTR_REGRESSION_SET_INTERCEPT:
468 {
469 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
470 bChanged = lclConvertToPropertySet<bool, SfxBoolItem>(rItemSet, nWhichId, xProperties, u"ForceIntercept"_ustr);
471 }
472 break;
473
474 case SCHATTR_REGRESSION_INTERCEPT_VALUE:
475 {
476 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
477 bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties, u"InterceptValue"_ustr);
478 }
479 break;
480
481 case SCHATTR_REGRESSION_CURVE_NAME:
482 {
483 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
484 bChanged = lclConvertToPropertySet<OUString, SfxStringItem>(rItemSet, nWhichId, xProperties, u"CurveName"_ustr);
485 }
486 break;
487
488 case SCHATTR_REGRESSION_SHOW_EQUATION:
489 {
490 uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), &rItemSet ));
491 bChanged = lclConvertToPropertySet<bool, SfxBoolItem>(rItemSet, nWhichId, xEqProp, u"ShowEquation"_ustr);
492 }
493 break;
494
495 case SCHATTR_REGRESSION_XNAME:
496 {
497 uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), &rItemSet ));
498 bChanged = lclConvertToPropertySet<OUString, SfxStringItem>(rItemSet, nWhichId, xEqProp, u"XName"_ustr);
499 }
500 break;
501
502 case SCHATTR_REGRESSION_YNAME:
503 {
504 uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), &rItemSet ));
505 bChanged = lclConvertToPropertySet<OUString, SfxStringItem>(rItemSet, nWhichId, xEqProp, u"YName"_ustr);
506 }
507 break;
508
509 case SCHATTR_REGRESSION_SHOW_COEFF:
510 {
511 uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), &rItemSet ));
512 bChanged = lclConvertToPropertySet<bool, SfxBoolItem>(rItemSet, nWhichId, xEqProp, u"ShowCorrelationCoefficient"_ustr);
513 }
514 break;
515
516 case SCHATTR_STAT_INDICATE:
517 {
518 bool bYError =
519 rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
520 uno::Reference< beans::XPropertySet > xErrorBarProp(
521 lcl_GetErrorBar( GetPropertySet(),bYError));
522 bool bOldHasErrorBar = xErrorBarProp.is();
523
524 SvxChartIndicate eIndicate =
525 static_cast< const SvxChartIndicateItem & >(
526 rItemSet.Get( nWhichId )).GetValue();
527
528 bool bNewIndPos = (eIndicate == SvxChartIndicate::Both || eIndicate == SvxChartIndicate::Up );
529 bool bNewIndNeg = (eIndicate == SvxChartIndicate::Both || eIndicate == SvxChartIndicate::Down );
530
531 bool bShowPos(false), bShowNeg(false);
532 lcl_getErrorIndicatorValues( xErrorBarProp, bShowPos, bShowNeg );
533
534 if( bOldHasErrorBar &&
535 ( bShowPos != bNewIndPos ||
536 bShowNeg != bNewIndNeg ))
537 {
538 xErrorBarProp->setPropertyValue( u"ShowPositiveError"_ustr , uno::Any( bNewIndPos ));
539 xErrorBarProp->setPropertyValue( u"ShowNegativeError"_ustr , uno::Any( bNewIndNeg ));
540 bChanged = true;
541 }
542 }
543 break;
544
545 case SCHATTR_STAT_RANGE_POS:
546 case SCHATTR_STAT_RANGE_NEG:
547 {
548 const bool bYError =
549 rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
550 uno::Reference< chart2::data::XDataSource > xErrorBarSource( lcl_GetErrorBar( GetPropertySet(), bYError),
551 uno::UNO_QUERY );
552 uno::Reference< chart2::data::XDataProvider > xDataProvider;
553
554 if( m_xModel.is())
555 xDataProvider.set( m_xModel->getDataProvider());
556 if( xErrorBarSource.is() && xDataProvider.is())
557 {
558 OUString aNewRange( static_cast< const SfxStringItem & >( rItemSet.Get( nWhichId )).GetValue());
559 bool bApplyNewRange = false;
560
561 bool bIsPositiveValue( nWhichId == SCHATTR_STAT_RANGE_POS );
562 if( m_xModel->hasInternalDataProvider())
563 {
564 if( !aNewRange.isEmpty())
565 {
566 uno::Reference< chart2::data::XDataSequence > xSeq(
567 StatisticsHelper::getErrorDataSequenceFromDataSource(
568 xErrorBarSource, bIsPositiveValue, bYError ));
569 if( ! xSeq.is())
570 {
571 // no data range for error bars yet => create
572 uno::Reference< chart2::XInternalDataProvider > xIntDataProvider( xDataProvider, uno::UNO_QUERY );
573 OSL_ASSERT( xIntDataProvider.is());
574 if( xIntDataProvider.is())
575 {
576 xIntDataProvider->appendSequence();
577 aNewRange = "last";
578 bApplyNewRange = true;
579 }
580 }
581 }
582 }
583 else
584 {
585 uno::Reference< chart2::data::XDataSequence > xSeq(
586 StatisticsHelper::getErrorDataSequenceFromDataSource(
587 xErrorBarSource, bIsPositiveValue, bYError ));
588 bApplyNewRange =
589 ! ( xSeq.is() && (aNewRange == xSeq->getSourceRangeRepresentation()));
590 }
591
592 if( bApplyNewRange )
593 StatisticsHelper::setErrorDataSequence(
594 xErrorBarSource, xDataProvider, aNewRange, bIsPositiveValue, bYError );
595 }
596 }
597 break;
598 }
599
600 return bChanged;
601 }
602
603 void StatisticsItemConverter::FillSpecialItem(
604 sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const
605 {
606 switch( nWhichId )
607 {
608 case SCHATTR_STAT_AVERAGE:
609 rOutItemSet.Put(
610 SfxBoolItem( nWhichId,
611 RegressionCurveHelper::hasMeanValueLine(
612 uno::Reference< chart2::XRegressionCurveContainer >(
613 GetPropertySet(), uno::UNO_QUERY ))));
614 break;
615
616 case SCHATTR_STAT_KIND_ERROR:
617 {
618 bool bYError =
619 rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
620 SvxChartKindError eErrorKind = SvxChartKindError::NONE;
621 uno::Reference< beans::XPropertySet > xErrorBarProp(
622 lcl_GetErrorBar( GetPropertySet(), bYError));
623 if( xErrorBarProp.is() )
624 {
625 sal_Int32 nStyle = 0;
626 if( xErrorBarProp->getPropertyValue( u"ErrorBarStyle"_ustr ) >>= nStyle )
627 {
628 switch( nStyle )
629 {
630 case css::chart::ErrorBarStyle::NONE:
631 break;
632 case css::chart::ErrorBarStyle::VARIANCE:
633 eErrorKind = SvxChartKindError::Variant; break;
634 case css::chart::ErrorBarStyle::STANDARD_DEVIATION:
635 eErrorKind = SvxChartKindError::Sigma; break;
636 case css::chart::ErrorBarStyle::ABSOLUTE:
637 eErrorKind = SvxChartKindError::Const; break;
638 case css::chart::ErrorBarStyle::RELATIVE:
639 eErrorKind = SvxChartKindError::Percent; break;
640 case css::chart::ErrorBarStyle::ERROR_MARGIN:
641 eErrorKind = SvxChartKindError::BigError; break;
642 case css::chart::ErrorBarStyle::STANDARD_ERROR:
643 eErrorKind = SvxChartKindError::StdError; break;
644 case css::chart::ErrorBarStyle::FROM_DATA:
645 eErrorKind = SvxChartKindError::Range; break;
646 }
647 }
648 }
649 rOutItemSet.Put( SvxChartKindErrorItem( eErrorKind, SCHATTR_STAT_KIND_ERROR ));
650 }
651 break;
652
653 case SCHATTR_STAT_PERCENT:
654 {
655 bool bYError =
656 rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
657 uno::Reference< beans::XPropertySet > xErrorBarProp( lcl_GetErrorBar( GetPropertySet(),bYError));
658 if( xErrorBarProp.is())
659 {
660 double fPos(0.0), fNeg(0.0);
661 lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
662 rOutItemSet.Put( SvxDoubleItem( ( fPos + fNeg ) / 2.0, SCHATTR_STAT_PERCENT ));
663 }
664 }
665 break;
666
667 case SCHATTR_STAT_BIGERROR:
668 {
669 bool bYError =
670 rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
671 uno::Reference< beans::XPropertySet > xErrorBarProp( lcl_GetErrorBar( GetPropertySet(),bYError));
672 if( xErrorBarProp.is())
673 {
674 double fPos(0.0), fNeg(0.0);
675 lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
676 rOutItemSet.Put( SvxDoubleItem( ( fPos + fNeg ) / 2.0, SCHATTR_STAT_BIGERROR ));
677 }
678 }
679 break;
680
681 case SCHATTR_STAT_CONSTPLUS:
682 {
683 bool bYError =
684 rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
685 uno::Reference< beans::XPropertySet > xErrorBarProp( lcl_GetErrorBar( GetPropertySet(),bYError));
686 if( xErrorBarProp.is())
687 {
688 double fPos(0.0), fNeg(0.0);
689 lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
690 rOutItemSet.Put( SvxDoubleItem( fPos, SCHATTR_STAT_CONSTPLUS ));
691 }
692 }
693 break;
694
695 case SCHATTR_STAT_CONSTMINUS:
696 {
697 bool bYError =
698 rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
699 uno::Reference< beans::XPropertySet > xErrorBarProp( lcl_GetErrorBar( GetPropertySet(),bYError));
700 if( xErrorBarProp.is())
701 {
702 double fPos(0.0), fNeg(0.0);
703 lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
704 rOutItemSet.Put( SvxDoubleItem( fNeg, SCHATTR_STAT_CONSTMINUS ));
705 }
706 }
707 break;
708
709 case SCHATTR_REGRESSION_TYPE:
710 {
711 SvxChartRegress eRegress =
712 RegressionCurveHelper::getFirstRegressTypeNotMeanValueLine(
713 uno::Reference< chart2::XRegressionCurveContainer >(
714 GetPropertySet(), uno::UNO_QUERY ) );
715 rOutItemSet.Put( SvxChartRegressItem( eRegress, SCHATTR_REGRESSION_TYPE ));
716 }
717 break;
718
719 case SCHATTR_REGRESSION_DEGREE:
720 {
721
722 uno::Reference<beans::XPropertySet> xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr ));
723 lclConvertToItemSet<sal_Int32, SfxInt32Item>(rOutItemSet, nWhichId, xProperties, u"PolynomialDegree"_ustr);
724 }
725 break;
726
727 case SCHATTR_REGRESSION_PERIOD:
728 {
729 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr ));
730 lclConvertToItemSet<sal_Int32, SfxInt32Item>(rOutItemSet, nWhichId, xProperties, u"MovingAveragePeriod"_ustr);
731 }
732 break;
733
734 case SCHATTR_REGRESSION_MOVING_TYPE:
735 {
736 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr ));
737 lclConvertToItemSet<sal_Int32, SfxInt32Item>(rOutItemSet, nWhichId, xProperties, u"MovingAverageType"_ustr);
738 }
739 break;
740
741 case SCHATTR_REGRESSION_EXTRAPOLATE_FORWARD:
742 {
743 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr ));
744 lclConvertToItemSetDouble(rOutItemSet, SCHATTR_REGRESSION_EXTRAPOLATE_FORWARD, xProperties, u"ExtrapolateForward"_ustr);
745 }
746 break;
747
748 case SCHATTR_REGRESSION_EXTRAPOLATE_BACKWARD:
749 {
750 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr ));
751 lclConvertToItemSetDouble(rOutItemSet, SCHATTR_REGRESSION_EXTRAPOLATE_BACKWARD, xProperties, u"ExtrapolateBackward"_ustr);
752 }
753 break;
754
755 case SCHATTR_REGRESSION_SET_INTERCEPT:
756 {
757 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr ));
758 lclConvertToItemSet<bool, SfxBoolItem>(rOutItemSet, nWhichId, xProperties, u"ForceIntercept"_ustr);
759 }
760 break;
761
762 case SCHATTR_REGRESSION_INTERCEPT_VALUE:
763 {
764 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr ));
765 lclConvertToItemSetDouble(rOutItemSet, SCHATTR_REGRESSION_INTERCEPT_VALUE, xProperties, u"InterceptValue"_ustr);
766 }
767 break;
768
769 case SCHATTR_REGRESSION_CURVE_NAME:
770 {
771 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr ));
772 lclConvertToItemSet<OUString, SfxStringItem>(rOutItemSet, nWhichId, xProperties, u"CurveName"_ustr);
773 }
774 break;
775
776 case SCHATTR_REGRESSION_SHOW_EQUATION:
777 {
778 uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), nullptr ));
779 lclConvertToItemSet<bool, SfxBoolItem>(rOutItemSet, nWhichId, xEqProp, u"ShowEquation"_ustr);
780 }
781 break;
782
783 case SCHATTR_REGRESSION_XNAME:
784 {
785 uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), nullptr ));
786 lclConvertToItemSet<OUString, SfxStringItem>(rOutItemSet, nWhichId, xEqProp, u"XName"_ustr);
787 }
788 break;
789
790 case SCHATTR_REGRESSION_YNAME:
791 {
792 uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), nullptr ));
793 lclConvertToItemSet<OUString, SfxStringItem>(rOutItemSet, nWhichId, xEqProp, u"YName"_ustr);
794 }
795 break;
796
797 case SCHATTR_REGRESSION_SHOW_COEFF:
798 {
799 uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), nullptr ));
800 lclConvertToItemSet<bool, SfxBoolItem>(rOutItemSet, nWhichId, xEqProp, u"ShowCorrelationCoefficient"_ustr);
801 }
802 break;
803
804 case SCHATTR_STAT_INDICATE:
805 {
806 bool bYError =
807 rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
808 uno::Reference< beans::XPropertySet > xErrorBarProp( lcl_GetErrorBar( GetPropertySet(),bYError));
809 SvxChartIndicate eIndicate = SvxChartIndicate::Both;
810 if( xErrorBarProp.is())
811 {
812 bool bShowPos(false), bShowNeg(false);
813 lcl_getErrorIndicatorValues( xErrorBarProp, bShowPos, bShowNeg );
814
815 if( bShowPos )
816 {
817 if( bShowNeg )
818 eIndicate = SvxChartIndicate::Both;
819 else
820 eIndicate = SvxChartIndicate::Up;
821 }
822 else
823 {
824 if( bShowNeg )
825 eIndicate = SvxChartIndicate::Down;
826 else
827 eIndicate = SvxChartIndicate::NONE;
828 }
829 }
830 rOutItemSet.Put( SvxChartIndicateItem( eIndicate, SCHATTR_STAT_INDICATE ));
831 }
832 break;
833
834 case SCHATTR_STAT_RANGE_POS:
835 case SCHATTR_STAT_RANGE_NEG:
836 {
837 bool bYError =
838 rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
839 uno::Reference< chart2::data::XDataSource > xErrorBarSource( lcl_GetErrorBar( GetPropertySet(),bYError),
840 uno::UNO_QUERY );
841 if( xErrorBarSource.is())
842 {
843 uno::Reference< chart2::data::XDataSequence > xSeq(
844 StatisticsHelper::getErrorDataSequenceFromDataSource(
845 xErrorBarSource, (nWhichId == SCHATTR_STAT_RANGE_POS), bYError ));
846 if( xSeq.is())
847 rOutItemSet.Put( SfxStringItem( nWhichId, xSeq->getSourceRangeRepresentation()));
848 }
849 }
850 break;
851 }
852 }
853
854 } // namespace chart
855
856 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */