Apply timer spinbox workaround to QgsDoubleSpinBox too

To prevent double changed event fired in case the slot
takes too long to execute.
This commit is contained in:
Alessandro Pasotti 2019-09-19 09:10:26 +02:00
parent bd6ecba176
commit 60fb0cb47f
3 changed files with 17 additions and 0 deletions

View File

@ -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 );
};

View File

@ -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() ) );

View File

@ -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 );