diff options
author | Laurent Balland <laurent.balland@mailo.fr> | 2023-06-18 19:25:39 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2023-07-05 03:19:43 +0200 |
commit | 47d3f102add9a46216e9082efdff362eb8555ad3 (patch) | |
tree | 0a0a38abb4c31ce5f1d5d05ae0b430d2b1c7bc8e /chart2 | |
parent | ef155fcf7bb78a2788f66cad3d6008b9203f5a32 (diff) |
tdf#155526 Moving average: remove Insert R2
Moving average trend line does not R² value.
This change remove "Insert R²" from context menu when the trend is of
type "Moving average"
Change-Id: I729a6421df34859e7176c798a2b68a6f13cfb544
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153294
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
(cherry picked from commit aa86e7e8c22527eb5da0b8a05dbd4bd749f7a2b8)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153838
Diffstat (limited to 'chart2')
-rw-r--r-- | chart2/source/controller/main/ControllerCommandDispatch.cxx | 13 | ||||
-rw-r--r-- | chart2/source/inc/RegressionCurveHelper.hxx | 1 | ||||
-rw-r--r-- | chart2/source/tools/RegressionCurveHelper.cxx | 14 | ||||
-rw-r--r-- | chart2/source/tools/RegressionCurveModel.cxx | 1 | ||||
-rw-r--r-- | chart2/source/tools/RegressionEquation.cxx | 8 |
5 files changed, 34 insertions, 3 deletions
diff --git a/chart2/source/controller/main/ControllerCommandDispatch.cxx b/chart2/source/controller/main/ControllerCommandDispatch.cxx index 620082bd99d8..ba659fd00449 100644 --- a/chart2/source/controller/main/ControllerCommandDispatch.cxx +++ b/chart2/source/controller/main/ControllerCommandDispatch.cxx @@ -285,23 +285,28 @@ void ControllerState::update( // Trendline Equation bMayFormatTrendlineEquation = bMayDeleteTrendlineEquation = RegressionCurveHelper::hasEquation( xRegCurve ); bMayAddTrendlineEquation = !bMayDeleteTrendlineEquation; + bMayAddR2Value = RegressionCurveHelper::MayHaveCorrelationCoefficient( xRegCurve ) && bMayAddTrendlineEquation; } else if( aObjectType == OBJECTTYPE_DATA_CURVE_EQUATION ) { bMayFormatTrendlineEquation = true; bool bHasR2Value = false; + bool bMayHaveR2 = true; try { uno::Reference< beans::XPropertySet > xEquationProperties = ObjectIdentifier::getObjectPropertySet( aSelObjCID, xModel ); if( xEquationProperties.is() ) + { xEquationProperties->getPropertyValue( "ShowCorrelationCoefficient" ) >>= bHasR2Value; + xEquationProperties->getPropertyValue( "MayHaveCorrelationCoefficient" ) >>= bMayHaveR2; + } } catch(const uno::RuntimeException&) { TOOLS_WARN_EXCEPTION("chart2", "" ); } - bMayAddR2Value = !bHasR2Value; + bMayAddR2Value = !bHasR2Value && bMayHaveR2; bMayDeleteR2Value = bHasR2Value; } } @@ -672,8 +677,10 @@ void ControllerCommandDispatch::updateCommandAvailability() m_aCommandAvailability[ ".uno:InsertMeanValue" ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayAddMeanValue; m_aCommandAvailability[ ".uno:InsertTrendline" ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayAddTrendline; m_aCommandAvailability[ ".uno:InsertTrendlineEquation" ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayAddTrendlineEquation; - m_aCommandAvailability[ ".uno:InsertTrendlineEquationAndR2" ] = m_aCommandAvailability[ ".uno:InsertTrendlineEquation" ]; - m_aCommandAvailability[ ".uno:InsertR2Value" ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayAddR2Value; + m_aCommandAvailability[ ".uno:InsertTrendlineEquationAndR2" ] = + m_aCommandAvailability[ ".uno:InsertTrendlineEquation" ] && m_apControllerState->bMayAddR2Value; + m_aCommandAvailability[ ".uno:InsertR2Value" ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayAddR2Value + && !m_apControllerState->bMayAddTrendlineEquation; m_aCommandAvailability[ ".uno:DeleteR2Value" ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayDeleteR2Value; m_aCommandAvailability[ ".uno:InsertXErrorBars" ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayAddXErrorBars; diff --git a/chart2/source/inc/RegressionCurveHelper.hxx b/chart2/source/inc/RegressionCurveHelper.hxx index 2666b41d9bb9..e2df1bb4cd4d 100644 --- a/chart2/source/inc/RegressionCurveHelper.hxx +++ b/chart2/source/inc/RegressionCurveHelper.hxx @@ -199,6 +199,7 @@ namespace chart::RegressionCurveHelper const rtl::Reference<::chart::RegressionCurveModel>& xCurve ); OOO_DLLPUBLIC_CHARTTOOLS bool hasEquation(const css::uno::Reference<css::chart2::XRegressionCurve>& xCurve ); + OOO_DLLPUBLIC_CHARTTOOLS bool MayHaveCorrelationCoefficient(const css::uno::Reference<css::chart2::XRegressionCurve>& xCurve ); } // namespace chart diff --git a/chart2/source/tools/RegressionCurveHelper.cxx b/chart2/source/tools/RegressionCurveHelper.cxx index 2ff161bf0cf7..9626b07c1fbd 100644 --- a/chart2/source/tools/RegressionCurveHelper.cxx +++ b/chart2/source/tools/RegressionCurveHelper.cxx @@ -915,6 +915,20 @@ bool RegressionCurveHelper::hasEquation( const Reference< chart2::XRegressionCur return bHasEquation; } +bool RegressionCurveHelper::MayHaveCorrelationCoefficient( const Reference< chart2::XRegressionCurve > & xCurve ) +{ + bool bMayHaveCorrelationCoefficient = true; + if( xCurve.is()) + { + uno::Reference< beans::XPropertySet > xEquationProp( xCurve->getEquationProperties() ); + if( xEquationProp.is() ) + { + xEquationProp->getPropertyValue( "MayHaveCorrelationCoefficient") >>= bMayHaveCorrelationCoefficient; + } + } + return bMayHaveCorrelationCoefficient; +} + } //namespace chart /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/tools/RegressionCurveModel.cxx b/chart2/source/tools/RegressionCurveModel.cxx index d4e8d3839b95..d64d053e2611 100644 --- a/chart2/source/tools/RegressionCurveModel.cxx +++ b/chart2/source/tools/RegressionCurveModel.cxx @@ -182,6 +182,7 @@ void SAL_CALL RegressionCurveModel::setEquationProperties( const uno::Reference< ModifyListenerHelper::removeListener( m_xEquationProperties, m_xModifyEventForwarder ); m_xEquationProperties.set( xEquationProperties ); + m_xEquationProperties->setPropertyValue( "MayHaveCorrelationCoefficient", uno::Any( m_eRegressionCurveType != CURVE_TYPE_MOVING_AVERAGE ) ); ModifyListenerHelper::addListener( m_xEquationProperties, m_xModifyEventForwarder ); fireModifyEvent(); } diff --git a/chart2/source/tools/RegressionEquation.cxx b/chart2/source/tools/RegressionEquation.cxx index 4805355aeb60..34bbd6b491d9 100644 --- a/chart2/source/tools/RegressionEquation.cxx +++ b/chart2/source/tools/RegressionEquation.cxx @@ -53,6 +53,7 @@ enum PROP_EQUATION_XNAME, PROP_EQUATION_YNAME, PROP_EQUATION_SHOW_CORRELATION_COEFF, + PROP_EQUATION_MAY_HAVE_CORRELATION_COEFF, PROP_EQUATION_REF_PAGE_SIZE, PROP_EQUATION_REL_POS, PROP_EQUATION_NUMBER_FORMAT @@ -85,6 +86,12 @@ void lcl_AddPropertiesToVector( beans::PropertyAttribute::BOUND | beans::PropertyAttribute::MAYBEDEFAULT ); + rOutProperties.emplace_back( "MayHaveCorrelationCoefficient", + PROP_EQUATION_MAY_HAVE_CORRELATION_COEFF, + cppu::UnoType<bool>::get(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT ); + rOutProperties.emplace_back( "ReferencePageSize", PROP_EQUATION_REF_PAGE_SIZE, cppu::UnoType<awt::Size>::get(), @@ -117,6 +124,7 @@ void lcl_AddPropertiesToVector( ::chart::PropertyHelper::setPropertyValueDefault( aOutMap, PROP_EQUATION_XNAME, OUString("x") ); ::chart::PropertyHelper::setPropertyValueDefault( aOutMap, PROP_EQUATION_YNAME, OUString("f(x)") ); ::chart::PropertyHelper::setPropertyValueDefault( aOutMap, PROP_EQUATION_SHOW_CORRELATION_COEFF, false ); + ::chart::PropertyHelper::setPropertyValueDefault( aOutMap, PROP_EQUATION_MAY_HAVE_CORRELATION_COEFF, true ); //::chart::PropertyHelper::setPropertyValueDefault( aOutMap, PROP_EQUATION_SEPARATOR, OUString( '\n' )); // override other defaults |