diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2016-11-15 14:35:56 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2016-11-17 09:59:54 +0000 |
commit | b1909ca4d1d80c36601eb942459db3ff60174c8e (patch) | |
tree | c4780a720ef7c71c6b1622e70f9abadba77bdb55 | |
parent | aa1a8444991aee671981a99d1e08c5e1cb02c94a (diff) |
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 <mitch.curtis@qt.io>
-rw-r--r-- | src/quicktemplates2/qquickspinbox.cpp | 3 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_spinbox.qml | 62 |
2 files changed, 64 insertions, 1 deletions
diff --git a/src/quicktemplates2/qquickspinbox.cpp b/src/quicktemplates2/qquickspinbox.cpp index 79ec5da0..473b6643 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 a62128d2..f2d8d3ef 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() + } } |