fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / controller / itemsetwrapper / StatisticsItemConverter.cxx
blobf7d905c440a2563bf1a6cbad5df59e4498d1f604
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 "macros.hxx"
23 #include "RegressionCurveHelper.hxx"
24 #include "ItemPropertyMap.hxx"
25 #include "ErrorBar.hxx"
26 #include "PropertyHelper.hxx"
27 #include "ChartModelHelper.hxx"
28 #include "ChartTypeHelper.hxx"
29 #include "StatisticsHelper.hxx"
31 #include "GraphicPropertyItemConverter.hxx"
32 #include <unonames.hxx>
34 #include <svl/stritem.hxx>
35 #include <svx/chrtitem.hxx>
36 #include <svl/intitem.hxx>
37 #include <rtl/math.hxx>
39 #include <com/sun/star/chart2/DataPointLabel.hpp>
40 #include <com/sun/star/chart2/XInternalDataProvider.hpp>
41 #include <com/sun/star/chart/ErrorBarStyle.hpp>
42 #include <com/sun/star/lang/XServiceName.hpp>
44 #include <functional>
45 #include <algorithm>
46 #include <vector>
48 using namespace ::com::sun::star;
50 namespace
53 uno::Reference< beans::XPropertySet > lcl_GetErrorBar(
54 const uno::Reference< beans::XPropertySet > & xProp, bool bYError )
56 uno::Reference< beans::XPropertySet > xResult;
58 if( xProp.is())
59 try
61 ( xProp->getPropertyValue( bYError ? OUString(CHART_UNONAME_ERRORBAR_Y) : OUString(CHART_UNONAME_ERRORBAR_X) ) >>= xResult );
63 catch( const uno::Exception & ex )
65 ASSERT_EXCEPTION( ex );
68 return xResult;
71 uno::Reference< beans::XPropertySet > lcl_GetDefaultErrorBar()
73 // todo: use a valid context
74 return uno::Reference< beans::XPropertySet >(
75 ::chart::createErrorBar( uno::Reference< uno::XComponentContext >()));
78 void lcl_getErrorValues( const uno::Reference< beans::XPropertySet > & xErrorBarProp,
79 double & rOutPosError, double & rOutNegError )
81 if( ! xErrorBarProp.is())
82 return;
84 try
86 xErrorBarProp->getPropertyValue( "PositiveError" ) >>= rOutPosError;
87 xErrorBarProp->getPropertyValue( "NegativeError" ) >>= rOutNegError;
89 catch( const uno::Exception & ex )
91 ASSERT_EXCEPTION( ex );
95 void lcl_getErrorIndicatorValues(
96 const uno::Reference< beans::XPropertySet > & xErrorBarProp,
97 bool & rOutShowPosError, bool & rOutShowNegError )
99 if( ! xErrorBarProp.is())
100 return;
104 xErrorBarProp->getPropertyValue( "ShowPositiveError" ) >>= rOutShowPosError;
105 xErrorBarProp->getPropertyValue( "ShowNegativeError" ) >>= rOutShowNegError;
107 catch( const uno::Exception & ex )
109 ASSERT_EXCEPTION( ex );
113 uno::Reference< beans::XPropertySet > lcl_getEquationProperties(
114 const uno::Reference< beans::XPropertySet > & xSeriesPropSet, const SfxItemSet * pItemSet )
116 bool bEquationExists = true;
118 // ensure that a trendline is on
119 if( pItemSet )
121 SvxChartRegress eRegress = CHREGRESS_NONE;
122 const SfxPoolItem *pPoolItem = NULL;
123 if( pItemSet->GetItemState( SCHATTR_REGRESSION_TYPE, true, &pPoolItem ) == SfxItemState::SET )
125 eRegress = static_cast< const SvxChartRegressItem * >( pPoolItem )->GetValue();
126 bEquationExists = ( eRegress != CHREGRESS_NONE );
130 if( bEquationExists )
132 uno::Reference< chart2::XRegressionCurveContainer > xRegCnt( xSeriesPropSet, uno::UNO_QUERY );
133 uno::Reference< chart2::XRegressionCurve > xCurve(
134 ::chart::RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegCnt ));
135 if( xCurve.is())
137 return xCurve->getEquationProperties();
141 return uno::Reference< beans::XPropertySet >();
144 uno::Reference< beans::XPropertySet > lcl_getCurveProperties(
145 const uno::Reference< beans::XPropertySet > & xSeriesPropSet, const SfxItemSet * pItemSet )
147 bool bExists = true;
149 // ensure that a trendline is on
150 if( pItemSet )
152 SvxChartRegress eRegress = CHREGRESS_NONE;
153 const SfxPoolItem *pPoolItem = NULL;
154 if( pItemSet->GetItemState( SCHATTR_REGRESSION_TYPE, true, &pPoolItem ) == SfxItemState::SET )
156 eRegress = static_cast< const SvxChartRegressItem * >( pPoolItem )->GetValue();
157 bExists = ( eRegress != CHREGRESS_NONE );
161 if( bExists )
163 uno::Reference< chart2::XRegressionCurveContainer > xRegCnt( xSeriesPropSet, uno::UNO_QUERY );
164 uno::Reference< chart2::XRegressionCurve > xCurve(
165 ::chart::RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegCnt ));
166 if( xCurve.is())
168 uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
169 return xProperties;
173 return uno::Reference< beans::XPropertySet >();
176 template <class T, class D>
177 bool lclConvertToPropertySet(const SfxItemSet& rItemSet, sal_uInt16 nWhichId, uno::Reference<beans::XPropertySet> xProperties, const OUString& aPropertyID)
179 OSL_ASSERT(xProperties.is());
180 if( xProperties.is() )
182 T aValue = static_cast<T>(static_cast<const D&>(rItemSet.Get( nWhichId )).GetValue());
183 T aOldValue = aValue;
184 bool aSuccess = xProperties->getPropertyValue( aPropertyID ) >>= aOldValue;
185 if (!aSuccess || aOldValue != aValue)
187 xProperties->setPropertyValue( aPropertyID , uno::makeAny( aValue ));
188 return true;
191 return false;
194 template <class T, class D>
195 void lclConvertToItemSet(SfxItemSet& rItemSet, sal_uInt16 nWhichId, uno::Reference<beans::XPropertySet> xProperties, const OUString& aPropertyID)
197 OSL_ASSERT(xProperties.is());
198 if( xProperties.is() )
200 T aValue = static_cast<T>(static_cast<const D&>(rItemSet.Get( nWhichId )).GetValue());
201 if(xProperties->getPropertyValue( aPropertyID ) >>= aValue)
203 rItemSet.Put(D( nWhichId, aValue ));
208 void lclConvertToItemSetDouble(SfxItemSet& rItemSet, sal_uInt16 nWhichId, uno::Reference<beans::XPropertySet> xProperties, const OUString& aPropertyID)
210 OSL_ASSERT(xProperties.is());
211 if( xProperties.is() )
213 double aValue = static_cast<double>(static_cast<const SvxDoubleItem&>(rItemSet.Get( nWhichId )).GetValue());
214 if(xProperties->getPropertyValue( aPropertyID ) >>= aValue)
216 rItemSet.Put(SvxDoubleItem( aValue, nWhichId ));
221 } // anonymous namespace
223 namespace chart
225 namespace wrapper
228 StatisticsItemConverter::StatisticsItemConverter(
229 const uno::Reference< frame::XModel > & xModel,
230 const uno::Reference< beans::XPropertySet > & rPropertySet,
231 SfxItemPool& rItemPool ) :
232 ItemConverter( rPropertySet, rItemPool ),
233 m_xModel( xModel )
237 StatisticsItemConverter::~StatisticsItemConverter()
241 const sal_uInt16 * StatisticsItemConverter::GetWhichPairs() const
243 // must span all used items!
244 return nStatWhichPairs;
247 bool StatisticsItemConverter::GetItemProperty(
248 tWhichIdType /* nWhichId */,
249 tPropertyNameWithMemberId & /* rOutProperty */ ) const
251 return false;
254 bool StatisticsItemConverter::ApplySpecialItem(
255 sal_uInt16 nWhichId, const SfxItemSet & rItemSet )
256 throw( uno::Exception )
258 bool bChanged = false;
260 switch( nWhichId )
262 case SCHATTR_STAT_AVERAGE:
264 uno::Reference< chart2::XRegressionCurveContainer > xRegCnt(
265 GetPropertySet(), uno::UNO_QUERY );
266 bool bOldHasMeanValueLine = RegressionCurveHelper::hasMeanValueLine( xRegCnt );
268 bool bNewHasMeanValueLine =
269 static_cast< const SfxBoolItem & >( rItemSet.Get( nWhichId )).GetValue();
271 if( bOldHasMeanValueLine != bNewHasMeanValueLine )
273 if( ! bNewHasMeanValueLine )
274 RegressionCurveHelper::removeMeanValueLine( xRegCnt );
275 else
276 RegressionCurveHelper::addMeanValueLine(
277 xRegCnt, uno::Reference< uno::XComponentContext >(), GetPropertySet() );
278 bChanged = true;
281 break;
283 // Attention !!! This case must be passed before SCHATTR_STAT_PERCENT,
284 // SCHATTR_STAT_BIGERROR, SCHATTR_STAT_CONSTPLUS,
285 // SCHATTR_STAT_CONSTMINUS and SCHATTR_STAT_INDICATE
286 case SCHATTR_STAT_KIND_ERROR:
288 bool bYError =
289 static_cast<const SfxBoolItem&>(rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE)).GetValue();
291 uno::Reference< beans::XPropertySet > xErrorBarProp(
292 lcl_GetErrorBar( GetPropertySet(), bYError ));
294 SvxChartKindError eErrorKind =
295 static_cast< const SvxChartKindErrorItem & >(
296 rItemSet.Get( nWhichId )).GetValue();
298 if( !xErrorBarProp.is() && eErrorKind == CHERROR_NONE)
300 //nothing to do
302 else
304 sal_Int32 nStyle = ::com::sun::star::chart::ErrorBarStyle::NONE;
306 switch( eErrorKind )
308 case CHERROR_NONE:
309 nStyle = ::com::sun::star::chart::ErrorBarStyle::NONE; break;
310 case CHERROR_VARIANT:
311 nStyle = ::com::sun::star::chart::ErrorBarStyle::VARIANCE; break;
312 case CHERROR_SIGMA:
313 nStyle = ::com::sun::star::chart::ErrorBarStyle::STANDARD_DEVIATION; break;
314 case CHERROR_PERCENT:
315 nStyle = ::com::sun::star::chart::ErrorBarStyle::RELATIVE; break;
316 case CHERROR_BIGERROR:
317 nStyle = ::com::sun::star::chart::ErrorBarStyle::ERROR_MARGIN; break;
318 case CHERROR_CONST:
319 nStyle = ::com::sun::star::chart::ErrorBarStyle::ABSOLUTE; break;
320 case CHERROR_STDERROR:
321 nStyle = ::com::sun::star::chart::ErrorBarStyle::STANDARD_ERROR; break;
322 case CHERROR_RANGE:
323 nStyle = ::com::sun::star::chart::ErrorBarStyle::FROM_DATA; break;
326 if( !xErrorBarProp.is() )
328 xErrorBarProp = lcl_GetDefaultErrorBar();
329 GetPropertySet()->setPropertyValue( bYError ? OUString(CHART_UNONAME_ERRORBAR_Y) : OUString(CHART_UNONAME_ERRORBAR_X),
330 uno::makeAny( xErrorBarProp ));
333 xErrorBarProp->setPropertyValue( "ErrorBarStyle" , uno::makeAny( nStyle ));
334 bChanged = true;
337 break;
339 case SCHATTR_STAT_PERCENT:
340 case SCHATTR_STAT_BIGERROR:
342 OSL_FAIL( "Deprecated item" );
343 bool bYError =
344 static_cast<const SfxBoolItem&>(rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE)).GetValue();
346 uno::Reference< beans::XPropertySet > xErrorBarProp(
347 lcl_GetErrorBar( GetPropertySet(), bYError));
348 bool bOldHasErrorBar = xErrorBarProp.is();
350 double fValue =
351 static_cast< const SvxDoubleItem & >(
352 rItemSet.Get( nWhichId )).GetValue();
353 double fPos(0.0), fNeg(0.0);
354 lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
356 if( bOldHasErrorBar &&
357 ! ( ::rtl::math::approxEqual( fPos, fValue ) &&
358 ::rtl::math::approxEqual( fNeg, fValue )))
360 xErrorBarProp->setPropertyValue( "PositiveError" , uno::makeAny( fValue ));
361 xErrorBarProp->setPropertyValue( "NegativeError" , uno::makeAny( fValue ));
362 bChanged = true;
365 break;
367 case SCHATTR_STAT_CONSTPLUS:
369 bool bYError =
370 static_cast<const SfxBoolItem&>(rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE)).GetValue();
372 uno::Reference< beans::XPropertySet > xErrorBarProp(
373 lcl_GetErrorBar( GetPropertySet(),bYError));
374 bool bOldHasErrorBar = xErrorBarProp.is();
376 double fValue =
377 static_cast< const SvxDoubleItem & >(
378 rItemSet.Get( nWhichId )).GetValue();
379 double fPos(0.0), fNeg(0.0);
380 lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
382 if( bOldHasErrorBar &&
383 ! ::rtl::math::approxEqual( fPos, fValue ))
385 xErrorBarProp->setPropertyValue( "PositiveError" , uno::makeAny( fValue ));
386 bChanged = true;
389 break;
391 case SCHATTR_STAT_CONSTMINUS:
393 bool bYError =
394 static_cast<const SfxBoolItem&>(rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE)).GetValue();
395 uno::Reference< beans::XPropertySet > xErrorBarProp(
396 lcl_GetErrorBar( GetPropertySet(),bYError));
397 bool bOldHasErrorBar = xErrorBarProp.is();
399 double fValue =
400 static_cast< const SvxDoubleItem & >(
401 rItemSet.Get( nWhichId )).GetValue();
402 double fPos(0.0), fNeg(0.0);
403 lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
405 if( bOldHasErrorBar &&
406 ! ::rtl::math::approxEqual( fNeg, fValue ))
408 xErrorBarProp->setPropertyValue( "NegativeError" , uno::makeAny( fValue ));
409 bChanged = true;
412 break;
414 case SCHATTR_REGRESSION_TYPE:
416 SvxChartRegress eRegress =
417 static_cast< const SvxChartRegressItem& >(
418 rItemSet.Get( nWhichId )).GetValue();
420 uno::Reference< chart2::XRegressionCurve > xCurve( GetPropertySet(), uno::UNO_QUERY );
421 uno::Reference< chart2::XRegressionCurveContainer > xContainer( GetPropertySet(), uno::UNO_QUERY );
423 if( eRegress == CHREGRESS_NONE )
425 if ( xContainer.is() )
427 xContainer->removeRegressionCurve( xCurve );
428 bChanged = true;
431 else
433 if ( xCurve.is() )
435 SvxChartRegress eOldRegress(
436 RegressionCurveHelper::getRegressionType(xCurve));
438 if( eOldRegress != eRegress )
440 xCurve = RegressionCurveHelper::changeRegressionCurveType(
441 eRegress,
442 xContainer,
443 xCurve,
444 uno::Reference< uno::XComponentContext >());
445 uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
446 resetPropertySet( xProperties );
447 bChanged = true;
452 break;
454 case SCHATTR_REGRESSION_DEGREE:
456 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
457 bChanged = lclConvertToPropertySet<sal_Int32, SfxInt32Item>(rItemSet, nWhichId, xProperties, "PolynomialDegree");
459 break;
461 case SCHATTR_REGRESSION_PERIOD:
463 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
464 bChanged = lclConvertToPropertySet<sal_Int32, SfxInt32Item>(rItemSet, nWhichId, xProperties, "MovingAveragePeriod");
466 break;
468 case SCHATTR_REGRESSION_EXTRAPOLATE_FORWARD:
470 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
471 bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties, "ExtrapolateForward");
473 break;
475 case SCHATTR_REGRESSION_EXTRAPOLATE_BACKWARD:
477 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
478 bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties, "ExtrapolateBackward");
480 break;
482 case SCHATTR_REGRESSION_SET_INTERCEPT:
484 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
485 bChanged = lclConvertToPropertySet<sal_Bool, SfxBoolItem>(rItemSet, nWhichId, xProperties, "ForceIntercept");
487 break;
489 case SCHATTR_REGRESSION_INTERCEPT_VALUE:
491 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
492 bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties, "InterceptValue");
494 break;
496 case SCHATTR_REGRESSION_CURVE_NAME:
498 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
499 bChanged = lclConvertToPropertySet<OUString, SfxStringItem>(rItemSet, nWhichId, xProperties, "CurveName");
501 break;
503 case SCHATTR_REGRESSION_SHOW_EQUATION:
505 uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), &rItemSet ));
506 bChanged = lclConvertToPropertySet<sal_Bool, SfxBoolItem>(rItemSet, nWhichId, xEqProp, "ShowEquation");
508 break;
510 case SCHATTR_REGRESSION_SHOW_COEFF:
512 uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), &rItemSet ));
513 bChanged = lclConvertToPropertySet<sal_Bool, SfxBoolItem>(rItemSet, nWhichId, xEqProp, "ShowCorrelationCoefficient");
515 break;
517 case SCHATTR_STAT_INDICATE:
519 bool bYError =
520 static_cast<const SfxBoolItem&>(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 == CHINDICATE_BOTH || eIndicate == CHINDICATE_UP );
530 bool bNewIndNeg = (eIndicate == CHINDICATE_BOTH || eIndicate == CHINDICATE_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::makeAny( bNewIndPos ));
540 xErrorBarProp->setPropertyValue( "ShowNegativeError" , uno::makeAny( bNewIndNeg ));
541 bChanged = true;
544 break;
546 case SCHATTR_STAT_RANGE_POS:
547 case SCHATTR_STAT_RANGE_NEG:
549 const bool bYError =
550 static_cast<const SfxBoolItem&>(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
607 throw( uno::Exception )
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 static_cast<const SfxBoolItem&>(rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE)).GetValue();
623 SvxChartKindError eErrorKind = CHERROR_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 ::com::sun::star::chart::ErrorBarStyle::NONE:
634 break;
635 case ::com::sun::star::chart::ErrorBarStyle::VARIANCE:
636 eErrorKind = CHERROR_VARIANT; break;
637 case ::com::sun::star::chart::ErrorBarStyle::STANDARD_DEVIATION:
638 eErrorKind = CHERROR_SIGMA; break;
639 case ::com::sun::star::chart::ErrorBarStyle::ABSOLUTE:
640 eErrorKind = CHERROR_CONST; break;
641 case ::com::sun::star::chart::ErrorBarStyle::RELATIVE:
642 eErrorKind = CHERROR_PERCENT; break;
643 case ::com::sun::star::chart::ErrorBarStyle::ERROR_MARGIN:
644 eErrorKind = CHERROR_BIGERROR; break;
645 case ::com::sun::star::chart::ErrorBarStyle::STANDARD_ERROR:
646 eErrorKind = CHERROR_STDERROR; break;
647 case ::com::sun::star::chart::ErrorBarStyle::FROM_DATA:
648 eErrorKind = CHERROR_RANGE; break;
652 rOutItemSet.Put( SvxChartKindErrorItem( eErrorKind, SCHATTR_STAT_KIND_ERROR ));
654 break;
656 case SCHATTR_STAT_PERCENT:
658 bool bYError =
659 static_cast<const SfxBoolItem&>(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, nWhichId ));
668 break;
670 case SCHATTR_STAT_BIGERROR:
672 bool bYError =
673 static_cast<const SfxBoolItem&>(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, nWhichId ));
682 break;
684 case SCHATTR_STAT_CONSTPLUS:
686 bool bYError =
687 static_cast<const SfxBoolItem&>(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, nWhichId ));
696 break;
698 case SCHATTR_STAT_CONSTMINUS:
700 bool bYError =
701 static_cast<const SfxBoolItem&>(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, nWhichId ));
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(), 0 ));
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(), 0 ));
733 lclConvertToItemSet<sal_Int32, SfxInt32Item>(rOutItemSet, nWhichId, xProperties, "MovingAveragePeriod");
735 break;
737 case SCHATTR_REGRESSION_EXTRAPOLATE_FORWARD:
739 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), 0 ));
740 lclConvertToItemSetDouble(rOutItemSet, nWhichId, xProperties, "ExtrapolateForward");
742 break;
744 case SCHATTR_REGRESSION_EXTRAPOLATE_BACKWARD:
746 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), 0 ));
747 lclConvertToItemSetDouble(rOutItemSet, nWhichId, xProperties, "ExtrapolateBackward");
749 break;
751 case SCHATTR_REGRESSION_SET_INTERCEPT:
753 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), 0 ));
754 lclConvertToItemSet<sal_Bool, SfxBoolItem>(rOutItemSet, nWhichId, xProperties, "ForceIntercept");
756 break;
758 case SCHATTR_REGRESSION_INTERCEPT_VALUE:
760 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), 0 ));
761 lclConvertToItemSetDouble(rOutItemSet, nWhichId, xProperties, "InterceptValue");
763 break;
765 case SCHATTR_REGRESSION_CURVE_NAME:
767 uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), 0 ));
768 lclConvertToItemSet<OUString, SfxStringItem>(rOutItemSet, nWhichId, xProperties, "CurveName");
770 break;
772 case SCHATTR_REGRESSION_SHOW_EQUATION:
774 uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), 0 ));
775 lclConvertToItemSet<sal_Bool, SfxBoolItem>(rOutItemSet, nWhichId, xEqProp, "ShowEquation");
777 break;
779 case SCHATTR_REGRESSION_SHOW_COEFF:
781 uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), 0 ));
782 lclConvertToItemSet<sal_Bool, SfxBoolItem>(rOutItemSet, nWhichId, xEqProp, "ShowCorrelationCoefficient");
784 break;
786 case SCHATTR_STAT_INDICATE:
788 bool bYError =
789 static_cast<const SfxBoolItem&>(rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE)).GetValue();
790 uno::Reference< beans::XPropertySet > xErrorBarProp( lcl_GetErrorBar( GetPropertySet(),bYError));
791 SvxChartIndicate eIndicate = CHINDICATE_BOTH;
792 if( xErrorBarProp.is())
794 bool bShowPos(false), bShowNeg(false);
795 lcl_getErrorIndicatorValues( xErrorBarProp, bShowPos, bShowNeg );
797 if( bShowPos )
799 if( bShowNeg )
800 eIndicate = CHINDICATE_BOTH;
801 else
802 eIndicate = CHINDICATE_UP;
804 else
806 if( bShowNeg )
807 eIndicate = CHINDICATE_DOWN;
808 else
809 eIndicate = CHINDICATE_NONE;
812 rOutItemSet.Put( SvxChartIndicateItem( eIndicate, SCHATTR_STAT_INDICATE ));
814 break;
816 case SCHATTR_STAT_RANGE_POS:
817 case SCHATTR_STAT_RANGE_NEG:
819 bool bYError =
820 static_cast<const SfxBoolItem&>(rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE)).GetValue();
821 uno::Reference< chart2::data::XDataSource > xErrorBarSource( lcl_GetErrorBar( GetPropertySet(),bYError),
822 uno::UNO_QUERY );
823 if( xErrorBarSource.is())
825 uno::Reference< chart2::data::XDataSequence > xSeq(
826 StatisticsHelper::getErrorDataSequenceFromDataSource(
827 xErrorBarSource, (nWhichId == SCHATTR_STAT_RANGE_POS), bYError ));
828 if( xSeq.is())
829 rOutItemSet.Put( SfxStringItem( nWhichId, xSeq->getSourceRangeRepresentation()));
832 break;
836 } // namespace wrapper
837 } // namespace chart
839 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */