[Libreoffice-commits] core.git: 2 commits - chart2/source chart2/uiconfig include/xmloff offapi/com xmloff/source

Laurent Balland-Poirier laurent.balland-poirier at laposte.net
Tue Aug 16 20:55:21 UTC 2016


 chart2/source/controller/dialogs/ObjectNameProvider.cxx                  |   10 +
 chart2/source/controller/dialogs/res_Trendline.cxx                       |   42 +++++++
 chart2/source/controller/dialogs/res_Trendline.hxx                       |   23 ++-
 chart2/source/controller/itemsetwrapper/RegressionCurveItemConverter.cxx |   26 ++++
 chart2/source/controller/itemsetwrapper/StatisticsItemConverter.cxx      |   28 ++++
 chart2/source/controller/main/ChartController_Insert.cxx                 |    2 
 chart2/source/controller/main/ChartController_Tools.cxx                  |    2 
 chart2/source/inc/RegressionCurveCalculator.hxx                          |    5 
 chart2/source/inc/chartview/ChartSfxItemIds.hxx                          |    4 
 chart2/source/tools/ExponentialRegressionCurveCalculator.cxx             |    6 -
 chart2/source/tools/LogarithmicRegressionCurveCalculator.cxx             |    8 -
 chart2/source/tools/MeanValueRegressionCurveCalculator.cxx               |    2 
 chart2/source/tools/PolynomialRegressionCurveCalculator.cxx              |    8 -
 chart2/source/tools/PotentialRegressionCurveCalculator.cxx               |    6 -
 chart2/source/tools/RegressionCurveCalculator.cxx                        |   16 ++
 chart2/source/tools/RegressionCurveHelper.cxx                            |    2 
 chart2/source/tools/RegressionEquation.cxx                               |   18 +++
 chart2/source/view/charttypes/VSeriesPlotter.cxx                         |    9 +
 chart2/source/view/main/ChartItemPool.cxx                                |    2 
 chart2/uiconfig/ui/tp_Trendline.ui                                       |   58 ++++++++++
 include/xmloff/xmltoken.hxx                                              |    2 
 offapi/com/sun/star/chart2/RegressionCurveEquation.idl                   |    2 
 offapi/com/sun/star/chart2/XRegressionCurveCalculator.idl                |    8 +
 xmloff/source/chart/PropertyMap.hxx                                      |    2 
 xmloff/source/core/xmltoken.cxx                                          |    2 
 25 files changed, 266 insertions(+), 27 deletions(-)

New commits:
commit aa21f8acfa4d4997688ef4ddc04fcf95987e3424
Author: Laurent Balland-Poirier <laurent.balland-poirier at laposte.net>
Date:   Fri Jul 15 09:57:42 2016 +0200

    tdf#100547 Save to ODF XY customized names
    
    Trendline equation: Following change 27069
    https://gerrit.libreoffice.org/27069
    Save customized names of X and Y variables in extended ODF
    
    Change-Id: Ie39487866f7671f4468a37f48847038fbd2cec2a
    Reviewed-on: https://gerrit.libreoffice.org/27233
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Laurent BP <laurent.balland-poirier at laposte.net>

diff --git a/include/xmloff/xmltoken.hxx b/include/xmloff/xmltoken.hxx
index 0a56591..1698737 100644
--- a/include/xmloff/xmltoken.hxx
+++ b/include/xmloff/xmltoken.hxx
@@ -2193,6 +2193,8 @@ namespace xmloff { namespace token {
         XML_REGRESSION_PERIOD,
         XML_REGRESSION_FORCE_INTERCEPT,
         XML_REGRESSION_INTERCEPT_VALUE,
+        XML_REGRESSION_X_NAME,
+        XML_REGRESSION_Y_NAME,
 
         XML_ERROR_INDICATOR,
 
diff --git a/xmloff/source/chart/PropertyMap.hxx b/xmloff/source/chart/PropertyMap.hxx
index e9f2634..fc919ea 100644
--- a/xmloff/source/chart/PropertyMap.hxx
+++ b/xmloff/source/chart/PropertyMap.hxx
@@ -217,6 +217,8 @@ const XMLPropertyMapEntry aXMLChartPropMap[] =
     MAP_ENTRY_ODF_EXT( "ExtrapolateBackward", LO_EXT, XML_REGRESSION_EXTRAPOLATE_BACKWARD, XML_TYPE_DOUBLE ),
     MAP_ENTRY_ODF_EXT( "ForceIntercept", LO_EXT, XML_REGRESSION_FORCE_INTERCEPT, XML_TYPE_BOOL ),
     MAP_ENTRY_ODF_EXT( "InterceptValue", LO_EXT, XML_REGRESSION_INTERCEPT_VALUE, XML_TYPE_DOUBLE ),
+    MAP_ENTRY_ODF_EXT( "XName", LO_EXT, XML_REGRESSION_X_NAME, XML_TYPE_STRING ),
+    MAP_ENTRY_ODF_EXT( "YName", LO_EXT, XML_REGRESSION_Y_NAME, XML_TYPE_STRING ),
 
     // import mapping for broken files
     MAP_ENTRY_ODF_EXT_IMPORT( "CurveName", CHART, XML_REGRESSION_CURVE_NAME, XML_TYPE_STRING ),
diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx
index f6924bb..ed6e22d 100644
--- a/xmloff/source/core/xmltoken.cxx
+++ b/xmloff/source/core/xmltoken.cxx
@@ -2201,6 +2201,8 @@ namespace xmloff { namespace token {
         TOKEN( "regression-period",               XML_REGRESSION_PERIOD ),
         TOKEN( "regression-force-intercept",      XML_REGRESSION_FORCE_INTERCEPT ),
         TOKEN( "regression-intercept-value",      XML_REGRESSION_INTERCEPT_VALUE ),
+        TOKEN( "regression-x-name",               XML_REGRESSION_X_NAME ),
+        TOKEN( "regression-y-name",               XML_REGRESSION_Y_NAME ),
 
         TOKEN( "error-indicator",                 XML_ERROR_INDICATOR ),
 
commit 428711f03c31802e339e57384b9f925a0e4dcc12
Author: Laurent Balland-Poirier <laurent.balland-poirier at laposte.net>
Date:   Tue Jun 28 23:34:34 2016 +0200

    Start tdf#100547 Trendline equation: customize X, Y names
    
    Change trend line UI to add fields: X name and Y name
    to change "x" and "f(x)" in equation representation
    
    Next to be done: save it to ODF file
    
    Change-Id: I0680ee1bbfbbb74016ecc858917e10d6790ac63a
    Reviewed-on: https://gerrit.libreoffice.org/27069
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Laurent BP <laurent.balland-poirier at laposte.net>

diff --git a/chart2/source/controller/dialogs/ObjectNameProvider.cxx b/chart2/source/controller/dialogs/ObjectNameProvider.cxx
index 3eccea9..6e112ae 100644
--- a/chart2/source/controller/dialogs/ObjectNameProvider.cxx
+++ b/chart2/source/controller/dialogs/ObjectNameProvider.cxx
@@ -565,6 +565,7 @@ OUString ObjectNameProvider::getHelpText( const OUString& rObjectCID, const Refe
                         sal_Int32 aPeriod = 2;
                         bool bForceIntercept = false;
                         double aInterceptValue = 0.0;
+                        OUString aXName ("x"), aYName ("f(x)");
                         const LocaleDataWrapper& rLocaleDataWrapper = Application::GetSettings().GetLocaleDataWrapper();
                         const OUString& aNumDecimalSep = rLocaleDataWrapper.getNumDecimalSep();
                         assert(aNumDecimalSep.getLength() > 0);
@@ -578,8 +579,17 @@ OUString ObjectNameProvider::getHelpText( const OUString& rObjectCID, const Refe
                                 xProperties->getPropertyValue( "ForceIntercept") >>= bForceIntercept;
                                 if (bForceIntercept)
                                         xProperties->getPropertyValue( "InterceptValue") >>= aInterceptValue;
+                                uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties());
+                                if( xEqProp.is())
+                                {
+                                    if ( !(xEqProp->getPropertyValue( "XName") >>= aXName) )
+                                        aXName = "x";
+                                    if ( !(xEqProp->getPropertyValue( "YName") >>= aYName) )
+                                        aYName = "f(x)";
+                                }
                         }
                         xCalculator->setRegressionProperties(aDegree, bForceIntercept, aInterceptValue, 2);
+                        xCalculator->setXYNames ( aXName, aYName );
                         RegressionCurveHelper::initializeCurveCalculator( xCalculator, xSeries, xChartModel );
 
                         // change text for Moving Average
diff --git a/chart2/source/controller/dialogs/res_Trendline.cxx b/chart2/source/controller/dialogs/res_Trendline.cxx
index 2ce1262..dbd77e6 100644
--- a/chart2/source/controller/dialogs/res_Trendline.cxx
+++ b/chart2/source/controller/dialogs/res_Trendline.cxx
@@ -60,6 +60,8 @@ TrendlineResources::TrendlineResources( vcl::Window * pParent, const SfxItemSet&
     pTabPage->get(m_pCB_SetIntercept,"setIntercept");
     pTabPage->get(m_pFmtFld_InterceptValue,"interceptValue");
     pTabPage->get(m_pCB_ShowEquation,"showEquation");
+    pTabPage->get(m_pEE_XName,"entry_Xname");
+    pTabPage->get(m_pEE_YName,"entry_Yname");
     pTabPage->get(m_pCB_ShowCorrelationCoeff,"showCorrelationCoefficient");
     pTabPage->get(m_pFI_Linear,"imageLinear");
     pTabPage->get(m_pFI_Logarithmic,"imageLogarithmic");
@@ -82,6 +84,8 @@ TrendlineResources::TrendlineResources( vcl::Window * pParent, const SfxItemSet&
     m_pNF_Period->SetModifyHdl( aLink2 );
     m_pFmtFld_InterceptValue->SetModifyHdl( aLink2 );
 
+    m_pCB_ShowEquation->SetToggleHdl( LINK(this, TrendlineResources, ShowEquation ) );
+
     Reset( rInAttrs );
     UpdateControlStates();
 }
@@ -121,6 +125,24 @@ void TrendlineResources::Reset( const SfxItemSet& rInAttrs )
     {
         m_pEE_Name->SetText("");
     }
+    if( rInAttrs.GetItemState( SCHATTR_REGRESSION_XNAME, true, &pPoolItem ) == SfxItemState::SET )
+    {
+        OUString aName = static_cast< const SfxStringItem* >(pPoolItem)->GetValue();
+        m_pEE_XName->SetText(aName);
+    }
+    else
+    {
+        m_pEE_XName->SetText("x");
+    }
+    if( rInAttrs.GetItemState( SCHATTR_REGRESSION_YNAME, true, &pPoolItem ) == SfxItemState::SET )
+    {
+        OUString aName = static_cast< const SfxStringItem* >(pPoolItem)->GetValue();
+        m_pEE_YName->SetText(aName);
+    }
+    else
+    {
+        m_pEE_YName->SetText("f(x)");
+    }
 
     SfxItemState aState = rInAttrs.GetItemState( SCHATTR_REGRESSION_TYPE, true, &pPoolItem );
     m_bTrendLineUnique = ( aState != SfxItemState::DONTCARE );
@@ -254,6 +276,14 @@ bool TrendlineResources::FillItemSet(SfxItemSet* rOutAttrs) const
 
     OUString aName = m_pEE_Name->GetText();
     rOutAttrs->Put(SfxStringItem(SCHATTR_REGRESSION_CURVE_NAME, aName));
+    aName = m_pEE_XName->GetText();
+    if ( aName.isEmpty() )
+        aName = "x";
+    rOutAttrs->Put(SfxStringItem(SCHATTR_REGRESSION_XNAME, aName));
+    aName = m_pEE_YName->GetText();
+    if ( aName.isEmpty() )
+        aName = "f(x)";
+    rOutAttrs->Put(SfxStringItem(SCHATTR_REGRESSION_YNAME, aName));
 
     sal_Int32 aDegree = m_pNF_Degree->GetValue();
     rOutAttrs->Put(SfxInt32Item( SCHATTR_REGRESSION_DEGREE, aDegree ) );
@@ -314,6 +344,8 @@ void TrendlineResources::UpdateControlStates()
     }
     m_pCB_ShowEquation->Enable( !bMovingAverage );
     m_pCB_ShowCorrelationCoeff->Enable( !bMovingAverage );
+    m_pEE_XName->Enable( !bMovingAverage && m_pCB_ShowEquation->IsChecked() );
+    m_pEE_YName->Enable( !bMovingAverage && m_pCB_ShowEquation->IsChecked() );
 }
 
 IMPL_LINK_TYPED( TrendlineResources, ChangeValue, Edit&, rNumericField, void)
@@ -356,6 +388,16 @@ void TrendlineResources::SetNbPoints( sal_Int32 nNbPoints )
     UpdateControlStates();
 }
 
+IMPL_LINK_TYPED( TrendlineResources, ShowEquation, CheckBox&, rCheckBox, void)
+{
+    if( &rCheckBox == m_pCB_ShowEquation )
+    {
+        m_pEE_XName->Enable( m_pCB_ShowEquation->IsChecked() );
+        m_pEE_YName->Enable( m_pCB_ShowEquation->IsChecked() );
+    }
+    UpdateControlStates();
+}
+
 } //  namespace chart
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/chart2/source/controller/dialogs/res_Trendline.hxx b/chart2/source/controller/dialogs/res_Trendline.hxx
index 9fe50e6..69ca98e 100644
--- a/chart2/source/controller/dialogs/res_Trendline.hxx
+++ b/chart2/source/controller/dialogs/res_Trendline.hxx
@@ -60,15 +60,17 @@ private:
     VclPtr<FixedImage>  m_pFI_Polynomial;
     VclPtr<FixedImage>  m_pFI_MovingAverage;
 
-    VclPtr<NumericField> m_pNF_Degree;
-    VclPtr<NumericField> m_pNF_Period;
-    VclPtr<Edit>         m_pEE_Name;
-    VclPtr<FormattedField> m_pFmtFld_ExtrapolateForward;
-    VclPtr<FormattedField> m_pFmtFld_ExtrapolateBackward;
-    VclPtr<CheckBox>     m_pCB_SetIntercept;
-    VclPtr<FormattedField> m_pFmtFld_InterceptValue;
-    VclPtr<CheckBox>     m_pCB_ShowEquation;
-    VclPtr<CheckBox>     m_pCB_ShowCorrelationCoeff;
+    VclPtr<NumericField>    m_pNF_Degree;
+    VclPtr<NumericField>    m_pNF_Period;
+    VclPtr<Edit>            m_pEE_Name;
+    VclPtr<FormattedField>  m_pFmtFld_ExtrapolateForward;
+    VclPtr<FormattedField>  m_pFmtFld_ExtrapolateBackward;
+    VclPtr<CheckBox>        m_pCB_SetIntercept;
+    VclPtr<FormattedField>  m_pFmtFld_InterceptValue;
+    VclPtr<CheckBox>        m_pCB_ShowEquation;
+    VclPtr<Edit>            m_pEE_XName;
+    VclPtr<Edit>            m_pEE_YName;
+    VclPtr<CheckBox>        m_pCB_ShowCorrelationCoeff;
 
     SvxChartRegress     m_eTrendLineType;
 
@@ -78,8 +80,9 @@ private:
     sal_Int32           m_nNbPoints;
 
     void UpdateControlStates();
-    DECL_LINK_TYPED( SelectTrendLine, Button *, void );
+    DECL_LINK_TYPED( SelectTrendLine, Button*, void );
     DECL_LINK_TYPED( ChangeValue, Edit&, void);
+    DECL_LINK_TYPED( ShowEquation, CheckBox&, void);
 };
 
 } //  namespace chart
diff --git a/chart2/source/controller/itemsetwrapper/RegressionCurveItemConverter.cxx b/chart2/source/controller/itemsetwrapper/RegressionCurveItemConverter.cxx
index 0e66927..e4ac942 100644
--- a/chart2/source/controller/itemsetwrapper/RegressionCurveItemConverter.cxx
+++ b/chart2/source/controller/itemsetwrapper/RegressionCurveItemConverter.cxx
@@ -230,6 +230,20 @@ bool RegressionCurveItemConverter::ApplySpecialItem(
         }
         break;
 
+        case SCHATTR_REGRESSION_XNAME:
+        {
+            uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties());
+            bChanged = lclConvertToPropertySet<OUString, SfxStringItem>(rItemSet, nWhichId, xEqProp, "XName");
+        }
+        break;
+
+        case SCHATTR_REGRESSION_YNAME:
+        {
+            uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties());
+            bChanged = lclConvertToPropertySet<OUString, SfxStringItem>(rItemSet, nWhichId, xEqProp, "YName");
+        }
+        break;
+
         case SCHATTR_REGRESSION_SHOW_COEFF:
         {
             uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties());
@@ -308,6 +322,18 @@ void RegressionCurveItemConverter::FillSpecialItem(sal_uInt16 nWhichId, SfxItemS
         }
         break;
 
+        case SCHATTR_REGRESSION_XNAME:
+        {
+            lclConvertToItemSet<OUString, SfxStringItem>(rOutItemSet, nWhichId, xCurve->getEquationProperties(), "XName");
+        }
+        break;
+
+        case SCHATTR_REGRESSION_YNAME:
+        {
+            lclConvertToItemSet<OUString, SfxStringItem>(rOutItemSet, nWhichId, xCurve->getEquationProperties(), "YName");
+        }
+        break;
+
         case SCHATTR_REGRESSION_SHOW_COEFF:
         {
             lclConvertToItemSet<bool, SfxBoolItem>(rOutItemSet, nWhichId, xCurve->getEquationProperties(), "ShowCorrelationCoefficient");
diff --git a/chart2/source/controller/itemsetwrapper/StatisticsItemConverter.cxx b/chart2/source/controller/itemsetwrapper/StatisticsItemConverter.cxx
index 9e1f0cc..b99d19a 100644
--- a/chart2/source/controller/itemsetwrapper/StatisticsItemConverter.cxx
+++ b/chart2/source/controller/itemsetwrapper/StatisticsItemConverter.cxx
@@ -507,6 +507,20 @@ bool StatisticsItemConverter::ApplySpecialItem(
         }
         break;
 
+        case SCHATTR_REGRESSION_XNAME:
+        {
+            uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), &rItemSet ));
+            bChanged = lclConvertToPropertySet<OUString, SfxStringItem>(rItemSet, nWhichId, xEqProp, "XName");
+        }
+        break;
+
+        case SCHATTR_REGRESSION_YNAME:
+        {
+            uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), &rItemSet ));
+            bChanged = lclConvertToPropertySet<OUString, SfxStringItem>(rItemSet, nWhichId, xEqProp, "YName");
+        }
+        break;
+
         case SCHATTR_REGRESSION_SHOW_COEFF:
         {
             uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), &rItemSet ));
@@ -776,6 +790,20 @@ void StatisticsItemConverter::FillSpecialItem(
         }
         break;
 
+        case SCHATTR_REGRESSION_XNAME:
+        {
+            uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), nullptr ));
+            lclConvertToItemSet<OUString, SfxStringItem>(rOutItemSet, nWhichId, xEqProp, "XName");
+        }
+        break;
+
+        case SCHATTR_REGRESSION_YNAME:
+        {
+            uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), nullptr ));
+            lclConvertToItemSet<OUString, SfxStringItem>(rOutItemSet, nWhichId, xEqProp, "YName");
+        }
+        break;
+
         case SCHATTR_REGRESSION_SHOW_COEFF:
         {
             uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), nullptr ));
diff --git a/chart2/source/controller/main/ChartController_Insert.cxx b/chart2/source/controller/main/ChartController_Insert.cxx
index fd0cda1..38819c7 100644
--- a/chart2/source/controller/main/ChartController_Insert.cxx
+++ b/chart2/source/controller/main/ChartController_Insert.cxx
@@ -536,6 +536,8 @@ void ChartController::executeDispatch_InsertTrendlineEquation( bool bInsertR2 )
                     ActionDescriptionProvider::INSERT, SCH_RESSTR( STR_OBJECT_CURVE_EQUATION )),
                 m_xUndoManager );
             xEqProp->setPropertyValue( "ShowEquation", uno::makeAny( true ));
+            xEqProp->setPropertyValue( "XName", uno::makeAny( OUString("x") ));
+            xEqProp->setPropertyValue( "YName", uno::makeAny( OUString("f(x)") ));
             xEqProp->setPropertyValue( "ShowCorrelationCoefficient", uno::makeAny( bInsertR2 ));
             aUndoGuard.commit();
         }
diff --git a/chart2/source/controller/main/ChartController_Tools.cxx b/chart2/source/controller/main/ChartController_Tools.cxx
index 3cc97af..8eb20b5 100644
--- a/chart2/source/controller/main/ChartController_Tools.cxx
+++ b/chart2/source/controller/main/ChartController_Tools.cxx
@@ -709,6 +709,8 @@ bool ChartController::executeDispatch_Delete()
                     {
                         ControllerLockGuardUNO aCtlLockGuard( xModel );
                         xEqProp->setPropertyValue( "ShowEquation", uno::makeAny( false ));
+                        xEqProp->setPropertyValue( "XName", uno::makeAny( OUString("x") ));
+                        xEqProp->setPropertyValue( "YName", uno::makeAny( OUString("f(x)") ));
                         xEqProp->setPropertyValue( "ShowCorrelationCoefficient", uno::makeAny( false ));
                     }
                     bReturn = true;
diff --git a/chart2/source/inc/RegressionCurveCalculator.hxx b/chart2/source/inc/RegressionCurveCalculator.hxx
index 4f8e260..422c39b 100644
--- a/chart2/source/inc/RegressionCurveCalculator.hxx
+++ b/chart2/source/inc/RegressionCurveCalculator.hxx
@@ -60,6 +60,7 @@ protected:
     bool  mForceIntercept;
     double    mInterceptValue;
     sal_Int32 mPeriod;
+    OUString mXName, mYName;
 
     // ____ XRegressionCurveCalculator ____
     virtual void SAL_CALL setRegressionProperties(
@@ -98,6 +99,10 @@ protected:
         const css::uno::Reference< css::util::XNumberFormatsSupplier >& xNumFmtSupplier,
         sal_Int32 nNumberFormatKey, sal_Int32 nFormulaLength )
         throw (css::uno::RuntimeException, std::exception) override;
+
+    virtual void SAL_CALL setXYNames(
+        const OUString& aXName, const OUString& aYName )
+        throw (css::uno::RuntimeException, std::exception) override;
 };
 
 } //  namespace chart
diff --git a/chart2/source/inc/chartview/ChartSfxItemIds.hxx b/chart2/source/inc/chartview/ChartSfxItemIds.hxx
index 3bce731..d2b873c 100644
--- a/chart2/source/inc/chartview/ChartSfxItemIds.hxx
+++ b/chart2/source/inc/chartview/ChartSfxItemIds.hxx
@@ -169,7 +169,9 @@
 #define SCHATTR_REGRESSION_SET_INTERCEPT        (SCHATTR_REGRESSION_START + 7)
 #define SCHATTR_REGRESSION_INTERCEPT_VALUE      (SCHATTR_REGRESSION_START + 8)
 #define SCHATTR_REGRESSION_CURVE_NAME           (SCHATTR_REGRESSION_START + 9)
-#define SCHATTR_REGRESSION_END                   SCHATTR_REGRESSION_CURVE_NAME
+#define SCHATTR_REGRESSION_XNAME                (SCHATTR_REGRESSION_START + 10)
+#define SCHATTR_REGRESSION_YNAME                (SCHATTR_REGRESSION_START + 11)
+#define SCHATTR_REGRESSION_END                   SCHATTR_REGRESSION_YNAME
 
 #define SCHATTR_END                     SCHATTR_REGRESSION_END
 
diff --git a/chart2/source/tools/ExponentialRegressionCurveCalculator.cxx b/chart2/source/tools/ExponentialRegressionCurveCalculator.cxx
index f6a7571..9d3f105 100644
--- a/chart2/source/tools/ExponentialRegressionCurveCalculator.cxx
+++ b/chart2/source/tools/ExponentialRegressionCurveCalculator.cxx
@@ -162,12 +162,12 @@ OUString ExponentialRegressionCurveCalculator::ImplGetRepresentation(
     bool bHasLogSlope = !rtl::math::approxEqual( fabs(m_fLogSlope), 1.0 );
     bool bHasIntercept = !rtl::math::approxEqual( fIntercept, 1.0 ) && fIntercept != 0.0;
 
-    OUStringBuffer aBuf( "f(x) = " );
+    OUStringBuffer aBuf( mYName + " = " );
     sal_Int32 nLineLength = aBuf.getLength();
     sal_Int32 nValueLength=0;
     if ( pFormulaMaxWidth && *pFormulaMaxWidth > 0 )
     {          // count characters different from coefficients
-        sal_Int32 nCharMin = nLineLength + 11;  // 11 = "exp( ", " x )" + 2 extra characters
+        sal_Int32 nCharMin = nLineLength + 10 + mXName.getLength();  // 10 = "exp( ", " x )" + 2 extra characters
         if ( m_fSign < 0.0 )
             nCharMin += 2;
         if ( fIntercept == 0.0 || ( !bHasSlope && m_fLogIntercept != 0.0 ) )
@@ -219,7 +219,7 @@ OUString ExponentialRegressionCurveCalculator::ImplGetRepresentation(
             aTmpBuf.append( aValueString + " " );
         }
     }
-    aTmpBuf.append( "x )");
+    aTmpBuf.append( mXName + " )");
     addStringToEquation( aBuf, nLineLength, aTmpBuf, pFormulaMaxWidth );
 
     return aBuf.makeStringAndClear();
diff --git a/chart2/source/tools/LogarithmicRegressionCurveCalculator.cxx b/chart2/source/tools/LogarithmicRegressionCurveCalculator.cxx
index 97f0b85..b3d5e8f 100644
--- a/chart2/source/tools/LogarithmicRegressionCurveCalculator.cxx
+++ b/chart2/source/tools/LogarithmicRegressionCurveCalculator.cxx
@@ -134,12 +134,12 @@ OUString LogarithmicRegressionCurveCalculator::ImplGetRepresentation(
     sal_Int32 nNumberFormatKey, sal_Int32* pFormulaMaxWidth /* = nullptr */ ) const
 {
     bool bHasSlope = !rtl::math::approxEqual( fabs( m_fSlope ), 1.0 );
-    OUStringBuffer aBuf( "f(x) = " );
+    OUStringBuffer aBuf( mYName + " = " );
     sal_Int32 nLineLength = aBuf.getLength();
     sal_Int32 nValueLength=0;
     if ( pFormulaMaxWidth && *pFormulaMaxWidth > 0 ) // count nValueLength
     {
-        sal_Int32 nCharMin = nLineLength + 7;  // 7 = "ln(x)" + 2 extra characters
+        sal_Int32 nCharMin = nLineLength + 6 + mXName.getLength();  // 6 = "ln(x)" + 2 extra characters
         if( m_fSlope < 0.0 )
             nCharMin += 2;  // "- "
         if( m_fSlope != 0.0 && m_fIntercept != 0.0 )
@@ -172,7 +172,7 @@ OUString LogarithmicRegressionCurveCalculator::ImplGetRepresentation(
                 aTmpBuf.append( aValueString + " " );
             }
         }
-        aTmpBuf.append( "ln(x) " );
+        aTmpBuf.append( "ln(" + mXName + ") " );
         addStringToEquation( aBuf, nLineLength, aTmpBuf, pFormulaMaxWidth );
         aTmpBuf.truncate();
 
@@ -189,7 +189,7 @@ OUString LogarithmicRegressionCurveCalculator::ImplGetRepresentation(
         addStringToEquation( aBuf, nLineLength, aTmpBuf, pFormulaMaxWidth );
     }
 
-    if ( aBuf.toString() == "f(x) = " )
+    if ( aBuf.toString().equals( OUString(mYName + " = ") ) )
         aBuf.append( "0" );
 
     return aBuf.makeStringAndClear();
diff --git a/chart2/source/tools/MeanValueRegressionCurveCalculator.cxx b/chart2/source/tools/MeanValueRegressionCurveCalculator.cxx
index 4703fe4..3835a46 100644
--- a/chart2/source/tools/MeanValueRegressionCurveCalculator.cxx
+++ b/chart2/source/tools/MeanValueRegressionCurveCalculator.cxx
@@ -121,7 +121,7 @@ OUString MeanValueRegressionCurveCalculator::ImplGetRepresentation(
     const uno::Reference< util::XNumberFormatter >& xNumFormatter,
     sal_Int32 nNumberFormatKey, sal_Int32* pFormulaLength /* = nullptr */ ) const
 {
-    OUString aBuf = "f(x) = ";
+    OUString aBuf = OUString(mYName + " = ");
     if ( pFormulaLength )
     {
         *pFormulaLength -= aBuf.getLength();
diff --git a/chart2/source/tools/PolynomialRegressionCurveCalculator.cxx b/chart2/source/tools/PolynomialRegressionCurveCalculator.cxx
index 2134b4f..c4976a5 100644
--- a/chart2/source/tools/PolynomialRegressionCurveCalculator.cxx
+++ b/chart2/source/tools/PolynomialRegressionCurveCalculator.cxx
@@ -225,7 +225,7 @@ OUString PolynomialRegressionCurveCalculator::ImplGetRepresentation(
     const uno::Reference< util::XNumberFormatter >& xNumFormatter,
     sal_Int32 nNumberFormatKey, sal_Int32* pFormulaMaxWidth /* = nullptr */ ) const
 {
-    OUStringBuffer aBuf( "f(x) = " );
+    OUStringBuffer aBuf( mYName + " = " );
 
     sal_Int32 nValueLength=0;
     sal_Int32 aLastIndex = mCoefficients.size() - 1;
@@ -252,7 +252,7 @@ OUString PolynomialRegressionCurveCalculator::ImplGetRepresentation(
                 nCharMin += 3; // " + "
             if ( i > 0 )
             {
-                 nCharMin += 1; // "x"
+                 nCharMin += mXName.getLength(); // "x"
                 if ( i > 1 )
                     nCharMin +=1; // "^i"
                 if ( i >= 10 )
@@ -296,7 +296,7 @@ OUString PolynomialRegressionCurveCalculator::ImplGetRepresentation(
 
         if(i > 0)
         {
-            aTmpBuf.append( "x" );
+            aTmpBuf.append( mXName );
             if (i > 1)
             {
                 if (i < 10) // simple case if only one digit
@@ -314,7 +314,7 @@ OUString PolynomialRegressionCurveCalculator::ImplGetRepresentation(
         }
         addStringToEquation( aBuf, nLineLength, aTmpBuf, pFormulaMaxWidth );
     }
-    if ( aBuf.toString() == "f(x) = " )
+    if ( aBuf.toString().equals( OUString( mYName + " = ") ) )
         aBuf.append( "0" );
 
     return aBuf.makeStringAndClear();
diff --git a/chart2/source/tools/PotentialRegressionCurveCalculator.cxx b/chart2/source/tools/PotentialRegressionCurveCalculator.cxx
index 3282f2d..aea4e68 100644
--- a/chart2/source/tools/PotentialRegressionCurveCalculator.cxx
+++ b/chart2/source/tools/PotentialRegressionCurveCalculator.cxx
@@ -146,12 +146,12 @@ OUString PotentialRegressionCurveCalculator::ImplGetRepresentation(
     sal_Int32 nNumberFormatKey, sal_Int32* pFormulaMaxWidth /* = nullptr */ ) const
 {
     bool bHasIntercept = !rtl::math::approxEqual( fabs(m_fIntercept), 1.0 );
-    OUStringBuffer aBuf( "f(x) = ");
+    OUStringBuffer aBuf( mYName + " = " );
     sal_Int32 nLineLength = aBuf.getLength();
     sal_Int32 nValueLength=0;
     if ( pFormulaMaxWidth && *pFormulaMaxWidth > 0 ) // count nValueLength
     {
-        sal_Int32 nCharMin = nLineLength + 4;  // 4 = "x^" + 2 extra characters
+        sal_Int32 nCharMin = nLineLength + mXName.getLength() + 3;  // 3 = "^" + 2 extra characters
         if ( m_fIntercept != 0.0 && m_fSlope != 0.0 )
         {
             if ( m_fIntercept < 0.0 )
@@ -187,7 +187,7 @@ OUString PotentialRegressionCurveCalculator::ImplGetRepresentation(
         }
         if( m_fSlope != 0.0 )  // add slope value
         {
-            aTmpBuf.append( "x^" );
+            aTmpBuf.append( mXName + "^" );
             aTmpBuf.append( getFormattedString( xNumFormatter, nNumberFormatKey, m_fSlope, pValueLength ));
         }
         addStringToEquation( aBuf, nLineLength, aTmpBuf, pFormulaMaxWidth );
diff --git a/chart2/source/tools/RegressionCurveCalculator.cxx b/chart2/source/tools/RegressionCurveCalculator.cxx
index 09f03cc..429eeb0 100644
--- a/chart2/source/tools/RegressionCurveCalculator.cxx
+++ b/chart2/source/tools/RegressionCurveCalculator.cxx
@@ -45,7 +45,8 @@ RegressionCurveCalculator::RegressionCurveCalculator() :
         mDegree(2),
         mForceIntercept(false),
         mInterceptValue(0.0),
-        mPeriod(2)
+        mPeriod(2),
+        mXName("x"), mYName("f(x)")
 {
     rtl::math::setNan( &m_fCorrelationCoeffitient );
     rtl::math::setNan( &mInterceptValue );
@@ -211,6 +212,19 @@ void RegressionCurveCalculator::addStringToEquation(
     nLineLength += aAddString.getLength();
 }
 
+void SAL_CALL RegressionCurveCalculator::setXYNames( const OUString& aXName, const OUString& aYName )
+    throw (uno::RuntimeException, std::exception)
+{
+    if ( aXName.isEmpty() )
+        mXName = OUString ("x");
+    else
+        mXName = aXName;
+    if ( aYName.isEmpty() )
+        mYName = OUString ("f(x)");
+    else
+        mYName = aYName;
+}
+
 } //  namespace chart
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/chart2/source/tools/RegressionCurveHelper.cxx b/chart2/source/tools/RegressionCurveHelper.cxx
index 4681a7c..4cc6d69 100644
--- a/chart2/source/tools/RegressionCurveHelper.cxx
+++ b/chart2/source/tools/RegressionCurveHelper.cxx
@@ -456,6 +456,8 @@ void RegressionCurveHelper::removeEquations(
                         if( xEqProp.is())
                         {
                             xEqProp->setPropertyValue( "ShowEquation", uno::makeAny( false ));
+                            xEqProp->setPropertyValue( "XName", uno::makeAny( OUString("x") ));
+                            xEqProp->setPropertyValue( "YName", uno::makeAny( OUString("f(x) ") ));
                             xEqProp->setPropertyValue( "ShowCorrelationCoefficient", uno::makeAny( false ));
                         }
                     }
diff --git a/chart2/source/tools/RegressionEquation.cxx b/chart2/source/tools/RegressionEquation.cxx
index a544fe2..692576f 100644
--- a/chart2/source/tools/RegressionEquation.cxx
+++ b/chart2/source/tools/RegressionEquation.cxx
@@ -52,6 +52,8 @@ static const char lcl_aServiceName[] =  "com.sun.star.chart2.RegressionEquation"
 enum
 {
     PROP_EQUATION_SHOW,
+    PROP_EQUATION_XNAME,
+    PROP_EQUATION_YNAME,
     PROP_EQUATION_SHOW_CORRELATION_COEFF,
     PROP_EQUATION_REF_PAGE_SIZE,
     PROP_EQUATION_REL_POS,
@@ -69,6 +71,20 @@ void lcl_AddPropertiesToVector(
                   | beans::PropertyAttribute::MAYBEDEFAULT ));
 
     rOutProperties.push_back(
+        Property( "XName",
+                  PROP_EQUATION_XNAME,
+                  cppu::UnoType<OUString>::get(),
+                  beans::PropertyAttribute::BOUND
+                  | beans::PropertyAttribute::MAYBEDEFAULT ));
+
+    rOutProperties.push_back(
+        Property( "YName",
+                  PROP_EQUATION_YNAME,
+                  cppu::UnoType<OUString>::get(),
+                  beans::PropertyAttribute::BOUND
+                  | beans::PropertyAttribute::MAYBEDEFAULT ));
+
+    rOutProperties.push_back(
         Property( "ShowCorrelationCoefficient",
                   PROP_EQUATION_SHOW_CORRELATION_COEFF,
                   cppu::UnoType<bool>::get(),
@@ -113,6 +129,8 @@ private:
         ::chart::CharacterProperties::AddDefaultsToMap( rOutMap );
 
         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_SHOW, false );
+        ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_XNAME, OUString("x") );
+        ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_YNAME, OUString("f(x)") );
         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_SHOW_CORRELATION_COEFF, false );
         //::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_SEPARATOR, OUString( '\n' ));
 
diff --git a/chart2/source/view/charttypes/VSeriesPlotter.cxx b/chart2/source/view/charttypes/VSeriesPlotter.cxx
index eebc596..7402bdf 100644
--- a/chart2/source/view/charttypes/VSeriesPlotter.cxx
+++ b/chart2/source/view/charttypes/VSeriesPlotter.cxx
@@ -1251,6 +1251,15 @@ void VSeriesPlotter::createRegressionCurveEquationShapes(
         xEquationProperties->getPropertyValue(CHART_UNONAME_NUMFMT) >>= nNumberFormatKey;
         bool bResizeEquation = true;
         sal_Int32 nMaxIteration = 2;
+        if ( bShowEquation )
+        {
+            OUString aXName, aYName;
+            if ( !(xEquationProperties->getPropertyValue( "XName" ) >>= aXName) )
+                aXName = OUString( "x" );
+            if ( !(xEquationProperties->getPropertyValue( "YName" ) >>= aYName) )
+                aYName = OUString( "f(x)" );
+            xRegressionCurveCalculator->setXYNames( aXName, aYName );
+        }
 
         for ( sal_Int32 nCountIteration = 0; bResizeEquation && nCountIteration < nMaxIteration ; nCountIteration++ )
         {
diff --git a/chart2/source/view/main/ChartItemPool.cxx b/chart2/source/view/main/ChartItemPool.cxx
index 1587ac7..6e089e0 100644
--- a/chart2/source/view/main/ChartItemPool.cxx
+++ b/chart2/source/view/main/ChartItemPool.cxx
@@ -158,6 +158,8 @@ ChartItemPool::ChartItemPool():
     ppPoolDefaults[SCHATTR_REGRESSION_SET_INTERCEPT         - SCHATTR_START] = new SfxBoolItem(SCHATTR_REGRESSION_SET_INTERCEPT, false);
     ppPoolDefaults[SCHATTR_REGRESSION_INTERCEPT_VALUE       - SCHATTR_START] = new SvxDoubleItem(0.0, SCHATTR_REGRESSION_INTERCEPT_VALUE);
     ppPoolDefaults[SCHATTR_REGRESSION_CURVE_NAME            - SCHATTR_START] = new SfxStringItem(SCHATTR_REGRESSION_CURVE_NAME, OUString());
+    ppPoolDefaults[SCHATTR_REGRESSION_XNAME                 - SCHATTR_START] = new SfxStringItem(SCHATTR_REGRESSION_XNAME, OUString("x"));
+    ppPoolDefaults[SCHATTR_REGRESSION_YNAME                 - SCHATTR_START] = new SfxStringItem(SCHATTR_REGRESSION_YNAME, OUString("f(x)"));
 
     /**************************************************************************
     * ItemInfos
diff --git a/chart2/uiconfig/ui/tp_Trendline.ui b/chart2/uiconfig/ui/tp_Trendline.ui
index 7060c99..e2a05d7 100644
--- a/chart2/uiconfig/ui/tp_Trendline.ui
+++ b/chart2/uiconfig/ui/tp_Trendline.ui
@@ -521,6 +521,64 @@
                     <property name="height">1</property>
                   </packing>
                 </child>
+                <child>
+                  <object class="GtkLabel" id="label6">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="xalign">0</property>
+                    <property name="label" translatable="yes">X Variable Name</property>
+                    <property name="use_underline">True</property>
+                    <property name="mnemonic_widget">entry_Xname</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">5</property>
+                    <property name="width">1</property>
+                    <property name="height">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkEntry" id="entry_Xname">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="invisible_char">•</property>
+                </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="top_attach">5</property>
+                    <property name="width">1</property>
+                    <property name="height">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="label9">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="xalign">0</property>
+                    <property name="label" translatable="yes">Y Variable Name</property>
+                    <property name="use_underline">True</property>
+                    <property name="mnemonic_widget">entry_Yname</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">6</property>
+                    <property name="width">1</property>
+                    <property name="height">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkEntry" id="entry_Yname">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="invisible_char">•</property>
+                </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="top_attach">6</property>
+                    <property name="width">1</property>
+                    <property name="height">1</property>
+                  </packing>
+                </child>
               </object>
             </child>
           </object>
diff --git a/offapi/com/sun/star/chart2/RegressionCurveEquation.idl b/offapi/com/sun/star/chart2/RegressionCurveEquation.idl
index 1956ce6..0aea580 100644
--- a/offapi/com/sun/star/chart2/RegressionCurveEquation.idl
+++ b/offapi/com/sun/star/chart2/RegressionCurveEquation.idl
@@ -42,6 +42,8 @@ service RegressionCurveEquation
     service       ::com::sun::star::style::CharacterProperties;
 
     [property]             boolean                                     ShowEquation;
+    [property]             string                                      XName;
+    [property]             string                                      YName;
     [property]             boolean                                     ShowCorrelationCoefficient;
 
     [property, maybevoid]  ::com::sun::star::chart2::RelativePosition  RelativePosition;
diff --git a/offapi/com/sun/star/chart2/XRegressionCurveCalculator.idl b/offapi/com/sun/star/chart2/XRegressionCurveCalculator.idl
index ce0632c..e7599ae 100644
--- a/offapi/com/sun/star/chart2/XRegressionCurveCalculator.idl
+++ b/offapi/com/sun/star/chart2/XRegressionCurveCalculator.idl
@@ -162,6 +162,14 @@ interface XRegressionCurveCalculator : com::sun::star::uno::XInterface
                                        [in] long nNumberFormatKey,
                                        [in] long nFormulaLength );
 
+    /** Set the names of X and Y variables of the equation to replace "x" and "f(x)" in representation
+
+        @param aXName string of the name of X variable
+        @param aYName string of the name of Y variable
+    */
+    void setXYNames( [in] string aXName,
+                     [in] string aYName );
+
 };
 
 } ; // chart2


More information about the Libreoffice-commits mailing list