vcl/inc/qt5/QtInstanceEntry.hxx  |    3 +++
 vcl/qt5/QtInstanceEntry.cxx      |    9 ++++++++-
 vcl/qt5/QtInstanceSpinButton.cxx |   13 +++++++++++++
 3 files changed, 24 insertions(+), 1 deletion(-)

New commits:
commit 70825e677f808437bd47651ebecc8a0c53955676
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Thu Nov 28 00:30:10 2024 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Thu Nov 28 08:38:26 2024 +0100

    tdf#130857 qt weld: Notify about spinbox combined value+text change
    
    While QtInstanceEntry generally takes care of handling signals
    for the spinbox's QLineEdit, this doesn't work when the value
    is changed as a result of setting a new spinbox value (e.g.
    by using the spinbox buttons), as the QLineEdit signals are blocked
    then, see QAbstractSpinBoxPrivate::updateEdit in qtbase [1].
    Therefore, connect the QDoubleSpinBox::textChanged signal
    to the slot that calls signal_changed() instead to ensure
    it gets called nonetheless, and disconnect from the other signal.
    
    While at it, also add a SolarMutexGuard when calling the
    signal.
    
    This fixes the issue noticed with the "Go to Page"
    dialog mentioned in previous commit
    
        Change-Id: I1f24cf3925e945ae78a9f1646535e08736cd8786
    
        Author: Michael Weghorn <m.wegh...@posteo.de>
        Date:   Wed Nov 27 23:53:58 2024 +0100
    
            tdf#130857 qt weld: Support "Go to Page" dialog
    
    as:
    
    > One issue seen with the dialog is that by using the
    > up arrow of the spinbox to increase the value, it
    > is currently possible to increase the value
    > beyond the maximum value (last page number),
    > while this is not the case when typing a number
    > into the box manually.
    >
    > This is because the GotoPageDlg::PageModifiedHdl
    > handler currently only gets called for the
    > latter case, not the former one, despite
    >
    >     Change-Id: Ie19bc852f4ceed0fa79565302975376db7126ea4
    >     Author: Michael Weghorn <m.wegh...@posteo.de>
    >     Date:   Wed Nov 27 22:53:55 2024 +0100
    >
    >         tdf#130857 qt weld: Also notify about programmatic text changes
    >
    > and will be addressed in a separate commit.
    
    [1] 
https://code.qt.io/cgit/qt/qtbase.git/tree/src/widgets/widgets/qabstractspinbox.cpp?id=ced47a590aeb85953a16eaf362887f14c2815c45#n1790
    
    Change-Id: Ifba9a0877442f9e84f0103d8aab202ae3583c5cf
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177451
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/inc/qt5/QtInstanceEntry.hxx b/vcl/inc/qt5/QtInstanceEntry.hxx
index aa094e1b99d6..73a4e3fec9a3 100644
--- a/vcl/inc/qt5/QtInstanceEntry.hxx
+++ b/vcl/inc/qt5/QtInstanceEntry.hxx
@@ -48,6 +48,9 @@ public:
     virtual void paste_clipboard() override;
 
     virtual void set_alignment(TxtAlign eXAlign) override;
+
+protected Q_SLOTS:
+    void handleTextChanged();
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/vcl/qt5/QtInstanceEntry.cxx b/vcl/qt5/QtInstanceEntry.cxx
index cb5cecb80c85..49da357f6d8c 100644
--- a/vcl/qt5/QtInstanceEntry.cxx
+++ b/vcl/qt5/QtInstanceEntry.cxx
@@ -22,7 +22,8 @@ QtInstanceEntry::QtInstanceEntry(QLineEdit* pLineEdit)
 
     QObject::connect(m_pLineEdit, &QLineEdit::cursorPositionChanged, this,
                      [&] { signal_cursor_position(); });
-    QObject::connect(m_pLineEdit, &QLineEdit::textChanged, this, [&] { 
signal_changed(); });
+    QObject::connect(m_pLineEdit, &QLineEdit::textChanged, this,
+                     &QtInstanceEntry::handleTextChanged);
 }
 
 void QtInstanceEntry::set_text(const OUString& rText)
@@ -173,4 +174,10 @@ void QtInstanceEntry::paste_clipboard() { assert(false && 
"Not implemented yet")
 
 void QtInstanceEntry::set_alignment(TxtAlign) { assert(false && "Not 
implemented yet"); }
 
+void QtInstanceEntry::handleTextChanged()
+{
+    SolarMutexGuard aGuard;
+    signal_changed();
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/vcl/qt5/QtInstanceSpinButton.cxx b/vcl/qt5/QtInstanceSpinButton.cxx
index 19c9754bccd0..22b4ba401c25 100644
--- a/vcl/qt5/QtInstanceSpinButton.cxx
+++ b/vcl/qt5/QtInstanceSpinButton.cxx
@@ -20,6 +20,19 @@ QtInstanceSpinButton::QtInstanceSpinButton(QtDoubleSpinBox* 
pSpinBox)
 
     connect(m_pSpinBox, QOverload<double>::of(&QtDoubleSpinBox::valueChanged), 
this,
             &QtInstanceSpinButton::handleValueChanged);
+
+    // While QtInstanceEntry generally takes care of handling signals
+    // for the spinbox's QLineEdit, this doesn't work when the value
+    // is changed as a result of setting a new spinbox value (e.g.
+    // by using the spinbox buttons), as the QLineEdit signals are blocked
+    // then, see QAbstractSpinBoxPrivate::updateEdit in qtbase:
+    // 
https://code.qt.io/cgit/qt/qtbase.git/tree/src/widgets/widgets/qabstractspinbox.cpp?id=ced47a590aeb85953a16eaf362887f14c2815c45#n1790
+    // Therefore, connect the QDoubleSpinBox::textChanged signal
+    // to the slot that calls signal_changed() instead to ensure
+    // it gets called nonetheless, and disconnect from the other signal.
+    disconnect(pSpinBox->lineEdit(), &QLineEdit::textChanged, this, nullptr);
+    connect(m_pSpinBox, &QDoubleSpinBox::textChanged, this,
+            &QtInstanceSpinButton::handleTextChanged);
 }
 
 QWidget* QtInstanceSpinButton::getQWidget() const { return m_pSpinBox; }

Reply via email to