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 /src/quicktemplates2 | |
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>
Diffstat (limited to 'src/quicktemplates2')
-rw-r--r-- | src/quicktemplates2/qquickspinbox.cpp | 48 |
1 files changed, 32 insertions, 16 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); } /*! |