diff options
Diffstat (limited to 'chart2/source/controller/dialogs/res_Trendline.cxx')
-rw-r--r-- | chart2/source/controller/dialogs/res_Trendline.cxx | 90 |
1 files changed, 60 insertions, 30 deletions
diff --git a/chart2/source/controller/dialogs/res_Trendline.cxx b/chart2/source/controller/dialogs/res_Trendline.cxx index 11514a19a84a..3cbba1e59a28 100644 --- a/chart2/source/controller/dialogs/res_Trendline.cxx +++ b/chart2/source/controller/dialogs/res_Trendline.cxx @@ -21,12 +21,16 @@ #include <bitmaps.hlst> #include <chartview/ChartSfxItemIds.hxx> +#include <com/sun/star/chart2/MovingAverageType.hpp> + #include <svl/intitem.hxx> +#include <svl/numformat.hxx> #include <svl/stritem.hxx> -#include <svl/zforlist.hxx> #include <vcl/formatter.hxx> #include <vcl/weld.hxx> +using namespace css::chart2; + namespace chart { @@ -65,6 +69,7 @@ TrendlineResources::TrendlineResources(weld::Builder& rBuilder, const SfxItemSet , m_xEE_XName(rBuilder.weld_entry("entry_Xname")) , m_xEE_YName(rBuilder.weld_entry("entry_Yname")) , m_xCB_ShowCorrelationCoeff(rBuilder.weld_check_button("showCorrelationCoefficient")) + , m_xCB_RegressionMovingType(rBuilder.weld_combo_box("combo_moving_type")) { FillValueSets(); @@ -78,7 +83,7 @@ TrendlineResources::TrendlineResources(weld::Builder& rBuilder, const SfxItemSet rInterceptFormatter.ClearMinValue(); rInterceptFormatter.ClearMaxValue(); - Link<weld::ToggleButton&,void> aLink = LINK(this, TrendlineResources, SelectTrendLine); + Link<weld::Toggleable&,void> aLink = LINK(this, TrendlineResources, SelectTrendLine); m_xRB_Linear->connect_toggled( aLink ); m_xRB_Logarithmic->connect_toggled( aLink ); m_xRB_Exponential->connect_toggled( aLink ); @@ -100,7 +105,7 @@ TrendlineResources::TrendlineResources(weld::Builder& rBuilder, const SfxItemSet TrendlineResources::~TrendlineResources() {} -IMPL_LINK_NOARG(TrendlineResources, SelectTrendLine, weld::ToggleButton&, void) +IMPL_LINK_NOARG(TrendlineResources, SelectTrendLine, weld::Toggleable&, void) { if (m_xRB_Linear->get_active()) m_eTrendLineType = SvxChartRegress::Linear; @@ -121,29 +126,27 @@ IMPL_LINK_NOARG(TrendlineResources, SelectTrendLine, weld::ToggleButton&, void) void TrendlineResources::Reset( const SfxItemSet& rInAttrs ) { - const SfxPoolItem *pPoolItem = nullptr; - - if( rInAttrs.GetItemState( SCHATTR_REGRESSION_CURVE_NAME, true, &pPoolItem ) == SfxItemState::SET ) + if( const SfxStringItem* pCurveNameItem = rInAttrs.GetItemIfSet( SCHATTR_REGRESSION_CURVE_NAME ) ) { - OUString aName = static_cast< const SfxStringItem* >(pPoolItem)->GetValue(); + OUString aName = pCurveNameItem->GetValue(); m_xEE_Name->set_text(aName); } else { m_xEE_Name->set_text(""); } - if( rInAttrs.GetItemState( SCHATTR_REGRESSION_XNAME, true, &pPoolItem ) == SfxItemState::SET ) + if( const SfxStringItem* pRegressionXNameItem = rInAttrs.GetItemIfSet( SCHATTR_REGRESSION_XNAME ) ) { - OUString aName = static_cast< const SfxStringItem* >(pPoolItem)->GetValue(); + OUString aName = pRegressionXNameItem->GetValue(); m_xEE_XName->set_text(aName); } else { m_xEE_XName->set_text("x"); } - if( rInAttrs.GetItemState( SCHATTR_REGRESSION_YNAME, true, &pPoolItem ) == SfxItemState::SET ) + if( const SfxStringItem* pRegressionYNameItem = rInAttrs.GetItemIfSet( SCHATTR_REGRESSION_YNAME ) ) { - OUString aName = static_cast< const SfxStringItem* >(pPoolItem)->GetValue(); + OUString aName = pRegressionYNameItem->GetValue(); m_xEE_YName->set_text(aName); } else @@ -151,8 +154,9 @@ void TrendlineResources::Reset( const SfxItemSet& rInAttrs ) m_xEE_YName->set_text("f(x)"); } + const SfxPoolItem* pPoolItem = nullptr; SfxItemState aState = rInAttrs.GetItemState( SCHATTR_REGRESSION_TYPE, true, &pPoolItem ); - m_bTrendLineUnique = ( aState != SfxItemState::DONTCARE ); + m_bTrendLineUnique = ( aState != SfxItemState::INVALID ); if( aState == SfxItemState::SET ) { const SvxChartRegressItem * pItem = dynamic_cast< const SvxChartRegressItem * >( pPoolItem ); @@ -162,9 +166,9 @@ void TrendlineResources::Reset( const SfxItemSet& rInAttrs ) } } - if( rInAttrs.GetItemState( SCHATTR_REGRESSION_DEGREE, true, &pPoolItem ) == SfxItemState::SET ) + if( const SfxInt32Item* pDegreeItem = rInAttrs.GetItemIfSet( SCHATTR_REGRESSION_DEGREE ) ) { - sal_Int32 nDegree = static_cast< const SfxInt32Item * >( pPoolItem )->GetValue(); + sal_Int32 nDegree = pDegreeItem->GetValue(); m_xNF_Degree->set_value( nDegree ); } else @@ -174,9 +178,9 @@ void TrendlineResources::Reset( const SfxItemSet& rInAttrs ) m_xNF_Degree->save_value(); - if( rInAttrs.GetItemState( SCHATTR_REGRESSION_PERIOD, true, &pPoolItem ) == SfxItemState::SET ) + if( const SfxInt32Item* pPeriodItem = rInAttrs.GetItemIfSet( SCHATTR_REGRESSION_PERIOD ) ) { - sal_Int32 nPeriod = static_cast< const SfxInt32Item * >( pPoolItem )->GetValue(); + sal_Int32 nPeriod = pPeriodItem->GetValue(); m_xNF_Period->set_value( nPeriod ); } else @@ -187,28 +191,28 @@ void TrendlineResources::Reset( const SfxItemSet& rInAttrs ) m_xNF_Period->save_value(); double nValue = 0.0; - if( rInAttrs.GetItemState( SCHATTR_REGRESSION_EXTRAPOLATE_FORWARD, true, &pPoolItem ) == SfxItemState::SET ) + if( const SvxDoubleItem* pForwardItem = rInAttrs.GetItemIfSet( SCHATTR_REGRESSION_EXTRAPOLATE_FORWARD ) ) { - nValue = static_cast<const SvxDoubleItem*>(pPoolItem)->GetValue() ; + nValue = pForwardItem->GetValue() ; } lcl_setValue(*m_xFmtFld_ExtrapolateForward, nValue); nValue = 0.0; - if( rInAttrs.GetItemState( SCHATTR_REGRESSION_EXTRAPOLATE_BACKWARD, true, &pPoolItem ) == SfxItemState::SET ) + if( const SvxDoubleItem* pBackwardItem = rInAttrs.GetItemIfSet( SCHATTR_REGRESSION_EXTRAPOLATE_BACKWARD ) ) { - nValue = static_cast<const SvxDoubleItem*>(pPoolItem)->GetValue() ; + nValue = pBackwardItem->GetValue() ; } lcl_setValue(*m_xFmtFld_ExtrapolateBackward, nValue); nValue = 0.0; - if( rInAttrs.GetItemState( SCHATTR_REGRESSION_INTERCEPT_VALUE, true, &pPoolItem ) == SfxItemState::SET ) + if( const SvxDoubleItem* pValueItem = rInAttrs.GetItemIfSet( SCHATTR_REGRESSION_INTERCEPT_VALUE ) ) { - nValue = static_cast<const SvxDoubleItem*>(pPoolItem)->GetValue() ; + nValue = pValueItem->GetValue() ; } lcl_setValue(*m_xFmtFld_InterceptValue, nValue); aState = rInAttrs.GetItemState( SCHATTR_REGRESSION_SET_INTERCEPT, true, &pPoolItem ); - if( aState == SfxItemState::DONTCARE ) + if( aState == SfxItemState::INVALID ) { m_xCB_SetIntercept->set_state(TRISTATE_INDET); } @@ -219,7 +223,7 @@ void TrendlineResources::Reset( const SfxItemSet& rInAttrs ) } aState = rInAttrs.GetItemState( SCHATTR_REGRESSION_SHOW_EQUATION, true, &pPoolItem ); - if( aState == SfxItemState::DONTCARE ) + if( aState == SfxItemState::INVALID ) { m_xCB_ShowEquation->set_state(TRISTATE_INDET); } @@ -230,7 +234,7 @@ void TrendlineResources::Reset( const SfxItemSet& rInAttrs ) } aState = rInAttrs.GetItemState( SCHATTR_REGRESSION_SHOW_COEFF, true, &pPoolItem ); - if( aState == SfxItemState::DONTCARE ) + if( aState == SfxItemState::INVALID ) { m_xCB_ShowCorrelationCoeff->set_state(TRISTATE_INDET); } @@ -240,6 +244,21 @@ void TrendlineResources::Reset( const SfxItemSet& rInAttrs ) m_xCB_ShowCorrelationCoeff->set_active( static_cast< const SfxBoolItem * >( pPoolItem )->GetValue()); } + if( const SfxInt32Item* pMovingTypeItem = rInAttrs.GetItemIfSet( SCHATTR_REGRESSION_MOVING_TYPE ) ) + { + sal_Int32 nMovingType = pMovingTypeItem->GetValue(); + if (nMovingType == MovingAverageType::Prior) + m_xCB_RegressionMovingType->set_active(0); + else if (nMovingType == MovingAverageType::Central) + m_xCB_RegressionMovingType->set_active(1); + else if (nMovingType == MovingAverageType::AveragedAbscissa) + m_xCB_RegressionMovingType->set_active(2); + } + else + { + m_xCB_RegressionMovingType->set_active(0); + } + if( !m_bTrendLineUnique ) return; @@ -273,6 +292,17 @@ void TrendlineResources::FillItemSet(SfxItemSet* rOutAttrs) const if( m_bTrendLineUnique ) rOutAttrs->Put( SvxChartRegressItem( m_eTrendLineType, SCHATTR_REGRESSION_TYPE )); + if (m_eTrendLineType == SvxChartRegress::MovingAverage) + { + sal_Int32 nType = MovingAverageType::Prior; + if (m_xCB_RegressionMovingType->get_active() == 1) + nType = MovingAverageType::Central; + else if (m_xCB_RegressionMovingType->get_active() == 2) + nType = MovingAverageType::AveragedAbscissa; + + rOutAttrs->Put(SfxInt32Item(SCHATTR_REGRESSION_MOVING_TYPE, nType)); + } + if( m_xCB_ShowEquation->get_state() != TRISTATE_INDET ) rOutAttrs->Put( SfxBoolItem( SCHATTR_REGRESSION_SHOW_EQUATION, m_xCB_ShowEquation->get_active() )); @@ -332,6 +362,7 @@ void TrendlineResources::UpdateControlStates() m_xNF_Period->set_max(m_nNbPoints - 1); } bool bMovingAverage = ( m_eTrendLineType == SvxChartRegress::MovingAverage ); + bool bPolynomial = ( m_eTrendLineType == SvxChartRegress::Polynomial ); bool bInterceptAvailable = ( m_eTrendLineType == SvxChartRegress::Linear ) || ( m_eTrendLineType == SvxChartRegress::Polynomial ) || ( m_eTrendLineType == SvxChartRegress::Exp ); @@ -341,11 +372,12 @@ void TrendlineResources::UpdateControlStates() m_xFmtFld_InterceptValue->set_sensitive( bInterceptAvailable ); if( bMovingAverage ) { - m_xCB_ShowEquation->set_state(TRISTATE_FALSE); m_xCB_ShowCorrelationCoeff->set_state(TRISTATE_FALSE); } - m_xCB_ShowEquation->set_sensitive( !bMovingAverage ); m_xCB_ShowCorrelationCoeff->set_sensitive( !bMovingAverage ); + m_xCB_RegressionMovingType->set_sensitive(bMovingAverage); + m_xNF_Period->set_sensitive(bMovingAverage); + m_xNF_Degree->set_sensitive(bPolynomial); m_xEE_XName->set_sensitive( !bMovingAverage && m_xCB_ShowEquation->get_active() ); m_xEE_YName->set_sensitive( !bMovingAverage && m_xCB_ShowEquation->get_active() ); } @@ -392,10 +424,8 @@ void TrendlineResources::SetNbPoints( sal_Int32 nNbPoints ) UpdateControlStates(); } -IMPL_LINK_NOARG(TrendlineResources, ShowEquation, weld::ToggleButton&, void) +IMPL_LINK_NOARG(TrendlineResources, ShowEquation, weld::Toggleable&, void) { - m_xEE_XName->set_sensitive(m_xCB_ShowEquation->get_active()); - m_xEE_YName->set_sensitive(m_xCB_ShowEquation->get_active()); UpdateControlStates(); } |