vcl: allow for overriding the default PDF rendering resolution
[LibreOffice.git] / chart2 / source / controller / itemsetwrapper / StatisticsItemConverter.cxx
blob6d6a9f6788bd4a3f9aa783b975fc7880155bc973
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 SvxChartRegress eRegress = SvxChartRegress::NONE;
111 const SfxPoolItem *pPoolItem = nullptr;
112 if( pItemSet->GetItemState( SCHATTR_REGRESSION_TYPE, true, &pPoolItem ) == SfxItemState::SET )
114 eRegress = static_cast< const SvxChartRegressItem * >( pPoolItem )->GetValue();
115 bEquationExists = ( eRegress != SvxChartRegress::NONE );
119 if( bEquationExists )
121 uno::Reference< chart2::XRegressionCurveContainer > xRegCnt( xSeriesPropSet, uno::UNO_QUERY );
122 uno::Reference< chart2::XRegressionCurve > xCurve(
123 ::chart::RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegCnt ));
124 if( xCurve.is())
126 return xCurve->getEquationProperties();
130 return uno::Reference< beans::XPropertySet >();
133 uno::Reference< beans::XPropertySet > lcl_getCurveProperties(
134 const uno::Reference< beans::XPropertySet > & xSeriesPropSet, const SfxItemSet * pItemSet )
136 bool bExists = true;
138 // ensure that a trendline is on
139 if( pItemSet )
141 SvxChartRegress eRegress = SvxChartRegress::NONE;
142 const SfxPoolItem *pPoolItem = nullptr;
143 if( pItemSet->GetItemState( SCHATTR_REGRESSION_TYPE, true, &pPoolItem ) == SfxItemState::SET )
145 eRegress = static_cast< const SvxChartRegressItem * >( pPoolItem )->GetValue();
146 bExists = ( eRegress != SvxChartRegress::NONE );
150 if( bExists )
152 uno::Reference< chart2::XRegressionCurveContainer > xRegCnt( xSeriesPropSet, uno::UNO_QUERY );
153 uno::Reference< chart2::XRegressionCurve > xCurve(
154 ::chart::RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegCnt ));
155 if( xCurve.is())
157 uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
158 return xProperties;
162 return uno::Reference< beans::XPropertySet >();
165 template <class T, class D>
166 bool lclConvertToPropertySet(const SfxItemSet& rItemSet, sal_uInt16 nWhichId, const uno::Reference<beans::XPropertySet>& xProperties, const OUString& aPropertyID)
168 OSL_ASSERT(xProperties.is());
169 if( xProperties.is() )
171 T aValue = static_cast<T>(static_cast<const D&>(rItemSet.Get( nWhichId )).GetValue());
172 T aOldValue = aValue;
173 bool aSuccess = xProperties->getPropertyValue( aPropertyID ) >>= aOldValue;
174 if (!aSuccess || aOldValue != aValue)
176 xProperties->setPropertyValue( aPropertyID , uno::Any( aValue ));
177 return true;
180 return false;
183 template <class T, class D>
184 void lclConvertToItemSet(SfxItemSet& rItemSet, sal_uInt16 nWhichId, const uno::Reference<beans::XPropertySet>& xProperties, const OUString& aPropertyID)
186 OSL_ASSERT(xProperties.is());
187 if( xProperties.is() )
189 T aValue = static_cast<T>(static_cast<const D&>(rItemSet.Get( nWhichId )).GetValue());
190 if(xProperties->getPropertyValue( aPropertyID ) >>= aValue)
192 rItemSet.Put(D( nWhichId, aValue ));
197 void lclConvertToItemSetDouble(SfxItemSet& rItemSet, sal_uInt16 nWhichId, const uno::Reference<beans::XPropertySet>& xProperties, const OUString& aPropertyID)
199 OSL_ASSERT(xProperties.is());
200 if( xProperties.is() )
202 double aValue = static_cast<const SvxDoubleItem&>(rItemSet.Get( nWhichId )).GetValue();
203 if(xProperties->getPropertyValue( aPropertyID ) >>= aValue)
205 rItemSet.Put(SvxDoubleItem( aValue, nWhichId ));
210 } // anonymous namespace
212 namespace chart
214 namespace wrapper
217 StatisticsItemConverter::StatisticsItemConverter(
218 const uno::Reference< frame::XModel > & xModel,
219 const uno::Reference< beans::XPropertySet > & rPropertySet,
220 SfxItemPool& rItemPool ) :
221 ItemConverter( rPropertySet, rItemPool ),
222 m_xModel( xModel )
226 StatisticsItemConverter::~StatisticsItemConverter()
230 const sal_uInt16 * StatisticsItemConverter::GetWhichPairs() const
232 // must span all used items!
233 return nStatWhichPairs;
236 bool StatisticsItemConverter::GetItemProperty(
237 tWhichIdType /* nWhichId */,
238 tPropertyNameWithMemberId & /* rOutProperty */ ) const
240 return false;
243 bool StatisticsItemConverter::ApplySpecialItem(
244 sal_uInt16 nWhichId, const SfxItemSet & rItemSet )
246 bool bChanged = false;
248 switch( nWhichId )
250 case SCHATTR_STAT_AVERAGE:
252 uno::Reference< chart2::XRegressionCurveContainer > xRegCnt(
253 GetPropertySet(), uno::UNO_QUERY );
254 bool bOldHasMeanValueLine = RegressionCurveHelper::hasMeanValueLine( xRegCnt );
256 bool bNewHasMeanValueLine =
257 static_cast< const SfxBoolItem & >( rItemSet.Get( nWhichId )).GetValue();
259 if( bOldHasMeanValueLine != bNewHasMeanValueLine )
261 if( ! bNewHasMeanValueLine )
262 RegressionCurveHelper::removeMeanValueLine( xRegCnt );
263 else
264 RegressionCurveHelper::addMeanValueLine( xRegCnt, GetPropertySet() );
265 bChanged = true;
268 break;
270 // Attention !!! This case must be passed before SCHATTR_STAT_PERCENT,
271 // SCHATTR_STAT_BIGERROR, SCHATTR_STAT_CONSTPLUS,
272 // SCHATTR_STAT_CONSTMINUS and SCHATTR_STAT_INDICATE
273 case SCHATTR_STAT_KIND_ERROR:
275 bool bYError =
276 rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
278 uno::Reference< beans::XPropertySet > xErrorBarProp(
279 lcl_GetErrorBar( GetPropertySet(), bYError ));
281 SvxChartKindError eErrorKind =
282 static_cast< const SvxChartKindErrorItem & >(
283 rItemSet.Get( nWhichId )).GetValue();
285 if( !xErrorBarProp.is() && eErrorKind == SvxChartKindError::NONE)
287 //nothing to do
289 else
291 sal_Int32 nStyle = css::chart::ErrorBarStyle::NONE;
293 switch( eErrorKind )
295 case SvxChartKindError::NONE:
296 nStyle = css::chart::ErrorBarStyle::NONE; break;
297 case SvxChartKindError::Variant:
298 nStyle = css::chart::ErrorBarStyle::VARIANCE; break;
299 case SvxChartKindError::Sigma:
300 nStyle = css::chart::ErrorBarStyle::STANDARD_DEVIATION; break;
301 case SvxChartKindError::Percent:
302 nStyle = css::chart::ErrorBarStyle::RELATIVE; break;
303 case SvxChartKindError::BigError:
304 nStyle = css::chart::ErrorBarStyle::ERROR_MARGIN; break;
305 case SvxChartKindError::Const:
306 nStyle = css::chart::ErrorBarStyle::ABSOLUTE; break;
307 case SvxChartKindError::StdError:
308 nStyle = css::chart::ErrorBarStyle::STANDARD_ERROR; break;
309 case SvxChartKindError::Range:
310 nStyle = css::chart::ErrorBarStyle::FROM_DATA; break;
313 if( !xErrorBarProp.is() )
315 xErrorBarProp = lcl_GetDefaultErrorBar();
316 GetPropertySet()->setPropertyValue( bYError ? OUString(CHART_UNONAME_ERRORBAR_Y) : OUString(CHART_UNONAME_ERRORBAR_X),
317 uno::Any( xErrorBarProp ));
320 xErrorBarProp->setPropertyValue( "ErrorBarStyle" , uno::Any( nStyle ));
321 bChanged = true;
324 break;
326 case SCHATTR_STAT_PERCENT:
327 case SCHATTR_STAT_BIGERROR:
329 OSL_FAIL( "Deprecated item" );
330 bool bYError =
331 rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
333 uno::Reference< beans::XPropertySet > xErrorBarProp(
334 lcl_GetErrorBar( GetPropertySet(), bYError));
335 bool bOldHasErrorBar = xErrorBarProp.is();
337 double fValue =
338 static_cast< const SvxDoubleItem & >(
339 rItemSet.Get( nWhichId )).GetValue();
340 double fPos(0.0), fNeg(0.0);
341 lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
343 if( bOldHasErrorBar &&
344 ! ( ::rtl::math::approxEqual( fPos, fValue ) &&
345 ::rtl::math::approxEqual( fNeg, fValue )))
347 xErrorBarProp->setPropertyValue( "PositiveError" , uno::Any( fValue ));
348 xErrorBarProp->setPropertyValue( "NegativeError" , uno::Any( fValue ));
349 bChanged = true;
352 break;
354 case SCHATTR_STAT_CONSTPLUS:
356 bool bYError =
357 rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
359 uno::Reference< beans::XPropertySet > xErrorBarProp(
360 lcl_GetErrorBar( GetPropertySet(),bYError));
361 bool bOldHasErrorBar = xErrorBarProp.is();
363 double fValue =
364 static_cast< const SvxDoubleItem & >(
365 rItemSet.Get( nWhichId )).GetValue();
366 double fPos(0.0), fNeg(0.0);
367 lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
369 if( bOldHasErrorBar &&
370 ! ::rtl::math::approxEqual( fPos, fValue ))
372 xErrorBarProp->setPropertyValue( "PositiveError" , uno::Any( fValue ));
373 bChanged = true;
376 break;
378 case SCHATTR_STAT_CONSTMINUS:
380 bool bYError =
381 rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
382 uno::Reference< beans::XPropertySet > xErrorBarProp(
383 lcl_GetErrorBar( GetPropertySet(),bYError));
384 bool bOldHasErrorBar = xErrorBarProp.is();
386 double fValue =
387 static_cast< const SvxDoubleItem & >(
388 rItemSet.Get( nWhichId )).GetValue();
389 double fPos(0.0), fNeg(0.0);
390 lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
392 if( bOldHasErrorBar &&
393 ! ::rtl::math::approxEqual( fNeg, fValue ))
395 xErrorBarProp->setPropertyValue( "NegativeError" , uno::Any( fValue ));
396 bChanged = true;
399 break;
401 case SCHATTR_REGRESSION_TYPE:
403 SvxChartRegress eRegress =
404 static_cast< const SvxChartRegressItem& >(
405 rItemSet.Get( nWhichId )).GetValue();
407 uno::Reference< chart2::XRegressionCurve > xCurve( GetPropertySet(), uno::UNO_QUERY );
408 uno::Reference< chart2::XRegressionCurveContainer > xContainer( GetPropertySet(), uno::UNO_QUERY );
410 if( eRegress == SvxChartRegress::NONE )
412 if ( xContainer.is() )
414 xContainer->removeRegressionCurve( xCurve );
415 bChanged = true;
418 else
420 if ( xCurve.is() )
422 SvxChartRegress eOldRegress(
423 RegressionCurveHelper::getRegressionType(xCurve));
425 if( eOldRegress != eRegress )
427 xCurve = RegressionCurveHelper::changeRegressionCurveType(
428 eRegress,
429 xContainer,
430 xCurve);
431 uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
432 resetPropertySet( xProperties );
433 bChanged = true;
438 break;
440 case SCHATTR_REGRESSION_DEGREE:
442 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
443 bChanged = lclConvertToPropertySet<sal_Int32, SfxInt32Item>(rItemSet, nWhichId, xProperties, "PolynomialDegree");
445 break;
447 case SCHATTR_REGRESSION_PERIOD:
449 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
450 bChanged = lclConvertToPropertySet<sal_Int32, SfxInt32Item>(rItemSet, nWhichId, xProperties, "MovingAveragePeriod");
452 break;
454 case SCHATTR_REGRESSION_EXTRAPOLATE_FORWARD:
456 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
457 bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties, "ExtrapolateForward");
459 break;
461 case SCHATTR_REGRESSION_EXTRAPOLATE_BACKWARD:
463 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
464 bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties, "ExtrapolateBackward");
466 break;
468 case SCHATTR_REGRESSION_SET_INTERCEPT:
470 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
471 bChanged = lclConvertToPropertySet<bool, SfxBoolItem>(rItemSet, nWhichId, xProperties, "ForceIntercept");
473 break;
475 case SCHATTR_REGRESSION_INTERCEPT_VALUE:
477 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
478 bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties, "InterceptValue");
480 break;
482 case SCHATTR_REGRESSION_CURVE_NAME:
484 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
485 bChanged = lclConvertToPropertySet<OUString, SfxStringItem>(rItemSet, nWhichId, xProperties, "CurveName");
487 break;
489 case SCHATTR_REGRESSION_SHOW_EQUATION:
491 uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), &rItemSet ));
492 bChanged = lclConvertToPropertySet<bool, SfxBoolItem>(rItemSet, nWhichId, xEqProp, "ShowEquation");
494 break;
496 case SCHATTR_REGRESSION_XNAME:
498 uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), &rItemSet ));
499 bChanged = lclConvertToPropertySet<OUString, SfxStringItem>(rItemSet, nWhichId, xEqProp, "XName");
501 break;
503 case SCHATTR_REGRESSION_YNAME:
505 uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), &rItemSet ));
506 bChanged = lclConvertToPropertySet<OUString, SfxStringItem>(rItemSet, nWhichId, xEqProp, "YName");
508 break;
510 case SCHATTR_REGRESSION_SHOW_COEFF:
512 uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), &rItemSet ));
513 bChanged = lclConvertToPropertySet<bool, SfxBoolItem>(rItemSet, nWhichId, xEqProp, "ShowCorrelationCoefficient");
515 break;
517 case SCHATTR_STAT_INDICATE:
519 bool bYError =
520 rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
521 uno::Reference< beans::XPropertySet > xErrorBarProp(
522 lcl_GetErrorBar( GetPropertySet(),bYError));
523 bool bOldHasErrorBar = xErrorBarProp.is();
525 SvxChartIndicate eIndicate =
526 static_cast< const SvxChartIndicateItem & >(
527 rItemSet.Get( nWhichId )).GetValue();
529 bool bNewIndPos = (eIndicate == SvxChartIndicate::Both || eIndicate == SvxChartIndicate::Up );
530 bool bNewIndNeg = (eIndicate == SvxChartIndicate::Both || eIndicate == SvxChartIndicate::Down );
532 bool bShowPos(false), bShowNeg(false);
533 lcl_getErrorIndicatorValues( xErrorBarProp, bShowPos, bShowNeg );
535 if( bOldHasErrorBar &&
536 ( bShowPos != bNewIndPos ||
537 bShowNeg != bNewIndNeg ))
539 xErrorBarProp->setPropertyValue( "ShowPositiveError" , uno::Any( bNewIndPos ));
540 xErrorBarProp->setPropertyValue( "ShowNegativeError" , uno::Any( bNewIndNeg ));
541 bChanged = true;
544 break;
546 case SCHATTR_STAT_RANGE_POS:
547 case SCHATTR_STAT_RANGE_NEG:
549 const bool bYError =
550 rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
551 uno::Reference< chart2::data::XDataSource > xErrorBarSource( lcl_GetErrorBar( GetPropertySet(), bYError),
552 uno::UNO_QUERY );
553 uno::Reference< chart2::XChartDocument > xChartDoc( m_xModel, uno::UNO_QUERY );
554 uno::Reference< chart2::data::XDataProvider > xDataProvider;
556 if( xChartDoc.is())
557 xDataProvider.set( xChartDoc->getDataProvider());
558 if( xErrorBarSource.is() && xDataProvider.is())
560 OUString aNewRange( static_cast< const SfxStringItem & >( rItemSet.Get( nWhichId )).GetValue());
561 bool bApplyNewRange = false;
563 bool bIsPositiveValue( nWhichId == SCHATTR_STAT_RANGE_POS );
564 if( xChartDoc->hasInternalDataProvider())
566 if( !aNewRange.isEmpty())
568 uno::Reference< chart2::data::XDataSequence > xSeq(
569 StatisticsHelper::getErrorDataSequenceFromDataSource(
570 xErrorBarSource, bIsPositiveValue, bYError ));
571 if( ! xSeq.is())
573 // no data range for error bars yet => create
574 uno::Reference< chart2::XInternalDataProvider > xIntDataProvider( xDataProvider, uno::UNO_QUERY );
575 OSL_ASSERT( xIntDataProvider.is());
576 if( xIntDataProvider.is())
578 xIntDataProvider->appendSequence();
579 aNewRange = "last";
580 bApplyNewRange = true;
585 else
587 uno::Reference< chart2::data::XDataSequence > xSeq(
588 StatisticsHelper::getErrorDataSequenceFromDataSource(
589 xErrorBarSource, bIsPositiveValue, bYError ));
590 bApplyNewRange =
591 ! ( xSeq.is() && (aNewRange == xSeq->getSourceRangeRepresentation()));
594 if( bApplyNewRange )
595 StatisticsHelper::setErrorDataSequence(
596 xErrorBarSource, xDataProvider, aNewRange, bIsPositiveValue, bYError );
599 break;
602 return bChanged;
605 void StatisticsItemConverter::FillSpecialItem(
606 sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const
608 switch( nWhichId )
610 case SCHATTR_STAT_AVERAGE:
611 rOutItemSet.Put(
612 SfxBoolItem( nWhichId,
613 RegressionCurveHelper::hasMeanValueLine(
614 uno::Reference< chart2::XRegressionCurveContainer >(
615 GetPropertySet(), uno::UNO_QUERY ))));
616 break;
618 case SCHATTR_STAT_KIND_ERROR:
620 bool bYError =
621 rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
622 SvxChartKindError eErrorKind = SvxChartKindError::NONE;
623 uno::Reference< beans::XPropertySet > xErrorBarProp(
624 lcl_GetErrorBar( GetPropertySet(), bYError));
625 if( xErrorBarProp.is() )
627 sal_Int32 nStyle = 0;
628 if( xErrorBarProp->getPropertyValue( "ErrorBarStyle" ) >>= nStyle )
630 switch( nStyle )
632 case css::chart::ErrorBarStyle::NONE:
633 break;
634 case css::chart::ErrorBarStyle::VARIANCE:
635 eErrorKind = SvxChartKindError::Variant; break;
636 case css::chart::ErrorBarStyle::STANDARD_DEVIATION:
637 eErrorKind = SvxChartKindError::Sigma; break;
638 case css::chart::ErrorBarStyle::ABSOLUTE:
639 eErrorKind = SvxChartKindError::Const; break;
640 case css::chart::ErrorBarStyle::RELATIVE:
641 eErrorKind = SvxChartKindError::Percent; break;
642 case css::chart::ErrorBarStyle::ERROR_MARGIN:
643 eErrorKind = SvxChartKindError::BigError; break;
644 case css::chart::ErrorBarStyle::STANDARD_ERROR:
645 eErrorKind = SvxChartKindError::StdError; break;
646 case css::chart::ErrorBarStyle::FROM_DATA:
647 eErrorKind = SvxChartKindError::Range; break;
651 rOutItemSet.Put( SvxChartKindErrorItem( eErrorKind, SCHATTR_STAT_KIND_ERROR ));
653 break;
655 case SCHATTR_STAT_PERCENT:
657 bool bYError =
658 rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
659 uno::Reference< beans::XPropertySet > xErrorBarProp( lcl_GetErrorBar( GetPropertySet(),bYError));
660 if( xErrorBarProp.is())
662 double fPos(0.0), fNeg(0.0);
663 lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
664 rOutItemSet.Put( SvxDoubleItem( ( fPos + fNeg ) / 2.0, nWhichId ));
667 break;
669 case SCHATTR_STAT_BIGERROR:
671 bool bYError =
672 rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
673 uno::Reference< beans::XPropertySet > xErrorBarProp( lcl_GetErrorBar( GetPropertySet(),bYError));
674 if( xErrorBarProp.is())
676 double fPos(0.0), fNeg(0.0);
677 lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
678 rOutItemSet.Put( SvxDoubleItem( ( fPos + fNeg ) / 2.0, nWhichId ));
681 break;
683 case SCHATTR_STAT_CONSTPLUS:
685 bool bYError =
686 rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
687 uno::Reference< beans::XPropertySet > xErrorBarProp( lcl_GetErrorBar( GetPropertySet(),bYError));
688 if( xErrorBarProp.is())
690 double fPos(0.0), fNeg(0.0);
691 lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
692 rOutItemSet.Put( SvxDoubleItem( fPos, nWhichId ));
695 break;
697 case SCHATTR_STAT_CONSTMINUS:
699 bool bYError =
700 rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
701 uno::Reference< beans::XPropertySet > xErrorBarProp( lcl_GetErrorBar( GetPropertySet(),bYError));
702 if( xErrorBarProp.is())
704 double fPos(0.0), fNeg(0.0);
705 lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
706 rOutItemSet.Put( SvxDoubleItem( fNeg, nWhichId ));
709 break;
711 case SCHATTR_REGRESSION_TYPE:
713 SvxChartRegress eRegress =
714 RegressionCurveHelper::getFirstRegressTypeNotMeanValueLine(
715 uno::Reference< chart2::XRegressionCurveContainer >(
716 GetPropertySet(), uno::UNO_QUERY ) );
717 rOutItemSet.Put( SvxChartRegressItem( eRegress, SCHATTR_REGRESSION_TYPE ));
719 break;
721 case SCHATTR_REGRESSION_DEGREE:
724 uno::Reference<beans::XPropertySet> xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr ));
725 lclConvertToItemSet<sal_Int32, SfxInt32Item>(rOutItemSet, nWhichId, xProperties, "PolynomialDegree");
727 break;
729 case SCHATTR_REGRESSION_PERIOD:
731 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr ));
732 lclConvertToItemSet<sal_Int32, SfxInt32Item>(rOutItemSet, nWhichId, xProperties, "MovingAveragePeriod");
734 break;
736 case SCHATTR_REGRESSION_EXTRAPOLATE_FORWARD:
738 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr ));
739 lclConvertToItemSetDouble(rOutItemSet, nWhichId, xProperties, "ExtrapolateForward");
741 break;
743 case SCHATTR_REGRESSION_EXTRAPOLATE_BACKWARD:
745 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr ));
746 lclConvertToItemSetDouble(rOutItemSet, nWhichId, xProperties, "ExtrapolateBackward");
748 break;
750 case SCHATTR_REGRESSION_SET_INTERCEPT:
752 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr ));
753 lclConvertToItemSet<bool, SfxBoolItem>(rOutItemSet, nWhichId, xProperties, "ForceIntercept");
755 break;
757 case SCHATTR_REGRESSION_INTERCEPT_VALUE:
759 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr ));
760 lclConvertToItemSetDouble(rOutItemSet, nWhichId, xProperties, "InterceptValue");
762 break;
764 case SCHATTR_REGRESSION_CURVE_NAME:
766 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr ));
767 lclConvertToItemSet<OUString, SfxStringItem>(rOutItemSet, nWhichId, xProperties, "CurveName");
769 break;
771 case SCHATTR_REGRESSION_SHOW_EQUATION:
773 uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), nullptr ));
774 lclConvertToItemSet<bool, SfxBoolItem>(rOutItemSet, nWhichId, xEqProp, "ShowEquation");
776 break;
778 case SCHATTR_REGRESSION_XNAME:
780 uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), nullptr ));
781 lclConvertToItemSet<OUString, SfxStringItem>(rOutItemSet, nWhichId, xEqProp, "XName");
783 break;
785 case SCHATTR_REGRESSION_YNAME:
787 uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), nullptr ));
788 lclConvertToItemSet<OUString, SfxStringItem>(rOutItemSet, nWhichId, xEqProp, "YName");
790 break;
792 case SCHATTR_REGRESSION_SHOW_COEFF:
794 uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), nullptr ));
795 lclConvertToItemSet<bool, SfxBoolItem>(rOutItemSet, nWhichId, xEqProp, "ShowCorrelationCoefficient");
797 break;
799 case SCHATTR_STAT_INDICATE:
801 bool bYError =
802 rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
803 uno::Reference< beans::XPropertySet > xErrorBarProp( lcl_GetErrorBar( GetPropertySet(),bYError));
804 SvxChartIndicate eIndicate = SvxChartIndicate::Both;
805 if( xErrorBarProp.is())
807 bool bShowPos(false), bShowNeg(false);
808 lcl_getErrorIndicatorValues( xErrorBarProp, bShowPos, bShowNeg );
810 if( bShowPos )
812 if( bShowNeg )
813 eIndicate = SvxChartIndicate::Both;
814 else
815 eIndicate = SvxChartIndicate::Up;
817 else
819 if( bShowNeg )
820 eIndicate = SvxChartIndicate::Down;
821 else
822 eIndicate = SvxChartIndicate::NONE;
825 rOutItemSet.Put( SvxChartIndicateItem( eIndicate, SCHATTR_STAT_INDICATE ));
827 break;
829 case SCHATTR_STAT_RANGE_POS:
830 case SCHATTR_STAT_RANGE_NEG:
832 bool bYError =
833 rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
834 uno::Reference< chart2::data::XDataSource > xErrorBarSource( lcl_GetErrorBar( GetPropertySet(),bYError),
835 uno::UNO_QUERY );
836 if( xErrorBarSource.is())
838 uno::Reference< chart2::data::XDataSequence > xSeq(
839 StatisticsHelper::getErrorDataSequenceFromDataSource(
840 xErrorBarSource, (nWhichId == SCHATTR_STAT_RANGE_POS), bYError ));
841 if( xSeq.is())
842 rOutItemSet.Put( SfxStringItem( nWhichId, xSeq->getSourceRangeRepresentation()));
845 break;
849 } // namespace wrapper
850 } // namespace chart
852 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */