From 60fb0cb47f8ec55ec3f92b392038276ea78edd6e Mon Sep 17 00:00:00 2001 From: Alessandro Pasotti Date: Thu, 19 Sep 2019 09:10:26 +0200 Subject: [PATCH] Apply timer spinbox workaround to QgsDoubleSpinBox too To prevent double changed event fired in case the slot takes too long to execute. --- .../editorwidgets/qgsdoublespinbox.sip.in | 2 ++ src/gui/editorwidgets/qgsdoublespinbox.cpp | 11 +++++++++++ src/gui/editorwidgets/qgsdoublespinbox.h | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/python/gui/auto_generated/editorwidgets/qgsdoublespinbox.sip.in b/python/gui/auto_generated/editorwidgets/qgsdoublespinbox.sip.in index dd6d5eb5edb..4ddd79e8e75 100644 --- a/python/gui/auto_generated/editorwidgets/qgsdoublespinbox.sip.in +++ b/python/gui/auto_generated/editorwidgets/qgsdoublespinbox.sip.in @@ -145,6 +145,8 @@ is equal to minimum(). Typical use is to indicate that this choice has a special virtual void wheelEvent( QWheelEvent *event ); + virtual void timerEvent( QTimerEvent *event ); + }; diff --git a/src/gui/editorwidgets/qgsdoublespinbox.cpp b/src/gui/editorwidgets/qgsdoublespinbox.cpp index e7c875c0569..0861721ce2c 100644 --- a/src/gui/editorwidgets/qgsdoublespinbox.cpp +++ b/src/gui/editorwidgets/qgsdoublespinbox.cpp @@ -93,6 +93,17 @@ void QgsDoubleSpinBox::wheelEvent( QWheelEvent *event ) setSingleStep( step ); } +void QgsDoubleSpinBox::timerEvent( QTimerEvent *event ) +{ + // Process all events, which may include a mouse release event + // Only allow the timer to trigger additional value changes if the user + // has in fact held the mouse button, rather than the timer expiry + // simply appearing before the mouse release in the event queue + qApp->processEvents(); + if ( QApplication::mouseButtons() & Qt::LeftButton ) + QDoubleSpinBox::timerEvent( event ); +} + void QgsDoubleSpinBox::paintEvent( QPaintEvent *event ) { mLineEdit->setShowClearButton( shouldShowClearForValue( value() ) ); diff --git a/src/gui/editorwidgets/qgsdoublespinbox.h b/src/gui/editorwidgets/qgsdoublespinbox.h index af61b22b0c4..4b3cbf31720 100644 --- a/src/gui/editorwidgets/qgsdoublespinbox.h +++ b/src/gui/editorwidgets/qgsdoublespinbox.h @@ -146,6 +146,10 @@ class GUI_EXPORT QgsDoubleSpinBox : public QDoubleSpinBox protected: void changeEvent( QEvent *event ) override; void wheelEvent( QWheelEvent *event ) override; + // This is required because private implementation of + // QAbstractSpinBoxPrivate may trigger a second + // undesired event from the auto-repeat mouse timer + void timerEvent( QTimerEvent *event ) override; private slots: void changed( double value );