27#include <unonames.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>
45uno::Reference< beans::XPropertySet > lcl_GetErrorBar(
46 const uno::Reference< beans::XPropertySet > & xProp,
bool bYError )
48 uno::Reference< beans::XPropertySet > xResult;
55 catch(
const uno::Exception & )
63uno::Reference< beans::XPropertySet > lcl_GetDefaultErrorBar()
65 return uno::Reference< beans::XPropertySet >( new ::chart::ErrorBar );
68void lcl_getErrorValues(
const uno::Reference< beans::XPropertySet > & xErrorBarProp,
69 double & rOutPosError,
double & rOutNegError )
71 if( ! xErrorBarProp.is())
76 xErrorBarProp->getPropertyValue(
"PositiveError" ) >>= rOutPosError;
77 xErrorBarProp->getPropertyValue(
"NegativeError" ) >>= rOutNegError;
79 catch(
const uno::Exception & )
85void lcl_getErrorIndicatorValues(
86 const uno::Reference< beans::XPropertySet > & xErrorBarProp,
87 bool & rOutShowPosError,
bool & rOutShowNegError )
89 if( ! xErrorBarProp.is())
94 xErrorBarProp->getPropertyValue(
"ShowPositiveError" ) >>= rOutShowPosError;
95 xErrorBarProp->getPropertyValue(
"ShowNegativeError" ) >>= rOutShowNegError;
97 catch(
const uno::Exception & )
103uno::Reference< beans::XPropertySet > lcl_getEquationProperties(
104 const uno::Reference< beans::XPropertySet > & xSeriesPropSet,
const SfxItemSet * pItemSet )
106 bool bEquationExists =
true;
114 bEquationExists = ( eRegress != SvxChartRegress::NONE );
118 if( bEquationExists )
120 uno::Reference< chart2::XRegressionCurveContainer > xRegCnt( xSeriesPropSet, uno::UNO_QUERY );
125 return xCurve->getEquationProperties();
129 return uno::Reference< beans::XPropertySet >();
132uno::Reference< beans::XPropertySet > lcl_getCurveProperties(
133 const uno::Reference< beans::XPropertySet > & xSeriesPropSet,
const SfxItemSet * pItemSet )
143 bExists = ( eRegress != SvxChartRegress::NONE );
149 uno::Reference< chart2::XRegressionCurveContainer > xRegCnt( xSeriesPropSet, uno::UNO_QUERY );
150 uno::Reference< chart2::XRegressionCurve > xCurve(
154 uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
159 return uno::Reference< beans::XPropertySet >();
162template <
class T,
class D>
163bool 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 ));
180template <
class T,
class D>
181void 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 ));
196 OSL_ASSERT(xProperties.is());
197 if( xProperties.is() )
199 double aValue = rItemSet.
Get( nWhichId ).GetValue();
200 if(xProperties->getPropertyValue( aPropertyID ) >>= aValue)
239 sal_uInt16 nWhichId,
const SfxItemSet & rItemSet )
241 bool bChanged =
false;
251 bool bNewHasMeanValueLine =
254 if( bOldHasMeanValueLine != bNewHasMeanValueLine )
256 if( ! bNewHasMeanValueLine )
280 if( !xErrorBarProp.is() && eErrorKind == SvxChartKindError::NONE)
286 sal_Int32 nStyle = css::chart::ErrorBarStyle::NONE;
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();
315 xErrorBarProp->setPropertyValue(
"ErrorBarStyle" ,
uno::Any( nStyle ));
324 OSL_FAIL(
"Deprecated item" );
330 bool bOldHasErrorBar = xErrorBarProp.is();
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 ));
356 bool bOldHasErrorBar = xErrorBarProp.is();
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 ));
379 bool bOldHasErrorBar = xErrorBarProp.is();
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 ));
405 if( eRegress == SvxChartRegress::NONE )
407 if ( xContainer.is() )
409 xContainer->removeRegressionCurve( xCurve );
420 if( eOldRegress != eRegress )
438 bChanged = lclConvertToPropertySet<sal_Int32, SfxInt32Item>(rItemSet, nWhichId, xProperties,
"PolynomialDegree");
445 bChanged = lclConvertToPropertySet<sal_Int32, SfxInt32Item>(rItemSet, nWhichId, xProperties,
"MovingAveragePeriod");
452 bChanged = lclConvertToPropertySet<sal_Int32, SfxInt32Item>(rItemSet, nWhichId, xProperties,
"MovingAverageType");
459 bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties,
"ExtrapolateForward");
466 bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties,
"ExtrapolateBackward");
473 bChanged = lclConvertToPropertySet<bool, SfxBoolItem>(rItemSet, nWhichId, xProperties,
"ForceIntercept");
480 bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties,
"InterceptValue");
487 bChanged = lclConvertToPropertySet<OUString, SfxStringItem>(rItemSet, nWhichId, xProperties,
"CurveName");
494 bChanged = lclConvertToPropertySet<bool, SfxBoolItem>(rItemSet, nWhichId, xEqProp,
"ShowEquation");
501 bChanged = lclConvertToPropertySet<OUString, SfxStringItem>(rItemSet, nWhichId, xEqProp,
"XName");
508 bChanged = lclConvertToPropertySet<OUString, SfxStringItem>(rItemSet, nWhichId, xEqProp,
"YName");
515 bChanged = lclConvertToPropertySet<bool, SfxBoolItem>(rItemSet, nWhichId, xEqProp,
"ShowCorrelationCoefficient");
525 bool bOldHasErrorBar = xErrorBarProp.is();
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 ));
558 xDataProvider.set(
m_xModel->getDataProvider());
559 if( xErrorBarSource.is() && xDataProvider.is())
562 bool bApplyNewRange =
false;
565 if(
m_xModel->hasInternalDataProvider())
567 if( !aNewRange.isEmpty())
571 xErrorBarSource, bIsPositiveValue, bYError ));
576 OSL_ASSERT( xIntDataProvider.is());
577 if( xIntDataProvider.is())
579 xIntDataProvider->appendSequence();
581 bApplyNewRange =
true;
590 xErrorBarSource, bIsPositiveValue, bYError ));
592 ! ( xSeq.is() && (aNewRange == xSeq->getSourceRangeRepresentation()));
597 xErrorBarSource, xDataProvider, aNewRange, bIsPositiveValue, bYError );
607 sal_uInt16 nWhichId,
SfxItemSet & rOutItemSet )
const
626 if( xErrorBarProp.is() )
628 sal_Int32 nStyle = 0;
629 if( xErrorBarProp->getPropertyValue(
"ErrorBarStyle" ) >>= nStyle )
633 case css::chart::ErrorBarStyle::NONE:
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;
661 if( xErrorBarProp.is())
663 double fPos(0.0), fNeg(0.0);
664 lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
675 if( xErrorBarProp.is())
677 double fPos(0.0), fNeg(0.0);
678 lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
689 if( xErrorBarProp.is())
691 double fPos(0.0), fNeg(0.0);
692 lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
703 if( xErrorBarProp.is())
705 double fPos(0.0), fNeg(0.0);
706 lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
726 lclConvertToItemSet<sal_Int32, SfxInt32Item>(rOutItemSet, nWhichId, xProperties,
"PolynomialDegree");
733 lclConvertToItemSet<sal_Int32, SfxInt32Item>(rOutItemSet, nWhichId, xProperties,
"MovingAveragePeriod");
740 lclConvertToItemSet<sal_Int32, SfxInt32Item>(rOutItemSet, nWhichId, xProperties,
"MovingAverageType");
761 lclConvertToItemSet<bool, SfxBoolItem>(rOutItemSet, nWhichId, xProperties,
"ForceIntercept");
775 lclConvertToItemSet<OUString, SfxStringItem>(rOutItemSet, nWhichId, xProperties,
"CurveName");
782 lclConvertToItemSet<bool, SfxBoolItem>(rOutItemSet, nWhichId, xEqProp,
"ShowEquation");
789 lclConvertToItemSet<OUString, SfxStringItem>(rOutItemSet, nWhichId, xEqProp,
"XName");
796 lclConvertToItemSet<OUString, SfxStringItem>(rOutItemSet, nWhichId, xEqProp,
"YName");
803 lclConvertToItemSet<bool, SfxBoolItem>(rOutItemSet, nWhichId, xEqProp,
"ShowCorrelationCoefficient");
813 if( xErrorBarProp.is())
815 bool bShowPos(
false), bShowNeg(
false);
816 lcl_getErrorIndicatorValues( xErrorBarProp, bShowPos, bShowNeg );
821 eIndicate = SvxChartIndicate::Both;
823 eIndicate = SvxChartIndicate::Up;
828 eIndicate = SvxChartIndicate::Down;
830 eIndicate = SvxChartIndicate::NONE;
844 if( xErrorBarSource.is())
850 rOutItemSet.
Put(
SfxStringItem( nWhichId, xSeq->getSourceRangeRepresentation()));
constexpr TypedWhichId< SfxStringItem > SCHATTR_STAT_RANGE_POS(SCHATTR_STAT_START+7)
constexpr TypedWhichId< SvxChartRegressItem > SCHATTR_REGRESSION_TYPE(SCHATTR_REGRESSION_START)
constexpr TypedWhichId< SvxDoubleItem > SCHATTR_REGRESSION_EXTRAPOLATE_FORWARD(SCHATTR_REGRESSION_START+5)
constexpr TypedWhichId< SfxBoolItem > SCHATTR_REGRESSION_SHOW_EQUATION(SCHATTR_REGRESSION_START+1)
constexpr TypedWhichId< SvxChartIndicateItem > SCHATTR_STAT_INDICATE(SCHATTR_STAT_START+6)
constexpr TypedWhichId< SfxBoolItem > SCHATTR_REGRESSION_SET_INTERCEPT(SCHATTR_REGRESSION_START+7)
constexpr TypedWhichId< SfxBoolItem > SCHATTR_STAT_ERRORBAR_TYPE(SCHATTR_STAT_START+9)
constexpr TypedWhichId< SvxDoubleItem > SCHATTR_STAT_BIGERROR(SCHATTR_STAT_START+3)
constexpr TypedWhichId< SfxInt32Item > SCHATTR_REGRESSION_MOVING_TYPE(SCHATTR_REGRESSION_START+12)
constexpr TypedWhichId< SfxStringItem > SCHATTR_REGRESSION_CURVE_NAME(SCHATTR_REGRESSION_START+9)
constexpr TypedWhichId< SfxStringItem > SCHATTR_REGRESSION_YNAME(SCHATTR_REGRESSION_START+11)
constexpr TypedWhichId< SvxChartKindErrorItem > SCHATTR_STAT_KIND_ERROR(SCHATTR_STAT_START+1)
constexpr TypedWhichId< SfxInt32Item > SCHATTR_REGRESSION_DEGREE(SCHATTR_REGRESSION_START+3)
constexpr TypedWhichId< SfxBoolItem > SCHATTR_REGRESSION_SHOW_COEFF(SCHATTR_REGRESSION_START+2)
constexpr TypedWhichId< SvxDoubleItem > SCHATTR_REGRESSION_EXTRAPOLATE_BACKWARD(SCHATTR_REGRESSION_START+6)
constexpr TypedWhichId< SfxStringItem > SCHATTR_STAT_RANGE_NEG(SCHATTR_STAT_START+8)
constexpr TypedWhichId< SfxBoolItem > SCHATTR_STAT_AVERAGE(SCHATTR_STAT_START)
constexpr TypedWhichId< SfxStringItem > SCHATTR_REGRESSION_XNAME(SCHATTR_REGRESSION_START+10)
constexpr TypedWhichId< SvxDoubleItem > SCHATTR_STAT_CONSTPLUS(SCHATTR_STAT_START+4)
constexpr TypedWhichId< SvxDoubleItem > SCHATTR_REGRESSION_INTERCEPT_VALUE(SCHATTR_REGRESSION_START+8)
constexpr TypedWhichId< SvxDoubleItem > SCHATTR_STAT_CONSTMINUS(SCHATTR_STAT_START+5)
constexpr TypedWhichId< SvxDoubleItem > SCHATTR_STAT_PERCENT(SCHATTR_STAT_START+2)
constexpr TypedWhichId< SfxInt32Item > SCHATTR_REGRESSION_PERIOD(SCHATTR_REGRESSION_START+4)
const WhichRangesContainer nStatWhichPairs(svl::Items< SCHATTR_STAT_START, SCHATTR_STAT_END, SCHATTR_REGRESSION_START, SCHATTR_REGRESSION_END >)
const OUString & GetValue() const
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
This class serves for conversion between properties of an XPropertySet and SfxItems in SfxItemSets.
void resetPropertySet(const css::uno::Reference< css::beans::XPropertySet > &xPropSet)
sets a new property set, that you get with GetPropertySet().
std::pair< tPropertyNameType, tMemberIdType > tPropertyNameWithMemberId
const css::uno::Reference< css::beans::XPropertySet > & GetPropertySet() const
Returns the XPropertySet that was given in the CTOR and is used to apply items in ApplyItemSet().
virtual bool GetItemProperty(tWhichIdType nWhichId, tPropertyNameWithMemberId &rOutProperty) const override
implement this method to return a Property object for a given which id.
rtl::Reference<::chart::ChartModel > m_xModel
StatisticsItemConverter(rtl::Reference<::chart::ChartModel > xChartModel, const css::uno::Reference< css::beans::XPropertySet > &rPropertySet, SfxItemPool &rItemPool)
virtual const WhichRangesContainer & GetWhichPairs() const override
implement this method to provide an array of which-ranges
virtual bool ApplySpecialItem(sal_uInt16 nWhichId, const SfxItemSet &rItemSet) override
for items that can not be mapped directly to a property.
virtual void FillSpecialItem(sal_uInt16 nWhichId, SfxItemSet &rOutItemSet) const override
for items that can not be mapped directly to a property.
virtual ~StatisticsItemConverter() override
#define DBG_UNHANDLED_EXCEPTION(...)
Reference< frame::XModel > m_xModel
OOO_DLLPUBLIC_CHARTTOOLS SvxChartRegress getFirstRegressTypeNotMeanValueLine(const css::uno::Reference< css::chart2::XRegressionCurveContainer > &xCurveContainer)
Returns the type of the first regression curve found that is not of type mean-value line.
OOO_DLLPUBLIC_CHARTTOOLS rtl::Reference<::chart::RegressionCurveModel > getFirstCurveNotMeanValueLine(const css::uno::Reference< css::chart2::XRegressionCurveContainer > &xCurveContainer)
Returns the first regression curve found that is not of type mean-value line.
OOO_DLLPUBLIC_CHARTTOOLS bool hasMeanValueLine(const css::uno::Reference< css::chart2::XRegressionCurveContainer > &xRegCnt)
OOO_DLLPUBLIC_CHARTTOOLS rtl::Reference<::chart::RegressionCurveModel > changeRegressionCurveType(SvxChartRegress eType, css::uno::Reference< css::chart2::XRegressionCurveContainer > const &xRegressionCurveContainer, css::uno::Reference< css::chart2::XRegressionCurve > const &xRegressionCurve)
OOO_DLLPUBLIC_CHARTTOOLS void removeMeanValueLine(css::uno::Reference< css::chart2::XRegressionCurveContainer > const &xRegCnt)
OOO_DLLPUBLIC_CHARTTOOLS SvxChartRegress getRegressionType(const css::uno::Reference< css::chart2::XRegressionCurve > &xCurve)
OOO_DLLPUBLIC_CHARTTOOLS void addMeanValueLine(css::uno::Reference< css::chart2::XRegressionCurveContainer > const &xRegCnt, const css::uno::Reference< css::beans::XPropertySet > &xSeriesProp)
creates a mean-value line and adds it to the container.
OOO_DLLPUBLIC_CHARTTOOLS css::uno::Reference< css::chart2::data::XDataSequence > getErrorDataSequenceFromDataSource(const css::uno::Reference< css::chart2::data::XDataSource > &xDataSource, bool bPositiveValue, bool bYError=true)
OOO_DLLPUBLIC_CHARTTOOLS void setErrorDataSequence(const css::uno::Reference< css::chart2::data::XDataSource > &xDataSource, const css::uno::Reference< css::chart2::data::XDataProvider > &xDataProvider, const OUString &rNewRange, bool bPositiveValue, bool bYError=true, OUString const *pXMLRange=nullptr)
Reference< XModel > xModel
constexpr OUStringLiteral CHART_UNONAME_ERRORBAR_Y
constexpr OUStringLiteral CHART_UNONAME_ERRORBAR_X