From b1909ca4d1d80c36601eb942459db3ff60174c8e Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Tue, 15 Nov 2016 14:35:56 +0100 Subject: [PATCH] QQuickSpinBox: fix auto-repeat Don't cancel auto-repeat on the tiniest mouse/touch move, but keep repeating until moved outside the button. The test has been written so that the exact amount of repeats does not matter, as long as it repeats. This is because waits are not reliable in a busy CI environment. Sometimes waits can take longer, timer events get queued, and we get an unexpected burst of repeats. Change-Id: Ibdcdd9e684bbcda032abfabb8a33ed892c7778df Task-number: QTBUG-57085 Reviewed-by: Mitch Curtis --- src/quicktemplates2/qquickspinbox.cpp | 3 +- tests/auto/controls/data/tst_spinbox.qml | 62 ++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/src/quicktemplates2/qquickspinbox.cpp b/src/quicktemplates2/qquickspinbox.cpp index 79ec5da046..473b664359 100644 --- a/src/quicktemplates2/qquickspinbox.cpp +++ b/src/quicktemplates2/qquickspinbox.cpp @@ -242,7 +242,8 @@ bool QQuickSpinBoxPrivate::handleMouseMoveEvent(QQuickItem *child, QMouseEvent * bool pressed = up->isPressed() || down->isPressed(); q->setAccessibleProperty("pressed", pressed); - stopPressRepeat(); + if (!pressed) + stopPressRepeat(); return pressed; } diff --git a/tests/auto/controls/data/tst_spinbox.qml b/tests/auto/controls/data/tst_spinbox.qml index a62128d261..f2d8d3ef37 100644 --- a/tests/auto/controls/data/tst_spinbox.qml +++ b/tests/auto/controls/data/tst_spinbox.qml @@ -491,4 +491,66 @@ TestCase { control.destroy() } + + function test_autoRepeat() { + var control = spinBox.createObject(testCase) + verify(control) + + compare(control.value, 0) + + var valueSpy = signalSpy.createObject(control, {target: control, signalName: "valueChanged"}) + verify(valueSpy.valid) + + var countBefore = 0 + + // repeat up + mousePress(control.up.indicator) + verify(control.up.pressed) + compare(valueSpy.count, 0) + valueSpy.wait() + valueSpy.wait() + countBefore = valueSpy.count + mouseRelease(control.up.indicator) + verify(!control.up.pressed) + compare(valueSpy.count, countBefore) + + valueSpy.clear() + + // repeat down + mousePress(control.down.indicator) + verify(control.down.pressed) + compare(valueSpy.count, 0) + valueSpy.wait() + valueSpy.wait() + countBefore = valueSpy.count + mouseRelease(control.down.indicator) + verify(!control.down.pressed) + compare(valueSpy.count, countBefore) + + mousePress(control.up.indicator) + verify(control.up.pressed) + valueSpy.wait() + + // move inside during repeat -> continue repeat (QTBUG-57085) + mouseMove(control.up.indicator, control.up.indicator.width / 4, control.up.indicator.height / 4) + verify(control.up.pressed) + valueSpy.wait() + + valueSpy.clear() + + // move outside during repeat -> stop repeat + mouseMove(control.up.indicator, -1, -1) + verify(!control.up.pressed) + // NOTE: The following wait() is NOT a reliable way to test that the + // auto-repeat timer is not running, but there's no way dig into the + // private APIs from QML. If this test ever fails in the future, it + // indicates that the auto-repeat timer logic is broken. + wait(125) + compare(valueSpy.count, 0) + + mouseRelease(control.up.indicator, -1, -1) + verify(!control.up.pressed) + + control.destroy() + } }