From 29dfaa92b9d56f5555b511756f5b8ee62aabc0bf Mon Sep 17 00:00:00 2001 From: Ivan Solovev Date: Thu, 2 Dec 2021 18:45:15 +0100 Subject: RangeSlider: update handle positions when 'from' or 'to' value is changed The RangeSlider's setTo() and setFrom() implementation was not updating the positions of the handles. This patch fixes it and aligns the behavior with the basic Slider. This commit is cherry-picked from qtdeclarative repo of the dev branch, because QuickControls2 were merged into that repo in Qt 6. Fixes: QTBUG-98482 Change-Id: I482c416f91be2b97af1d922305dfe6fc1f5bd573 Reviewed-by: Mitch Curtis (cherry picked from commit 7ff266ff782b35817d3ecc1a08c3a54bd2c2aa88) --- tests/auto/controls/data/tst_rangeslider.qml | 37 ++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'tests/auto/controls/data/tst_rangeslider.qml') diff --git a/tests/auto/controls/data/tst_rangeslider.qml b/tests/auto/controls/data/tst_rangeslider.qml index d645ec70..42f5bad5 100644 --- a/tests/auto/controls/data/tst_rangeslider.qml +++ b/tests/auto/controls/data/tst_rangeslider.qml @@ -159,6 +159,43 @@ TestCase { compare(control.first.position, 0.5) } + function test_setToFromUpdatesHandles() { + var control = createTemporaryObject(sliderComponent, testCase, { from: 0, to: 100, "first.value": 50, "second.value": 75 }) + verify(control) + + let firstPos = control.first.position + let secondPos = control.second.position + + var firstPosChangesSpy = signalSpy.createObject(control, {target: control.first, signalName: "positionChanged"}) + verify(firstPosChangesSpy.valid) + + var secondPosChangesSpy = signalSpy.createObject(control, {target: control.second, signalName: "positionChanged"}) + verify(secondPosChangesSpy.valid) + + // Increasing the 'to' value, so the positions of the handles should be + // moved to the left (become smaller) + control.to = 200; + compare(firstPosChangesSpy.count, 1) + compare(secondPosChangesSpy.count, 1) + verify(control.first.position < firstPos) + verify(control.second.position < secondPos) + + // resetting the values + control.to = 100 + firstPosChangesSpy.clear() + secondPosChangesSpy.clear() + firstPos = control.first.position + secondPos = control.second.position + + // Decreasing the 'from' value, so the positions of the handles should + // be moved to the right (become larger) + control.from = -100 + compare(firstPosChangesSpy.count, 1) + compare(secondPosChangesSpy.count, 1) + verify(control.first.position > firstPos) + verify(control.second.position > secondPos) + } + function test_setValues() { var control = createTemporaryObject(sliderComponent, testCase) verify(control) -- cgit v1.2.3