From 1c7d06f2696465993d63a33bf4144f49f02552bc Mon Sep 17 00:00:00 2001
From: Jens Bache-Wiig <jens.bache-wiig@digia.com>
Date: Tue, 4 Jun 2013 11:03:39 +0200
Subject: [PATCH] Fix warning in Slider when stepSize is set

Also adding a new test for stepSize

Task-number: QTBUG-31441

Change-Id: Ib8d9cc2188b5f73b6b0ac866ade1a7edb1d662b7
Reviewed-by: Caroline Chao <caroline.chao@digia.com>
---
 src/controls/Slider.qml                 | 16 ++++++++--------
 tests/auto/controls/data/tst_slider.qml | 11 +++++++++++
 2 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/src/controls/Slider.qml b/src/controls/Slider.qml
index b31d4f78d..e7e491515 100644
--- a/src/controls/Slider.qml
+++ b/src/controls/Slider.qml
@@ -197,6 +197,14 @@ Control {
         anchors.horizontalCenter: !__horizontal ? parent.horizontalCenter : undefined
         width: __panel.handleWidth
         height: __panel.handleHeight
+
+        function updatePos() {
+            if (updateValueWhileDragging && !mouseArea.drag.active)
+                            range.position = __horizontal ? x : y
+        }
+
+        onXChanged: updatePos();
+        onYChanged: updatePos();
     }
 
     MouseArea {
@@ -247,14 +255,6 @@ Control {
         }
     }
 
-    // Range position normally follows handle, except when
-    // 'updateValueWhileDragging' is false.
-    Binding {
-        when: updateValueWhileDragging && !mouseArea.drag.active
-        target: range
-        property: "position"
-        value: __horizontal ? fakeHandle.x : fakeHandle.y
-    }
 
     // During the drag, we simply ignore the position set from the range, this
     // means that setting a value while dragging will not "interrupt" the
diff --git a/tests/auto/controls/data/tst_slider.qml b/tests/auto/controls/data/tst_slider.qml
index 96b4d4223..177a8fcb2 100644
--- a/tests/auto/controls/data/tst_slider.qml
+++ b/tests/auto/controls/data/tst_slider.qml
@@ -282,5 +282,16 @@ Item {
             verify(control.value > 0.5)
             control.destroy()
         }
+
+        function test_valueAndHandlePosition()
+        {
+            var slider = Qt.createQmlObject('import QtQuick.Controls 1.0; Slider {minimumValue: 0; maximumValue: 100; width: 100; height: 20; stepSize: 1}', container, '');
+            slider.forceActiveFocus()
+            slider.value = 0
+            compare(slider.__handlePos, 0)
+            slider.value = 50
+            compare(slider.__handlePos, 50)
+            slider.destroy()
+        }
     }
 }
-- 
GitLab