nss: upgrade to release 3.73
[LibreOffice.git] / chart2 / source / controller / itemsetwrapper / StatisticsItemConverter.cxx
blobc0691daf24cfd6c28d82f81c60eaad991716993e
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 <ErrorBar.hxx>
24 #include <StatisticsHelper.hxx>
26 #include <unonames.hxx>
28 #include <svl/stritem.hxx>
29 #include <svx/chrtitem.hxx>
30 #include <svl/intitem.hxx>
31 #include <rtl/math.hxx>
33 #include <com/sun/star/chart2/XInternalDataProvider.hpp>
34 #include <com/sun/star/chart2/XChartDocument.hpp>
35 #include <com/sun/star/chart2/XRegressionCurveContainer.hpp>
36 #include <com/sun/star/chart/ErrorBarStyle.hpp>
37 #include <tools/diagnose_ex.h>
39 using namespace ::com::sun::star;
41 namespace
44 uno::Reference< beans::XPropertySet > lcl_GetErrorBar(
45 const uno::Reference< beans::XPropertySet > & xProp, bool bYError )
47 uno::Reference< beans::XPropertySet > xResult;
49 if( xProp.is())
50 try
52 ( xProp->getPropertyValue( bYError ? OUString(CHART_UNONAME_ERRORBAR_Y) : OUString(CHART_UNONAME_ERRORBAR_X) ) >>= xResult );
54 catch( const uno::Exception & )
56 DBG_UNHANDLED_EXCEPTION("chart2");
59 return xResult;
62 uno::Reference< beans::XPropertySet > lcl_GetDefaultErrorBar()
64 return uno::Reference< beans::XPropertySet >( new ::chart::ErrorBar );
67 void lcl_getErrorValues( const uno::Reference< beans::XPropertySet > & xErrorBarProp,
68 double & rOutPosError, double & rOutNegError )
70 if( ! xErrorBarProp.is())
71 return;
73 try
75 xErrorBarProp->getPropertyValue( "PositiveError" ) >>= rOutPosError;
76 xErrorBarProp->getPropertyValue( "NegativeError" ) >>= rOutNegError;
78 catch( const uno::Exception & )
80 DBG_UNHANDLED_EXCEPTION("chart2");
84 void lcl_getErrorIndicatorValues(
85 const uno::Reference< beans::XPropertySet > & xErrorBarProp,
86 bool & rOutShowPosError, bool & rOutShowNegError )
88 if( ! xErrorBarProp.is())
89 return;
91 try
93 xErrorBarProp->getPropertyValue( "ShowPositiveError" ) >>= rOutShowPosError;
94 xErrorBarProp->getPropertyValue( "ShowNegativeError" ) >>= rOutShowNegError;
96 catch( const uno::Exception & )
98 DBG_UNHANDLED_EXCEPTION("chart2");
102 uno::Reference< beans::XPropertySet > lcl_getEquationProperties(
103 const uno::Reference< beans::XPropertySet > & xSeriesPropSet, const SfxItemSet * pItemSet )
105 bool bEquationExists = true;
107 // ensure that a trendline is on
108 if( pItemSet )
110 const SfxPoolItem *pPoolItem = nullptr;
111 if( pItemSet->GetItemState( SCHATTR_REGRESSION_TYPE, true, &pPoolItem ) == SfxItemState::SET )
113 SvxChartRegress eRegress = static_cast< const SvxChartRegressItem * >( pPoolItem )->GetValue();
114 bEquationExists = ( eRegress != SvxChartRegress::NONE );
118 if( bEquationExists )
120 uno::Reference< chart2::XRegressionCurveContainer > xRegCnt( xSeriesPropSet, uno::UNO_QUERY );
121 uno::Reference< chart2::XRegressionCurve > 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 const SfxPoolItem *pPoolItem = nullptr;
141 if( pItemSet->GetItemState( SCHATTR_REGRESSION_TYPE, true, &pPoolItem ) == SfxItemState::SET )
143 SvxChartRegress eRegress = static_cast< const SvxChartRegressItem * >( pPoolItem )->GetValue();
144 bExists = ( eRegress != SvxChartRegress::NONE );
148 if( bExists )
150 uno::Reference< chart2::XRegressionCurveContainer > xRegCnt( xSeriesPropSet, uno::UNO_QUERY );
151 uno::Reference< chart2::XRegressionCurve > xCurve(
152 ::chart::RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegCnt ));
153 if( xCurve.is())
155 uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
156 return xProperties;
160 return uno::Reference< beans::XPropertySet >();
163 template <class T, class D>
164 bool lclConvertToPropertySet(const SfxItemSet& rItemSet, sal_uInt16 nWhichId, const uno::Reference<beans::XPropertySet>& xProperties, const OUString& aPropertyID)
166 OSL_ASSERT(xProperties.is());
167 if( xProperties.is() )
169 T aValue = static_cast<T>(static_cast<const D&>(rItemSet.Get( nWhichId )).GetValue());
170 T aOldValue = aValue;
171 bool aSuccess = xProperties->getPropertyValue( aPropertyID ) >>= aOldValue;
172 if (!aSuccess || aOldValue != aValue)
174 xProperties->setPropertyValue( aPropertyID , uno::Any( aValue ));
175 return true;
178 return false;
181 template <class T, class D>
182 void lclConvertToItemSet(SfxItemSet& rItemSet, sal_uInt16 nWhichId, const uno::Reference<beans::XPropertySet>& xProperties, const OUString& aPropertyID)
184 OSL_ASSERT(xProperties.is());
185 if( xProperties.is() )
187 T aValue = static_cast<T>(static_cast<const D&>(rItemSet.Get( nWhichId )).GetValue());
188 if(xProperties->getPropertyValue( aPropertyID ) >>= aValue)
190 rItemSet.Put(D( nWhichId, aValue ));
195 void lclConvertToItemSetDouble(SfxItemSet& rItemSet, sal_uInt16 nWhichId, const uno::Reference<beans::XPropertySet>& xProperties, const OUString& aPropertyID)
197 OSL_ASSERT(xProperties.is());
198 if( xProperties.is() )
200 double aValue = static_cast<const SvxDoubleItem&>(rItemSet.Get( nWhichId )).GetValue();
201 if(xProperties->getPropertyValue( aPropertyID ) >>= aValue)
203 rItemSet.Put(SvxDoubleItem( aValue, nWhichId ));
208 } // anonymous namespace
210 namespace chart::wrapper
213 StatisticsItemConverter::StatisticsItemConverter(
214 const uno::Reference< frame::XModel > & xModel,
215 const uno::Reference< beans::XPropertySet > & rPropertySet,
216 SfxItemPool& rItemPool ) :
217 ItemConverter( rPropertySet, rItemPool ),
218 m_xModel( xModel )
222 StatisticsItemConverter::~StatisticsItemConverter()
226 const sal_uInt16 * StatisticsItemConverter::GetWhichPairs() const
228 // must span all used items!
229 return nStatWhichPairs;
232 bool StatisticsItemConverter::GetItemProperty(
233 tWhichIdType /* nWhichId */,
234 tPropertyNameWithMemberId & /* rOutProperty */ ) const
236 return false;
239 bool StatisticsItemConverter::ApplySpecialItem(
240 sal_uInt16 nWhichId, const SfxItemSet & rItemSet )
242 bool bChanged = false;
244 switch( nWhichId )
246 case SCHATTR_STAT_AVERAGE:
248 uno::Reference< chart2::XRegressionCurveContainer > xRegCnt(
249 GetPropertySet(), uno::UNO_QUERY );
250 bool bOldHasMeanValueLine = RegressionCurveHelper::hasMeanValueLine( xRegCnt );
252 bool bNewHasMeanValueLine =
253 static_cast< const SfxBoolItem & >( rItemSet.Get( nWhichId )).GetValue();
255 if( bOldHasMeanValueLine != bNewHasMeanValueLine )
257 if( ! bNewHasMeanValueLine )
258 RegressionCurveHelper::removeMeanValueLine( xRegCnt );
259 else
260 RegressionCurveHelper::addMeanValueLine( xRegCnt, GetPropertySet() );
261 bChanged = true;
264 break;
266 // Attention !!! This case must be passed before SCHATTR_STAT_PERCENT,
267 // SCHATTR_STAT_BIGERROR, SCHATTR_STAT_CONSTPLUS,
268 // SCHATTR_STAT_CONSTMINUS and SCHATTR_STAT_INDICATE
269 case SCHATTR_STAT_KIND_ERROR:
271 bool bYError =
272 rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
274 uno::Reference< beans::XPropertySet > xErrorBarProp(
275 lcl_GetErrorBar( GetPropertySet(), bYError ));
277 SvxChartKindError eErrorKind =
278 static_cast< const SvxChartKindErrorItem & >(
279 rItemSet.Get( nWhichId )).GetValue();
281 if( !xErrorBarProp.is() && eErrorKind == SvxChartKindError::NONE)
283 //nothing to do
285 else
287 sal_Int32 nStyle = css::chart::ErrorBarStyle::NONE;
289 switch( eErrorKind )
291 case SvxChartKindError::NONE:
292 nStyle = css::chart::ErrorBarStyle::NONE; break;
293 case SvxChartKindError::Variant:
294 nStyle = css::chart::ErrorBarStyle::VARIANCE; break;
295 case SvxChartKindError::Sigma:
296 nStyle = css::chart::ErrorBarStyle::STANDARD_DEVIATION; break;
297 case SvxChartKindError::Percent:
298 nStyle = css::chart::ErrorBarStyle::RELATIVE; break;
299 case SvxChartKindError::BigError:
300 nStyle = css::chart::ErrorBarStyle::ERROR_MARGIN; break;
301 case SvxChartKindError::Const:
302 nStyle = css::chart::ErrorBarStyle::ABSOLUTE; break;
303 case SvxChartKindError::StdError:
304 nStyle = css::chart::ErrorBarStyle::STANDARD_ERROR; break;
305 case SvxChartKindError::Range:
306 nStyle = css::chart::ErrorBarStyle::FROM_DATA; break;
309 if( !xErrorBarProp.is() )
311 xErrorBarProp = lcl_GetDefaultErrorBar();
312 GetPropertySet()->setPropertyValue( bYError ? OUString(CHART_UNONAME_ERRORBAR_Y) : OUString(CHART_UNONAME_ERRORBAR_X),
313 uno::Any( xErrorBarProp ));
316 xErrorBarProp->setPropertyValue( "ErrorBarStyle" , uno::Any( nStyle ));
317 bChanged = true;
320 break;
322 case SCHATTR_STAT_PERCENT:
323 case SCHATTR_STAT_BIGERROR:
325 OSL_FAIL( "Deprecated item" );
326 bool bYError =
327 rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
329 uno::Reference< beans::XPropertySet > xErrorBarProp(
330 lcl_GetErrorBar( GetPropertySet(), bYError));
331 bool bOldHasErrorBar = xErrorBarProp.is();
333 double fValue =
334 static_cast< const SvxDoubleItem & >(
335 rItemSet.Get( nWhichId )).GetValue();
336 double fPos(0.0), fNeg(0.0);
337 lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
339 if( bOldHasErrorBar &&
340 ! ( ::rtl::math::approxEqual( fPos, fValue ) &&
341 ::rtl::math::approxEqual( fNeg, fValue )))
343 xErrorBarProp->setPropertyValue( "PositiveError" , uno::Any( fValue ));
344 xErrorBarProp->setPropertyValue( "NegativeError" , uno::Any( fValue ));
345 bChanged = true;
348 break;
350 case SCHATTR_STAT_CONSTPLUS:
352 bool bYError =
353 rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
355 uno::Reference< beans::XPropertySet > xErrorBarProp(
356 lcl_GetErrorBar( GetPropertySet(),bYError));
357 bool bOldHasErrorBar = xErrorBarProp.is();
359 double fValue =
360 static_cast< const SvxDoubleItem & >(
361 rItemSet.Get( nWhichId )).GetValue();
362 double fPos(0.0), fNeg(0.0);
363 lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
365 if( bOldHasErrorBar &&
366 ! ::rtl::math::approxEqual( fPos, fValue ))
368 xErrorBarProp->setPropertyValue( "PositiveError" , uno::Any( fValue ));
369 bChanged = true;
372 break;
374 case SCHATTR_STAT_CONSTMINUS:
376 bool bYError =
377 rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
378 uno::Reference< beans::XPropertySet > xErrorBarProp(
379 lcl_GetErrorBar( GetPropertySet(),bYError));
380 bool bOldHasErrorBar = xErrorBarProp.is();
382 double fValue =
383 static_cast< const SvxDoubleItem & >(
384 rItemSet.Get( nWhichId )).GetValue();
385 double fPos(0.0), fNeg(0.0);
386 lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
388 if( bOldHasErrorBar &&
389 ! ::rtl::math::approxEqual( fNeg, fValue ))
391 xErrorBarProp->setPropertyValue( "NegativeError" , uno::Any( fValue ));
392 bChanged = true;
395 break;
397 case SCHATTR_REGRESSION_TYPE:
399 SvxChartRegress eRegress =
400 static_cast< const SvxChartRegressItem& >(
401 rItemSet.Get( nWhichId )).GetValue();
403 uno::Reference< chart2::XRegressionCurve > xCurve( GetPropertySet(), uno::UNO_QUERY );
404 uno::Reference< chart2::XRegressionCurveContainer > xContainer( GetPropertySet(), uno::UNO_QUERY );
406 if( eRegress == SvxChartRegress::NONE )
408 if ( xContainer.is() )
410 xContainer->removeRegressionCurve( xCurve );
411 bChanged = true;
414 else
416 if ( xCurve.is() )
418 SvxChartRegress eOldRegress(
419 RegressionCurveHelper::getRegressionType(xCurve));
421 if( eOldRegress != eRegress )
423 xCurve = RegressionCurveHelper::changeRegressionCurveType(
424 eRegress,
425 xContainer,
426 xCurve);
427 uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
428 resetPropertySet( xProperties );
429 bChanged = true;
434 break;
436 case SCHATTR_REGRESSION_DEGREE:
438 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
439 bChanged = lclConvertToPropertySet<sal_Int32, SfxInt32Item>(rItemSet, nWhichId, xProperties, "PolynomialDegree");
441 break;
443 case SCHATTR_REGRESSION_PERIOD:
445 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
446 bChanged = lclConvertToPropertySet<sal_Int32, SfxInt32Item>(rItemSet, nWhichId, xProperties, "MovingAveragePeriod");
448 break;
450 case SCHATTR_REGRESSION_EXTRAPOLATE_FORWARD:
452 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
453 bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties, "ExtrapolateForward");
455 break;
457 case SCHATTR_REGRESSION_EXTRAPOLATE_BACKWARD:
459 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
460 bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties, "ExtrapolateBackward");
462 break;
464 case SCHATTR_REGRESSION_SET_INTERCEPT:
466 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
467 bChanged = lclConvertToPropertySet<bool, SfxBoolItem>(rItemSet, nWhichId, xProperties, "ForceIntercept");
469 break;
471 case SCHATTR_REGRESSION_INTERCEPT_VALUE:
473 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
474 bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties, "InterceptValue");
476 break;
478 case SCHATTR_REGRESSION_CURVE_NAME:
480 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
481 bChanged = lclConvertToPropertySet<OUString, SfxStringItem>(rItemSet, nWhichId, xProperties, "CurveName");
483 break;
485 case SCHATTR_REGRESSION_SHOW_EQUATION:
487 uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), &rItemSet ));
488 bChanged = lclConvertToPropertySet<bool, SfxBoolItem>(rItemSet, nWhichId, xEqProp, "ShowEquation");
490 break;
492 case SCHATTR_REGRESSION_XNAME:
494 uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), &rItemSet ));
495 bChanged = lclConvertToPropertySet<OUString, SfxStringItem>(rItemSet, nWhichId, xEqProp, "XName");
497 break;
499 case SCHATTR_REGRESSION_YNAME:
501 uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), &rItemSet ));
502 bChanged = lclConvertToPropertySet<OUString, SfxStringItem>(rItemSet, nWhichId, xEqProp, "YName");
504 break;
506 case SCHATTR_REGRESSION_SHOW_COEFF:
508 uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), &rItemSet ));
509 bChanged = lclConvertToPropertySet<bool, SfxBoolItem>(rItemSet, nWhichId, xEqProp, "ShowCorrelationCoefficient");
511 break;
513 case SCHATTR_STAT_INDICATE:
515 bool bYError =
516 rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
517 uno::Reference< beans::XPropertySet > xErrorBarProp(
518 lcl_GetErrorBar( GetPropertySet(),bYError));
519 bool bOldHasErrorBar = xErrorBarProp.is();
521 SvxChartIndicate eIndicate =
522 static_cast< const SvxChartIndicateItem & >(
523 rItemSet.Get( nWhichId )).GetValue();
525 bool bNewIndPos = (eIndicate == SvxChartIndicate::Both || eIndicate == SvxChartIndicate::Up );
526 bool bNewIndNeg = (eIndicate == SvxChartIndicate::Both || eIndicate == SvxChartIndicate::Down );
528 bool bShowPos(false), bShowNeg(false);
529 lcl_getErrorIndicatorValues( xErrorBarProp, bShowPos, bShowNeg );
531 if( bOldHasErrorBar &&
532 ( bShowPos != bNewIndPos ||
533 bShowNeg != bNewIndNeg ))
535 xErrorBarProp->setPropertyValue( "ShowPositiveError" , uno::Any( bNewIndPos ));
536 xErrorBarProp->setPropertyValue( "ShowNegativeError" , uno::Any( bNewIndNeg ));
537 bChanged = true;
540 break;
542 case SCHATTR_STAT_RANGE_POS:
543 case SCHATTR_STAT_RANGE_NEG:
545 const bool bYError =
546 rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
547 uno::Reference< chart2::data::XDataSource > xErrorBarSource( lcl_GetErrorBar( GetPropertySet(), bYError),
548 uno::UNO_QUERY );
549 uno::Reference< chart2::XChartDocument > xChartDoc( m_xModel, uno::UNO_QUERY );
550 uno::Reference< chart2::data::XDataProvider > xDataProvider;
552 if( xChartDoc.is())
553 xDataProvider.set( xChartDoc->getDataProvider());
554 if( xErrorBarSource.is() && xDataProvider.is())
556 OUString aNewRange( static_cast< const SfxStringItem & >( rItemSet.Get( nWhichId )).GetValue());
557 bool bApplyNewRange = false;
559 bool bIsPositiveValue( nWhichId == SCHATTR_STAT_RANGE_POS );
560 if( xChartDoc->hasInternalDataProvider())
562 if( !aNewRange.isEmpty())
564 uno::Reference< chart2::data::XDataSequence > xSeq(
565 StatisticsHelper::getErrorDataSequenceFromDataSource(
566 xErrorBarSource, bIsPositiveValue, bYError ));
567 if( ! xSeq.is())
569 // no data range for error bars yet => create
570 uno::Reference< chart2::XInternalDataProvider > xIntDataProvider( xDataProvider, uno::UNO_QUERY );
571 OSL_ASSERT( xIntDataProvider.is());
572 if( xIntDataProvider.is())
574 xIntDataProvider->appendSequence();
575 aNewRange = "last";
576 bApplyNewRange = true;
581 else
583 uno::Reference< chart2::data::XDataSequence > xSeq(
584 StatisticsHelper::getErrorDataSequenceFromDataSource(
585 xErrorBarSource, bIsPositiveValue, bYError ));
586 bApplyNewRange =
587 ! ( xSeq.is() && (aNewRange == xSeq->getSourceRangeRepresentation()));
590 if( bApplyNewRange )
591 StatisticsHelper::setErrorDataSequence(
592 xErrorBarSource, xDataProvider, aNewRange, bIsPositiveValue, bYError );
595 break;
598 return bChanged;
601 void StatisticsItemConverter::FillSpecialItem(
602 sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const
604 switch( nWhichId )
606 case SCHATTR_STAT_AVERAGE:
607 rOutItemSet.Put(
608 SfxBoolItem( nWhichId,
609 RegressionCurveHelper::hasMeanValueLine(
610 uno::Reference< chart2::XRegressionCurveContainer >(
611 GetPropertySet(), uno::UNO_QUERY ))));
612 break;
614 case SCHATTR_STAT_KIND_ERROR:
616 bool bYError =
617 rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
618 SvxChartKindError eErrorKind = SvxChartKindError::NONE;
619 uno::Reference< beans::XPropertySet > xErrorBarProp(
620 lcl_GetErrorBar( GetPropertySet(), bYError));
621 if( xErrorBarProp.is() )
623 sal_Int32 nStyle = 0;
624 if( xErrorBarProp->getPropertyValue( "ErrorBarStyle" ) >>= nStyle )
626 switch( nStyle )
628 case css::chart::ErrorBarStyle::NONE:
629 break;
630 case css::chart::ErrorBarStyle::VARIANCE:
631 eErrorKind = SvxChartKindError::Variant; break;
632 case css::chart::ErrorBarStyle::STANDARD_DEVIATION:
633 eErrorKind = SvxChartKindError::Sigma; break;
634 case css::chart::ErrorBarStyle::ABSOLUTE:
635 eErrorKind = SvxChartKindError::Const; break;
636 case css::chart::ErrorBarStyle::RELATIVE:
637 eErrorKind = SvxChartKindError::Percent; break;
638 case css::chart::ErrorBarStyle::ERROR_MARGIN:
639 eErrorKind = SvxChartKindError::BigError; break;
640 case css::chart::ErrorBarStyle::STANDARD_ERROR:
641 eErrorKind = SvxChartKindError::StdError; break;
642 case css::chart::ErrorBarStyle::FROM_DATA:
643 eErrorKind = SvxChartKindError::Range; break;
647 rOutItemSet.Put( SvxChartKindErrorItem( eErrorKind, SCHATTR_STAT_KIND_ERROR ));
649 break;
651 case SCHATTR_STAT_PERCENT:
653 bool bYError =
654 rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
655 uno::Reference< beans::XPropertySet > xErrorBarProp( lcl_GetErrorBar( GetPropertySet(),bYError));
656 if( xErrorBarProp.is())
658 double fPos(0.0), fNeg(0.0);
659 lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
660 rOutItemSet.Put( SvxDoubleItem( ( fPos + fNeg ) / 2.0, nWhichId ));
663 break;
665 case SCHATTR_STAT_BIGERROR:
667 bool bYError =
668 rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
669 uno::Reference< beans::XPropertySet > xErrorBarProp( lcl_GetErrorBar( GetPropertySet(),bYError));
670 if( xErrorBarProp.is())
672 double fPos(0.0), fNeg(0.0);
673 lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
674 rOutItemSet.Put( SvxDoubleItem( ( fPos + fNeg ) / 2.0, nWhichId ));
677 break;
679 case SCHATTR_STAT_CONSTPLUS:
681 bool bYError =
682 rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
683 uno::Reference< beans::XPropertySet > xErrorBarProp( lcl_GetErrorBar( GetPropertySet(),bYError));
684 if( xErrorBarProp.is())
686 double fPos(0.0), fNeg(0.0);
687 lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
688 rOutItemSet.Put( SvxDoubleItem( fPos, nWhichId ));
691 break;
693 case SCHATTR_STAT_CONSTMINUS:
695 bool bYError =
696 rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
697 uno::Reference< beans::XPropertySet > xErrorBarProp( lcl_GetErrorBar( GetPropertySet(),bYError));
698 if( xErrorBarProp.is())
700 double fPos(0.0), fNeg(0.0);
701 lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
702 rOutItemSet.Put( SvxDoubleItem( fNeg, nWhichId ));
705 break;
707 case SCHATTR_REGRESSION_TYPE:
709 SvxChartRegress eRegress =
710 RegressionCurveHelper::getFirstRegressTypeNotMeanValueLine(
711 uno::Reference< chart2::XRegressionCurveContainer >(
712 GetPropertySet(), uno::UNO_QUERY ) );
713 rOutItemSet.Put( SvxChartRegressItem( eRegress, SCHATTR_REGRESSION_TYPE ));
715 break;
717 case SCHATTR_REGRESSION_DEGREE:
720 uno::Reference<beans::XPropertySet> xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr ));
721 lclConvertToItemSet<sal_Int32, SfxInt32Item>(rOutItemSet, nWhichId, xProperties, "PolynomialDegree");
723 break;
725 case SCHATTR_REGRESSION_PERIOD:
727 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr ));
728 lclConvertToItemSet<sal_Int32, SfxInt32Item>(rOutItemSet, nWhichId, xProperties, "MovingAveragePeriod");
730 break;
732 case SCHATTR_REGRESSION_EXTRAPOLATE_FORWARD:
734 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr ));
735 lclConvertToItemSetDouble(rOutItemSet, nWhichId, xProperties, "ExtrapolateForward");
737 break;
739 case SCHATTR_REGRESSION_EXTRAPOLATE_BACKWARD:
741 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr ));
742 lclConvertToItemSetDouble(rOutItemSet, nWhichId, xProperties, "ExtrapolateBackward");
744 break;
746 case SCHATTR_REGRESSION_SET_INTERCEPT:
748 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr ));
749 lclConvertToItemSet<bool, SfxBoolItem>(rOutItemSet, nWhichId, xProperties, "ForceIntercept");
751 break;
753 case SCHATTR_REGRESSION_INTERCEPT_VALUE:
755 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr ));
756 lclConvertToItemSetDouble(rOutItemSet, nWhichId, xProperties, "InterceptValue");
758 break;
760 case SCHATTR_REGRESSION_CURVE_NAME:
762 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr ));
763 lclConvertToItemSet<OUString, SfxStringItem>(rOutItemSet, nWhichId, xProperties, "CurveName");
765 break;
767 case SCHATTR_REGRESSION_SHOW_EQUATION:
769 uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), nullptr ));
770 lclConvertToItemSet<bool, SfxBoolItem>(rOutItemSet, nWhichId, xEqProp, "ShowEquation");
772 break;
774 case SCHATTR_REGRESSION_XNAME:
776 uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), nullptr ));
777 lclConvertToItemSet<OUString, SfxStringItem>(rOutItemSet, nWhichId, xEqProp, "XName");
779 break;
781 case SCHATTR_REGRESSION_YNAME:
783 uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), nullptr ));
784 lclConvertToItemSet<OUString, SfxStringItem>(rOutItemSet, nWhichId, xEqProp, "YName");
786 break;
788 case SCHATTR_REGRESSION_SHOW_COEFF:
790 uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), nullptr ));
791 lclConvertToItemSet<bool, SfxBoolItem>(rOutItemSet, nWhichId, xEqProp, "ShowCorrelationCoefficient");
793 break;
795 case SCHATTR_STAT_INDICATE:
797 bool bYError =
798 rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
799 uno::Reference< beans::XPropertySet > xErrorBarProp( lcl_GetErrorBar( GetPropertySet(),bYError));
800 SvxChartIndicate eIndicate = SvxChartIndicate::Both;
801 if( xErrorBarProp.is())
803 bool bShowPos(false), bShowNeg(false);
804 lcl_getErrorIndicatorValues( xErrorBarProp, bShowPos, bShowNeg );
806 if( bShowPos )
808 if( bShowNeg )
809 eIndicate = SvxChartIndicate::Both;
810 else
811 eIndicate = SvxChartIndicate::Up;
813 else
815 if( bShowNeg )
816 eIndicate = SvxChartIndicate::Down;
817 else
818 eIndicate = SvxChartIndicate::NONE;
821 rOutItemSet.Put( SvxChartIndicateItem( eIndicate, SCHATTR_STAT_INDICATE ));
823 break;
825 case SCHATTR_STAT_RANGE_POS:
826 case SCHATTR_STAT_RANGE_NEG:
828 bool bYError =
829 rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
830 uno::Reference< chart2::data::XDataSource > xErrorBarSource( lcl_GetErrorBar( GetPropertySet(),bYError),
831 uno::UNO_QUERY );
832 if( xErrorBarSource.is())
834 uno::Reference< chart2::data::XDataSequence > xSeq(
835 StatisticsHelper::getErrorDataSequenceFromDataSource(
836 xErrorBarSource, (nWhichId == SCHATTR_STAT_RANGE_POS), bYError ));
837 if( xSeq.is())
838 rOutItemSet.Put( SfxStringItem( nWhichId, xSeq->getSourceRangeRepresentation()));
841 break;
845 } // namespace chart
847 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */