include/vcl/formatter.hxx                 |    2 
 vcl/qt5/QtInstanceFormattedSpinButton.cxx |    4 +
 vcl/source/control/fmtfield.cxx           |   68 +++++++++++++++---------------
 3 files changed, 42 insertions(+), 32 deletions(-)

New commits:
commit 4d580ab25c24fc2293f41a3b580c874f817ee7aa
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Wed Feb 19 16:55:01 2025 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Wed Feb 19 22:43:08 2025 +0100

    tdf#130857 qt weld: Format QtInstanceFormattedSpinButton value
    
    Set a function used to convert the value to text to show in
    the QtDoubleSpinBox used in QtInstanceFormattedSpinButton.
    
    For further background, see also
    
        commit 6871b55b6915396caa3e5aca7e233f6a5efc7864
        Author: Michael Weghorn <m.wegh...@posteo.de>
        Date:   Sat Feb 15 17:47:01 2025 +0100
    
            tdf#130857 qt weld: Implement SpinButton text <-> value conversion
    
    and related commits doing similar for QtInstanceSpinButton.
    
    This e.g. makes the time value shown in the Impress
    "Slide Show" -> "Slide Show Settings" dialog be formatted
    as expected in a WIP branch that declares support
    for that dialog.
    
    Conversion the other way around (i.e. text to value)
    is still missing.
    
    Change-Id: I229553c15ca318643472b9ca797f0a81060a3f2b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181914
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/vcl/qt5/QtInstanceFormattedSpinButton.cxx 
b/vcl/qt5/QtInstanceFormattedSpinButton.cxx
index eba70b74e65a..22b8860dede9 100644
--- a/vcl/qt5/QtInstanceFormattedSpinButton.cxx
+++ b/vcl/qt5/QtInstanceFormattedSpinButton.cxx
@@ -31,6 +31,10 @@ 
QtInstanceFormattedSpinButton::QtInstanceFormattedSpinButton(QtDoubleSpinBox* pS
     disconnect(pSpinBox->lineEdit(), &QLineEdit::textChanged, this, nullptr);
     connect(m_pSpinBox, &QDoubleSpinBox::textChanged, this,
             &QtInstanceFormattedSpinButton::handleTextChanged);
+
+    // set function to convert value to text
+    m_pSpinBox->setFormatValueFunction(
+        [this](double fValue) { return GetFormatter().FormatValue(fValue); });
 }
 
 QWidget* QtInstanceFormattedSpinButton::getQWidget() const { return 
m_pSpinBox; }
commit 15adb8396cc8f2a1c693f3d11bcd7d42a1aad41a
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Tue Feb 18 22:06:58 2025 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Wed Feb 19 22:43:03 2025 +0100

    tdf#130857 vcl: Extract Formatter method to convert value to string
    
    Extract logic to convert a value to a string from
    Formatter::ImplSetValue to a new method Formatter::FormatValue.
    
    The new method will also be used by QtInstanceFormattedSpinButton in
    an upcoming commit.
    
    Change-Id: I8735cf49c9c72f2fba3782256a7f54507bcf76e6
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181913
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/include/vcl/formatter.hxx b/include/vcl/formatter.hxx
index 4e40fd43a8bb..889c20a879f8 100644
--- a/include/vcl/formatter.hxx
+++ b/include/vcl/formatter.hxx
@@ -244,6 +244,8 @@ public:
 
     void    SetInputHdl(const Link<double*,TriState>& rLink) { m_aInputHdl = 
rLink; }
     void    SetFormatValueHdl(const Link<double, std::optional<OUString>>& 
rLink) { m_aFormatValueHdl = rLink; }
+
+    OUString FormatValue(double fValue);
 public:
 
     //The following methods are interesting, if m_bTreatAsNumber is set to 
sal_False
diff --git a/vcl/source/control/fmtfield.cxx b/vcl/source/control/fmtfield.cxx
index 3de297e380ef..8dc97702e533 100644
--- a/vcl/source/control/fmtfield.cxx
+++ b/vcl/source/control/fmtfield.cxx
@@ -533,6 +533,39 @@ bool Formatter::SetFormat(const OUString& rFormatString, 
LanguageType eLang)
     return true;
 }
 
+OUString Formatter::FormatValue(double fValue)
+{
+    if (m_aFormatValueHdl.IsSet())
+    {
+        std::optional<OUString> aText = m_aFormatValueHdl.Call(fValue);
+        if (aText.has_value())
+            return aText.value();
+    }
+
+    OUString sNewText;
+    if (GetOrCreateFormatter().IsTextFormat(m_nFormatKey))
+    {
+        // first convert the number as string in standard format
+        OUString sTemp;
+        GetOrCreateFormatter().GetOutputString(fValue, 0, sTemp, 
&m_pLastOutputColor);
+        // then encode the string in the corresponding text format
+        GetOrCreateFormatter().GetOutputString(sTemp, m_nFormatKey, sNewText, 
&m_pLastOutputColor);
+    }
+    else
+    {
+        if( IsUsingInputStringForFormatting())
+        {
+            sNewText = GetOrCreateFormatter().GetInputLineString(fValue, 
m_nFormatKey);
+        }
+        else
+        {
+            GetOrCreateFormatter().GetOutputString(fValue, m_nFormatKey, 
sNewText, &m_pLastOutputColor);
+        }
+    }
+
+    return sNewText;
+}
+
 bool Formatter::GetThousandsSep() const
 {
     DBG_ASSERT(!GetOrCreateFormatter().IsTextFormat(m_nFormatKey),
@@ -744,38 +777,9 @@ void Formatter::ImplSetValue(double dVal, bool bForce)
     m_ValueState = valueDouble;
     UpdateCurrentValue(dVal);
 
-    std::optional<OUString> aText;
-    if (m_aFormatValueHdl.IsSet())
-        aText = m_aFormatValueHdl.Call(dVal);
-
-    if (!aText.has_value())
-    {
-        OUString sNewText;
-        if (GetOrCreateFormatter().IsTextFormat(m_nFormatKey))
-        {
-            // first convert the number as string in standard format
-            OUString sTemp;
-            GetOrCreateFormatter().GetOutputString(dVal, 0, sTemp, 
&m_pLastOutputColor);
-            // then encode the string in the corresponding text format
-            GetOrCreateFormatter().GetOutputString(sTemp, m_nFormatKey, 
sNewText, &m_pLastOutputColor);
-        }
-        else
-        {
-            if( IsUsingInputStringForFormatting())
-            {
-                sNewText = GetOrCreateFormatter().GetInputLineString(dVal, 
m_nFormatKey);
-            }
-            else
-            {
-                GetOrCreateFormatter().GetOutputString(dVal, m_nFormatKey, 
sNewText, &m_pLastOutputColor);
-            }
-        }
-        aText = sNewText;
-    }
-
-    assert(aText.has_value());
-    ImplSetTextImpl(*aText, nullptr);
-    DBG_ASSERT(CheckText(*aText), "FormattedField::ImplSetValue : formatted 
string doesn't match the criteria !");
+    const OUString sNewText = FormatValue(dVal);
+    ImplSetTextImpl(sNewText, nullptr);
+    DBG_ASSERT(CheckText(sNewText), "FormattedField::ImplSetValue : formatted 
string doesn't match the criteria !");
 
     m_ValueState = valueDouble;
 }

Reply via email to