diff options
author | Laurent Balland <laurent.balland@mailo.fr> | 2023-06-18 19:25:39 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2023-06-27 07:48:34 +0200 |
commit | aa86e7e8c22527eb5da0b8a05dbd4bd749f7a2b8 (patch) | |
tree | 7b44b6dd9c95ff049ce7ff0216b84416a943259a /chart2 | |
parent | 191814f47afd2dd6340e1da4499ca794d6dff268 (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>
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 9e03e495827d..98468a138c3f 100644 --- a/chart2/source/controller/main/ControllerCommandDispatch.cxx +++ b/chart2/source/controller/main/ControllerCommandDispatch.cxx @@ -283,23 +283,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; } } @@ -674,8 +679,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 9f1b935c0d01..f9d919506460 100644 --- a/chart2/source/inc/RegressionCurveHelper.hxx +++ b/chart2/source/inc/RegressionCurveHelper.hxx @@ -195,6 +195,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 8d9ba75962e9..65e6b13ac0a0 100644 --- a/chart2/source/tools/RegressionCurveHelper.cxx +++ b/chart2/source/tools/RegressionCurveHelper.cxx @@ -898,6 +898,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 23d3a4d9ac05..5c1082e89a74 100644 --- a/chart2/source/tools/RegressionCurveModel.cxx +++ b/chart2/source/tools/RegressionCurveModel.cxx @@ -183,6 +183,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 |