diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2017-01-17 11:48:45 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2017-01-17 11:55:02 +0000 |
commit | 624f61b7d8ada80818b697393aa8d22595b7b8e6 (patch) | |
tree | f60d72fd427c1d3b0446da5962e269ed45da5f93 | |
parent | 537eced61381f0ce1eabdc797bb0dacd11e11d39 (diff) |
QQuickSpinBox: enable/disable up/down buttons on range changes
Previously the buttons were enabled/disabled on range changes only if
it caused the value to change. Make sure to update them also when the
value does not change.
Task-number: QTBUG-58217
Change-Id: Ibab5b8b7a58d5b88341c507a63b69f5a05fdfc1f
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r-- | src/quicktemplates2/qquickspinbox.cpp | 48 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_spinbox.qml | 23 |
2 files changed, 53 insertions, 18 deletions
diff --git a/src/quicktemplates2/qquickspinbox.cpp b/src/quicktemplates2/qquickspinbox.cpp index f73457b5..c44b9e81 100644 --- a/src/quicktemplates2/qquickspinbox.cpp +++ b/src/quicktemplates2/qquickspinbox.cpp @@ -102,6 +102,7 @@ public: int boundValue(int value) const; void updateValue(); + bool setValue(int value); int effectiveStepSize() const; @@ -156,6 +157,24 @@ void QQuickSpinBoxPrivate::updateValue() } } +bool QQuickSpinBoxPrivate::setValue(int newValue) +{ + Q_Q(QQuickSpinBox); + if (q->isComponentComplete()) + newValue = boundValue(newValue); + + if (value == newValue) + return false; + + value = newValue; + + updateUpEnabled(); + updateDownEnabled(); + + emit q->valueChanged(); + return true; +} + int QQuickSpinBoxPrivate::effectiveStepSize() const { return from > to ? -1 * stepSize : stepSize; @@ -322,8 +341,12 @@ void QQuickSpinBox::setFrom(int from) d->from = from; emit fromChanged(); - if (isComponentComplete()) - setValue(d->value); + if (isComponentComplete()) { + if (!d->setValue(d->value)) { + d->updateUpEnabled(); + d->updateDownEnabled(); + } + } } /*! @@ -347,8 +370,12 @@ void QQuickSpinBox::setTo(int to) d->to = to; emit toChanged(); - if (isComponentComplete()) - setValue(d->value); + if (isComponentComplete()) { + if (!d->setValue(d->value)) { + d->updateUpEnabled(); + d->updateDownEnabled(); + } + } } /*! @@ -365,18 +392,7 @@ int QQuickSpinBox::value() const void QQuickSpinBox::setValue(int value) { Q_D(QQuickSpinBox); - if (isComponentComplete()) - value = d->boundValue(value); - - if (d->value == value) - return; - - d->value = value; - - d->updateUpEnabled(); - d->updateDownEnabled(); - - emit valueChanged(); + d->setValue(value); } /*! diff --git a/tests/auto/controls/data/tst_spinbox.qml b/tests/auto/controls/data/tst_spinbox.qml index 06426f40..76f18a99 100644 --- a/tests/auto/controls/data/tst_spinbox.qml +++ b/tests/auto/controls/data/tst_spinbox.qml @@ -120,9 +120,21 @@ TestCase { compare(control.up.indicator.enabled, true) compare(control.down.indicator.enabled, false) + control.value = 30 + compare(control.from, 25) + compare(control.value, 30) + compare(control.up.indicator.enabled, true) + compare(control.down.indicator.enabled, true) + + control.from = 30 + compare(control.from, 30) + compare(control.value, 30) + compare(control.up.indicator.enabled, true) + compare(control.down.indicator.enabled, false) + control.to = 75 compare(control.to, 75) - compare(control.value, 25) + compare(control.value, 30) compare(control.up.indicator.enabled, true) compare(control.down.indicator.enabled, false) @@ -131,7 +143,14 @@ TestCase { compare(control.up.indicator.enabled, true) compare(control.down.indicator.enabled, true) - control.to = 40; + control.to = 50 + compare(control.to, 50) + compare(control.value, 50) + compare(control.up.indicator.enabled, false) + compare(control.down.indicator.enabled, true) + + control.to = 40 + compare(control.to, 40) compare(control.value, 40) compare(control.up.indicator.enabled, false) compare(control.down.indicator.enabled, true) |