Avoid potential negative array index access to cached text.
[LibreOffice.git] / chart2 / source / controller / itemsetwrapper / StatisticsItemConverter.cxx
blobc725972c249bd8f31d446000f9e08f03b473a136
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 <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>
29 #include <svl/stritem.hxx>
30 #include <svx/chrtitem.hxx>
31 #include <svl/intitem.hxx>
32 #include <rtl/math.hxx>
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>
40 using namespace ::com::sun::star;
42 namespace
45 uno::Reference< beans::XPropertySet > lcl_GetErrorBar(
46 const uno::Reference< beans::XPropertySet > & xProp, bool bYError )
48 uno::Reference< beans::XPropertySet > xResult;
50 if( xProp.is())
51 try
53 ( xProp->getPropertyValue( bYError ? CHART_UNONAME_ERRORBAR_Y : CHART_UNONAME_ERRORBAR_X ) >>= xResult );
55 catch( const uno::Exception & )
57 DBG_UNHANDLED_EXCEPTION("chart2");
60 return xResult;
63 uno::Reference< beans::XPropertySet > lcl_GetDefaultErrorBar()
65 return uno::Reference< beans::XPropertySet >( new ::chart::ErrorBar );
68 void lcl_getErrorValues( const uno::Reference< beans::XPropertySet > & xErrorBarProp,
69 double & rOutPosError, double & rOutNegError )
71 if( ! xErrorBarProp.is())
72 return;
74 try
76 xErrorBarProp->getPropertyValue( "PositiveError" ) >>= rOutPosError;
77 xErrorBarProp->getPropertyValue( "NegativeError" ) >>= rOutNegError;
79 catch( const uno::Exception & )
81 DBG_UNHANDLED_EXCEPTION("chart2");
85 void lcl_getErrorIndicatorValues(
86 const uno::Reference< beans::XPropertySet > & xErrorBarProp,
87 bool & rOutShowPosError, bool & rOutShowNegError )
89 if( ! xErrorBarProp.is())
90 return;
92 try
94 xErrorBarProp->getPropertyValue( "ShowPositiveError" ) >>= rOutShowPosError;
95 xErrorBarProp->getPropertyValue( "ShowNegativeError" ) >>= rOutShowNegError;
97 catch( const uno::Exception & )
99 DBG_UNHANDLED_EXCEPTION("chart2");
103 uno::Reference< beans::XPropertySet > lcl_getEquationProperties(
104 const uno::Reference< beans::XPropertySet > & xSeriesPropSet, const SfxItemSet * pItemSet )
106 bool bEquationExists = true;
108 // ensure that a trendline is on
109 if( pItemSet )
111 if( const SvxChartRegressItem* pRegressionItem = pItemSet->GetItemIfSet( SCHATTR_REGRESSION_TYPE ) )
113 SvxChartRegress eRegress = pRegressionItem->GetValue();
114 bEquationExists = ( eRegress != SvxChartRegress::NONE );
118 if( bEquationExists )
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())
125 return xCurve->getEquationProperties();
129 return uno::Reference< beans::XPropertySet >();
132 uno::Reference< beans::XPropertySet > lcl_getCurveProperties(
133 const uno::Reference< beans::XPropertySet > & xSeriesPropSet, const SfxItemSet * pItemSet )
135 bool bExists = true;
137 // ensure that a trendline is on
138 if( pItemSet )
140 if( const SvxChartRegressItem* pRegressionItem = pItemSet->GetItemIfSet( SCHATTR_REGRESSION_TYPE ) )
142 SvxChartRegress eRegress = pRegressionItem->GetValue();
143 bExists = ( eRegress != SvxChartRegress::NONE );
147 if( bExists )
149 uno::Reference< chart2::XRegressionCurveContainer > xRegCnt( xSeriesPropSet, uno::UNO_QUERY );
150 uno::Reference< chart2::XRegressionCurve > xCurve(
151 ::chart::RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegCnt ));
152 if( xCurve.is())
154 uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
155 return xProperties;
159 return uno::Reference< beans::XPropertySet >();
162 template <class T, class D>
163 bool lclConvertToPropertySet(const SfxItemSet& rItemSet, sal_uInt16 nWhichId, const uno::Reference<beans::XPropertySet>& xProperties, const OUString& aPropertyID)
165 OSL_ASSERT(xProperties.is());
166 if( xProperties.is() )
168 T aValue = static_cast<T>(static_cast<const D&>(rItemSet.Get( nWhichId )).GetValue());
169 T aOldValue = aValue;
170 bool aSuccess = xProperties->getPropertyValue( aPropertyID ) >>= aOldValue;
171 if (!aSuccess || aOldValue != aValue)
173 xProperties->setPropertyValue( aPropertyID , uno::Any( aValue ));
174 return true;
177 return false;
180 template <class T, class D>
181 void lclConvertToItemSet(SfxItemSet& rItemSet, sal_uInt16 nWhichId, const uno::Reference<beans::XPropertySet>& xProperties, const OUString& aPropertyID)
183 OSL_ASSERT(xProperties.is());
184 if( xProperties.is() )
186 T aValue = static_cast<T>(static_cast<const D&>(rItemSet.Get( nWhichId )).GetValue());
187 if(xProperties->getPropertyValue( aPropertyID ) >>= aValue)
189 rItemSet.Put(D( nWhichId, aValue ));
194 void lclConvertToItemSetDouble(SfxItemSet& rItemSet, TypedWhichId<SvxDoubleItem> nWhichId, const uno::Reference<beans::XPropertySet>& xProperties, const OUString& aPropertyID)
196 OSL_ASSERT(xProperties.is());
197 if( xProperties.is() )
199 double aValue = rItemSet.Get( nWhichId ).GetValue();
200 if(xProperties->getPropertyValue( aPropertyID ) >>= aValue)
202 rItemSet.Put(SvxDoubleItem( aValue, nWhichId ));
207 } // anonymous namespace
209 namespace chart::wrapper
212 StatisticsItemConverter::StatisticsItemConverter(
213 rtl::Reference<::chart::ChartModel> xModel,
214 const uno::Reference< beans::XPropertySet > & rPropertySet,
215 SfxItemPool& rItemPool ) :
216 ItemConverter( rPropertySet, rItemPool ),
217 m_xModel(std::move( xModel ))
221 StatisticsItemConverter::~StatisticsItemConverter()
225 const WhichRangesContainer& StatisticsItemConverter::GetWhichPairs() const
227 // must span all used items!
228 return nStatWhichPairs;
231 bool StatisticsItemConverter::GetItemProperty(
232 tWhichIdType /* nWhichId */,
233 tPropertyNameWithMemberId & /* rOutProperty */ ) const
235 return false;
238 bool StatisticsItemConverter::ApplySpecialItem(
239 sal_uInt16 nWhichId, const SfxItemSet & rItemSet )
241 bool bChanged = false;
243 switch( nWhichId )
245 case SCHATTR_STAT_AVERAGE:
247 uno::Reference< chart2::XRegressionCurveContainer > xRegCnt(
248 GetPropertySet(), uno::UNO_QUERY );
249 bool bOldHasMeanValueLine = RegressionCurveHelper::hasMeanValueLine( xRegCnt );
251 bool bNewHasMeanValueLine =
252 static_cast< const SfxBoolItem & >( rItemSet.Get( nWhichId )).GetValue();
254 if( bOldHasMeanValueLine != bNewHasMeanValueLine )
256 if( ! bNewHasMeanValueLine )
257 RegressionCurveHelper::removeMeanValueLine( xRegCnt );
258 else
259 RegressionCurveHelper::addMeanValueLine( xRegCnt, GetPropertySet() );
260 bChanged = true;
263 break;
265 // Attention !!! This case must be passed before SCHATTR_STAT_PERCENT,
266 // SCHATTR_STAT_BIGERROR, SCHATTR_STAT_CONSTPLUS,
267 // SCHATTR_STAT_CONSTMINUS and SCHATTR_STAT_INDICATE
268 case SCHATTR_STAT_KIND_ERROR:
270 bool bYError =
271 rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
273 uno::Reference< beans::XPropertySet > xErrorBarProp(
274 lcl_GetErrorBar( GetPropertySet(), bYError ));
276 SvxChartKindError eErrorKind =
277 static_cast< const SvxChartKindErrorItem & >(
278 rItemSet.Get( nWhichId )).GetValue();
280 if( !xErrorBarProp.is() && eErrorKind == SvxChartKindError::NONE)
282 //nothing to do
284 else
286 sal_Int32 nStyle = css::chart::ErrorBarStyle::NONE;
288 switch( eErrorKind )
290 case SvxChartKindError::NONE:
291 nStyle = css::chart::ErrorBarStyle::NONE; break;
292 case SvxChartKindError::Variant:
293 nStyle = css::chart::ErrorBarStyle::VARIANCE; break;
294 case SvxChartKindError::Sigma:
295 nStyle = css::chart::ErrorBarStyle::STANDARD_DEVIATION; break;
296 case SvxChartKindError::Percent:
297 nStyle = css::chart::ErrorBarStyle::RELATIVE; break;
298 case SvxChartKindError::BigError:
299 nStyle = css::chart::ErrorBarStyle::ERROR_MARGIN; break;
300 case SvxChartKindError::Const:
301 nStyle = css::chart::ErrorBarStyle::ABSOLUTE; break;
302 case SvxChartKindError::StdError:
303 nStyle = css::chart::ErrorBarStyle::STANDARD_ERROR; break;
304 case SvxChartKindError::Range:
305 nStyle = css::chart::ErrorBarStyle::FROM_DATA; break;
308 if( !xErrorBarProp.is() )
310 xErrorBarProp = lcl_GetDefaultErrorBar();
311 GetPropertySet()->setPropertyValue( bYError ? CHART_UNONAME_ERRORBAR_Y : CHART_UNONAME_ERRORBAR_X,
312 uno::Any( xErrorBarProp ));
315 xErrorBarProp->setPropertyValue( "ErrorBarStyle" , uno::Any( nStyle ));
316 bChanged = true;
319 break;
321 case SCHATTR_STAT_PERCENT:
322 case SCHATTR_STAT_BIGERROR:
324 OSL_FAIL( "Deprecated item" );
325 bool bYError =
326 rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
328 uno::Reference< beans::XPropertySet > xErrorBarProp(
329 lcl_GetErrorBar( GetPropertySet(), bYError));
330 bool bOldHasErrorBar = xErrorBarProp.is();
332 double fValue =
333 static_cast< const SvxDoubleItem & >(
334 rItemSet.Get( nWhichId )).GetValue();
335 double fPos(0.0), fNeg(0.0);
336 lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
338 if( bOldHasErrorBar &&
339 ! ( ::rtl::math::approxEqual( fPos, fValue ) &&
340 ::rtl::math::approxEqual( fNeg, fValue )))
342 xErrorBarProp->setPropertyValue( "PositiveError" , uno::Any( fValue ));
343 xErrorBarProp->setPropertyValue( "NegativeError" , uno::Any( fValue ));
344 bChanged = true;
347 break;
349 case SCHATTR_STAT_CONSTPLUS:
351 bool bYError =
352 rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
354 uno::Reference< beans::XPropertySet > xErrorBarProp(
355 lcl_GetErrorBar( GetPropertySet(),bYError));
356 bool bOldHasErrorBar = xErrorBarProp.is();
358 double fValue =
359 static_cast< const SvxDoubleItem & >(
360 rItemSet.Get( nWhichId )).GetValue();
361 double fPos(0.0), fNeg(0.0);
362 lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
364 if( bOldHasErrorBar &&
365 ! ::rtl::math::approxEqual( fPos, fValue ))
367 xErrorBarProp->setPropertyValue( "PositiveError" , uno::Any( fValue ));
368 bChanged = true;
371 break;
373 case SCHATTR_STAT_CONSTMINUS:
375 bool bYError =
376 rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
377 uno::Reference< beans::XPropertySet > xErrorBarProp(
378 lcl_GetErrorBar( GetPropertySet(),bYError));
379 bool bOldHasErrorBar = xErrorBarProp.is();
381 double fValue =
382 static_cast< const SvxDoubleItem & >(
383 rItemSet.Get( nWhichId )).GetValue();
384 double fPos(0.0), fNeg(0.0);
385 lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
387 if( bOldHasErrorBar &&
388 ! ::rtl::math::approxEqual( fNeg, fValue ))
390 xErrorBarProp->setPropertyValue( "NegativeError" , uno::Any( fValue ));
391 bChanged = true;
394 break;
396 case SCHATTR_REGRESSION_TYPE:
398 SvxChartRegress eRegress =
399 static_cast< const SvxChartRegressItem& >(
400 rItemSet.Get( nWhichId )).GetValue();
402 uno::Reference< chart2::XRegressionCurve > xCurve( GetPropertySet(), uno::UNO_QUERY );
403 uno::Reference< chart2::XRegressionCurveContainer > xContainer( GetPropertySet(), uno::UNO_QUERY );
405 if( eRegress == SvxChartRegress::NONE )
407 if ( xContainer.is() )
409 xContainer->removeRegressionCurve( xCurve );
410 bChanged = true;
413 else
415 if ( xCurve.is() )
417 SvxChartRegress eOldRegress(
418 RegressionCurveHelper::getRegressionType(xCurve));
420 if( eOldRegress != eRegress )
422 xCurve = RegressionCurveHelper::changeRegressionCurveType(
423 eRegress,
424 xContainer,
425 xCurve);
426 uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
427 resetPropertySet( xProperties );
428 bChanged = true;
433 break;
435 case SCHATTR_REGRESSION_DEGREE:
437 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
438 bChanged = lclConvertToPropertySet<sal_Int32, SfxInt32Item>(rItemSet, nWhichId, xProperties, "PolynomialDegree");
440 break;
442 case SCHATTR_REGRESSION_PERIOD:
444 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
445 bChanged = lclConvertToPropertySet<sal_Int32, SfxInt32Item>(rItemSet, nWhichId, xProperties, "MovingAveragePeriod");
447 break;
449 case SCHATTR_REGRESSION_MOVING_TYPE:
451 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
452 bChanged = lclConvertToPropertySet<sal_Int32, SfxInt32Item>(rItemSet, nWhichId, xProperties, "MovingAverageType");
454 break;
456 case SCHATTR_REGRESSION_EXTRAPOLATE_FORWARD:
458 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
459 bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties, "ExtrapolateForward");
461 break;
463 case SCHATTR_REGRESSION_EXTRAPOLATE_BACKWARD:
465 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
466 bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties, "ExtrapolateBackward");
468 break;
470 case SCHATTR_REGRESSION_SET_INTERCEPT:
472 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
473 bChanged = lclConvertToPropertySet<bool, SfxBoolItem>(rItemSet, nWhichId, xProperties, "ForceIntercept");
475 break;
477 case SCHATTR_REGRESSION_INTERCEPT_VALUE:
479 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
480 bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties, "InterceptValue");
482 break;
484 case SCHATTR_REGRESSION_CURVE_NAME:
486 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
487 bChanged = lclConvertToPropertySet<OUString, SfxStringItem>(rItemSet, nWhichId, xProperties, "CurveName");
489 break;
491 case SCHATTR_REGRESSION_SHOW_EQUATION:
493 uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), &rItemSet ));
494 bChanged = lclConvertToPropertySet<bool, SfxBoolItem>(rItemSet, nWhichId, xEqProp, "ShowEquation");
496 break;
498 case SCHATTR_REGRESSION_XNAME:
500 uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), &rItemSet ));
501 bChanged = lclConvertToPropertySet<OUString, SfxStringItem>(rItemSet, nWhichId, xEqProp, "XName");
503 break;
505 case SCHATTR_REGRESSION_YNAME:
507 uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), &rItemSet ));
508 bChanged = lclConvertToPropertySet<OUString, SfxStringItem>(rItemSet, nWhichId, xEqProp, "YName");
510 break;
512 case SCHATTR_REGRESSION_SHOW_COEFF:
514 uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), &rItemSet ));
515 bChanged = lclConvertToPropertySet<bool, SfxBoolItem>(rItemSet, nWhichId, xEqProp, "ShowCorrelationCoefficient");
517 break;
519 case SCHATTR_STAT_INDICATE:
521 bool bYError =
522 rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
523 uno::Reference< beans::XPropertySet > xErrorBarProp(
524 lcl_GetErrorBar( GetPropertySet(),bYError));
525 bool bOldHasErrorBar = xErrorBarProp.is();
527 SvxChartIndicate eIndicate =
528 static_cast< const SvxChartIndicateItem & >(
529 rItemSet.Get( nWhichId )).GetValue();
531 bool bNewIndPos = (eIndicate == SvxChartIndicate::Both || eIndicate == SvxChartIndicate::Up );
532 bool bNewIndNeg = (eIndicate == SvxChartIndicate::Both || eIndicate == SvxChartIndicate::Down );
534 bool bShowPos(false), bShowNeg(false);
535 lcl_getErrorIndicatorValues( xErrorBarProp, bShowPos, bShowNeg );
537 if( bOldHasErrorBar &&
538 ( bShowPos != bNewIndPos ||
539 bShowNeg != bNewIndNeg ))
541 xErrorBarProp->setPropertyValue( "ShowPositiveError" , uno::Any( bNewIndPos ));
542 xErrorBarProp->setPropertyValue( "ShowNegativeError" , uno::Any( bNewIndNeg ));
543 bChanged = true;
546 break;
548 case SCHATTR_STAT_RANGE_POS:
549 case SCHATTR_STAT_RANGE_NEG:
551 const bool bYError =
552 rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
553 uno::Reference< chart2::data::XDataSource > xErrorBarSource( lcl_GetErrorBar( GetPropertySet(), bYError),
554 uno::UNO_QUERY );
555 uno::Reference< chart2::data::XDataProvider > xDataProvider;
557 if( m_xModel.is())
558 xDataProvider.set( m_xModel->getDataProvider());
559 if( xErrorBarSource.is() && xDataProvider.is())
561 OUString aNewRange( static_cast< const SfxStringItem & >( rItemSet.Get( nWhichId )).GetValue());
562 bool bApplyNewRange = false;
564 bool bIsPositiveValue( nWhichId == SCHATTR_STAT_RANGE_POS );
565 if( m_xModel->hasInternalDataProvider())
567 if( !aNewRange.isEmpty())
569 uno::Reference< chart2::data::XDataSequence > xSeq(
570 StatisticsHelper::getErrorDataSequenceFromDataSource(
571 xErrorBarSource, bIsPositiveValue, bYError ));
572 if( ! xSeq.is())
574 // no data range for error bars yet => create
575 uno::Reference< chart2::XInternalDataProvider > xIntDataProvider( xDataProvider, uno::UNO_QUERY );
576 OSL_ASSERT( xIntDataProvider.is());
577 if( xIntDataProvider.is())
579 xIntDataProvider->appendSequence();
580 aNewRange = "last";
581 bApplyNewRange = true;
586 else
588 uno::Reference< chart2::data::XDataSequence > xSeq(
589 StatisticsHelper::getErrorDataSequenceFromDataSource(
590 xErrorBarSource, bIsPositiveValue, bYError ));
591 bApplyNewRange =
592 ! ( xSeq.is() && (aNewRange == xSeq->getSourceRangeRepresentation()));
595 if( bApplyNewRange )
596 StatisticsHelper::setErrorDataSequence(
597 xErrorBarSource, xDataProvider, aNewRange, bIsPositiveValue, bYError );
600 break;
603 return bChanged;
606 void StatisticsItemConverter::FillSpecialItem(
607 sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const
609 switch( nWhichId )
611 case SCHATTR_STAT_AVERAGE:
612 rOutItemSet.Put(
613 SfxBoolItem( nWhichId,
614 RegressionCurveHelper::hasMeanValueLine(
615 uno::Reference< chart2::XRegressionCurveContainer >(
616 GetPropertySet(), uno::UNO_QUERY ))));
617 break;
619 case SCHATTR_STAT_KIND_ERROR:
621 bool bYError =
622 rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
623 SvxChartKindError eErrorKind = SvxChartKindError::NONE;
624 uno::Reference< beans::XPropertySet > xErrorBarProp(
625 lcl_GetErrorBar( GetPropertySet(), bYError));
626 if( xErrorBarProp.is() )
628 sal_Int32 nStyle = 0;
629 if( xErrorBarProp->getPropertyValue( "ErrorBarStyle" ) >>= nStyle )
631 switch( nStyle )
633 case css::chart::ErrorBarStyle::NONE:
634 break;
635 case css::chart::ErrorBarStyle::VARIANCE:
636 eErrorKind = SvxChartKindError::Variant; break;
637 case css::chart::ErrorBarStyle::STANDARD_DEVIATION:
638 eErrorKind = SvxChartKindError::Sigma; break;
639 case css::chart::ErrorBarStyle::ABSOLUTE:
640 eErrorKind = SvxChartKindError::Const; break;
641 case css::chart::ErrorBarStyle::RELATIVE:
642 eErrorKind = SvxChartKindError::Percent; break;
643 case css::chart::ErrorBarStyle::ERROR_MARGIN:
644 eErrorKind = SvxChartKindError::BigError; break;
645 case css::chart::ErrorBarStyle::STANDARD_ERROR:
646 eErrorKind = SvxChartKindError::StdError; break;
647 case css::chart::ErrorBarStyle::FROM_DATA:
648 eErrorKind = SvxChartKindError::Range; break;
652 rOutItemSet.Put( SvxChartKindErrorItem( eErrorKind, SCHATTR_STAT_KIND_ERROR ));
654 break;
656 case SCHATTR_STAT_PERCENT:
658 bool bYError =
659 rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
660 uno::Reference< beans::XPropertySet > xErrorBarProp( lcl_GetErrorBar( GetPropertySet(),bYError));
661 if( xErrorBarProp.is())
663 double fPos(0.0), fNeg(0.0);
664 lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
665 rOutItemSet.Put( SvxDoubleItem( ( fPos + fNeg ) / 2.0, SCHATTR_STAT_PERCENT ));
668 break;
670 case SCHATTR_STAT_BIGERROR:
672 bool bYError =
673 rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
674 uno::Reference< beans::XPropertySet > xErrorBarProp( lcl_GetErrorBar( GetPropertySet(),bYError));
675 if( xErrorBarProp.is())
677 double fPos(0.0), fNeg(0.0);
678 lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
679 rOutItemSet.Put( SvxDoubleItem( ( fPos + fNeg ) / 2.0, SCHATTR_STAT_BIGERROR ));
682 break;
684 case SCHATTR_STAT_CONSTPLUS:
686 bool bYError =
687 rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
688 uno::Reference< beans::XPropertySet > xErrorBarProp( lcl_GetErrorBar( GetPropertySet(),bYError));
689 if( xErrorBarProp.is())
691 double fPos(0.0), fNeg(0.0);
692 lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
693 rOutItemSet.Put( SvxDoubleItem( fPos, SCHATTR_STAT_CONSTPLUS ));
696 break;
698 case SCHATTR_STAT_CONSTMINUS:
700 bool bYError =
701 rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
702 uno::Reference< beans::XPropertySet > xErrorBarProp( lcl_GetErrorBar( GetPropertySet(),bYError));
703 if( xErrorBarProp.is())
705 double fPos(0.0), fNeg(0.0);
706 lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
707 rOutItemSet.Put( SvxDoubleItem( fNeg, SCHATTR_STAT_CONSTMINUS ));
710 break;
712 case SCHATTR_REGRESSION_TYPE:
714 SvxChartRegress eRegress =
715 RegressionCurveHelper::getFirstRegressTypeNotMeanValueLine(
716 uno::Reference< chart2::XRegressionCurveContainer >(
717 GetPropertySet(), uno::UNO_QUERY ) );
718 rOutItemSet.Put( SvxChartRegressItem( eRegress, SCHATTR_REGRESSION_TYPE ));
720 break;
722 case SCHATTR_REGRESSION_DEGREE:
725 uno::Reference<beans::XPropertySet> xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr ));
726 lclConvertToItemSet<sal_Int32, SfxInt32Item>(rOutItemSet, nWhichId, xProperties, "PolynomialDegree");
728 break;
730 case SCHATTR_REGRESSION_PERIOD:
732 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr ));
733 lclConvertToItemSet<sal_Int32, SfxInt32Item>(rOutItemSet, nWhichId, xProperties, "MovingAveragePeriod");
735 break;
737 case SCHATTR_REGRESSION_MOVING_TYPE:
739 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr ));
740 lclConvertToItemSet<sal_Int32, SfxInt32Item>(rOutItemSet, nWhichId, xProperties, "MovingAverageType");
742 break;
744 case SCHATTR_REGRESSION_EXTRAPOLATE_FORWARD:
746 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr ));
747 lclConvertToItemSetDouble(rOutItemSet, SCHATTR_REGRESSION_EXTRAPOLATE_FORWARD, xProperties, "ExtrapolateForward");
749 break;
751 case SCHATTR_REGRESSION_EXTRAPOLATE_BACKWARD:
753 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr ));
754 lclConvertToItemSetDouble(rOutItemSet, SCHATTR_REGRESSION_EXTRAPOLATE_BACKWARD, xProperties, "ExtrapolateBackward");
756 break;
758 case SCHATTR_REGRESSION_SET_INTERCEPT:
760 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr ));
761 lclConvertToItemSet<bool, SfxBoolItem>(rOutItemSet, nWhichId, xProperties, "ForceIntercept");
763 break;
765 case SCHATTR_REGRESSION_INTERCEPT_VALUE:
767 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr ));
768 lclConvertToItemSetDouble(rOutItemSet, SCHATTR_REGRESSION_INTERCEPT_VALUE, xProperties, "InterceptValue");
770 break;
772 case SCHATTR_REGRESSION_CURVE_NAME:
774 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr ));
775 lclConvertToItemSet<OUString, SfxStringItem>(rOutItemSet, nWhichId, xProperties, "CurveName");
777 break;
779 case SCHATTR_REGRESSION_SHOW_EQUATION:
781 uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), nullptr ));
782 lclConvertToItemSet<bool, SfxBoolItem>(rOutItemSet, nWhichId, xEqProp, "ShowEquation");
784 break;
786 case SCHATTR_REGRESSION_XNAME:
788 uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), nullptr ));
789 lclConvertToItemSet<OUString, SfxStringItem>(rOutItemSet, nWhichId, xEqProp, "XName");
791 break;
793 case SCHATTR_REGRESSION_YNAME:
795 uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), nullptr ));
796 lclConvertToItemSet<OUString, SfxStringItem>(rOutItemSet, nWhichId, xEqProp, "YName");
798 break;
800 case SCHATTR_REGRESSION_SHOW_COEFF:
802 uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), nullptr ));
803 lclConvertToItemSet<bool, SfxBoolItem>(rOutItemSet, nWhichId, xEqProp, "ShowCorrelationCoefficient");
805 break;
807 case SCHATTR_STAT_INDICATE:
809 bool bYError =
810 rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
811 uno::Reference< beans::XPropertySet > xErrorBarProp( lcl_GetErrorBar( GetPropertySet(),bYError));
812 SvxChartIndicate eIndicate = SvxChartIndicate::Both;
813 if( xErrorBarProp.is())
815 bool bShowPos(false), bShowNeg(false);
816 lcl_getErrorIndicatorValues( xErrorBarProp, bShowPos, bShowNeg );
818 if( bShowPos )
820 if( bShowNeg )
821 eIndicate = SvxChartIndicate::Both;
822 else
823 eIndicate = SvxChartIndicate::Up;
825 else
827 if( bShowNeg )
828 eIndicate = SvxChartIndicate::Down;
829 else
830 eIndicate = SvxChartIndicate::NONE;
833 rOutItemSet.Put( SvxChartIndicateItem( eIndicate, SCHATTR_STAT_INDICATE ));
835 break;
837 case SCHATTR_STAT_RANGE_POS:
838 case SCHATTR_STAT_RANGE_NEG:
840 bool bYError =
841 rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
842 uno::Reference< chart2::data::XDataSource > xErrorBarSource( lcl_GetErrorBar( GetPropertySet(),bYError),
843 uno::UNO_QUERY );
844 if( xErrorBarSource.is())
846 uno::Reference< chart2::data::XDataSequence > xSeq(
847 StatisticsHelper::getErrorDataSequenceFromDataSource(
848 xErrorBarSource, (nWhichId == SCHATTR_STAT_RANGE_POS), bYError ));
849 if( xSeq.is())
850 rOutItemSet.Put( SfxStringItem( nWhichId, xSeq->getSourceRangeRepresentation()));
853 break;
857 } // namespace chart
859 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */