chart2/source/controller/main/ControllerCommandDispatch.cxx |   13 ++++++++---
 chart2/source/inc/RegressionCurveHelper.hxx                 |    1 
 chart2/source/tools/RegressionCurveHelper.cxx               |   14 ++++++++++++
 chart2/source/tools/RegressionCurveModel.cxx                |    1 
 chart2/source/tools/RegressionEquation.cxx                  |    8 ++++++
 5 files changed, 34 insertions(+), 3 deletions(-)

New commits:
commit 439e2fb0ccc8fc75fb9239a7370db9dd56ee9c55
Author:     Laurent Balland <laurent.ball...@mailo.fr>
AuthorDate: Sun Jun 18 19:25:39 2023 +0200
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Thu Jun 29 09:41:56 2023 +0200

    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 <qui...@gmail.com>
    (cherry picked from commit aa86e7e8c22527eb5da0b8a05dbd4bd749f7a2b8)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153700

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 0bed3ca19e16..ef4c2091b4c2 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

Reply via email to