aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2017-11-06 13:53:03 +0100
committerJ-P Nurmi <jpnurmi@qt.io>2017-11-07 08:33:50 +0000
commitf46776cc68f88a8cbc518cacf6c63f31f11d73b0 (patch)
tree0d442492c20e0f7380afb5a475f4d9d3f4bc1429
parentf0f66c1aa001c630a6b246e312bef7f8e83958d2 (diff)
Fix QQuickSlider::valueAt()
Task-number: QTBUG-64065 Change-Id: Id77a85ce5b88c20795e9f7fe9d2ece974f46a315 Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
-rw-r--r--src/quicktemplates2/qquickslider.cpp6
-rw-r--r--tests/auto/controls/data/tst_slider.qml6
2 files changed, 7 insertions, 5 deletions
diff --git a/src/quicktemplates2/qquickslider.cpp b/src/quicktemplates2/qquickslider.cpp
index 4d3cbe3e..da2f402f 100644
--- a/src/quicktemplates2/qquickslider.cpp
+++ b/src/quicktemplates2/qquickslider.cpp
@@ -513,10 +513,10 @@ void QQuickSlider::setHandle(QQuickItem *handle)
qreal QQuickSlider::valueAt(qreal position) const
{
Q_D(const QQuickSlider);
- const qreal value = d->from + (d->to - d->from) * position;
+ const qreal value = (d->to - d->from) * position;
if (qFuzzyIsNull(d->stepSize))
- return value;
- return qRound(value / d->stepSize) * d->stepSize;
+ return d->from + value;
+ return d->from + qRound(value / d->stepSize) * d->stepSize;
}
/*!
diff --git a/tests/auto/controls/data/tst_slider.qml b/tests/auto/controls/data/tst_slider.qml
index 8d696297..9ee8626d 100644
--- a/tests/auto/controls/data/tst_slider.qml
+++ b/tests/auto/controls/data/tst_slider.qml
@@ -769,12 +769,14 @@ TestCase {
return [
{ tag: "0.0..1.0", from: 0.0, to: 1.0, values: [0.0, 0.2, 0.5, 1.0] },
{ tag: "0..100", from: 0, to: 100, values: [0, 20, 50, 100] },
- { tag: "100..-100", from: 100, to: -100, values: [100, 60, 0, -100] }
+ { tag: "100..-100", from: 100, to: -100, values: [100, 60, 0, -100] },
+ { tag: "-7..7", from: -7, to: 7, stepSize: 1.0, values: [-7.0, -4.0, 0.0, 7.0] },
+ { tag: "-3..7", from: -3, to: 7, stepSize: 5.0, values: [-3.0, -3.0, 2.0, 7.0] },
]
}
function test_valueAt(data) {
- var control = createTemporaryObject(slider, testCase, {from: data.from, to: data.to})
+ var control = createTemporaryObject(slider, testCase, {from: data.from, to: data.to, stepSize: data.stepSize})
verify(control)
compare(control.valueAt(0.0), data.values[0])