aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2/qquickspinbox.cpp
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2020-08-18 13:48:50 +0200
committerAndy Shaw <andy.shaw@qt.io>2020-09-11 09:58:28 +0200
commit97d2d271233246ed8a0d8930c9110603bf7b03bd (patch)
tree87cb98ab1432042c256e17f9e7529a3f392f84e4 /src/quicktemplates2/qquickspinbox.cpp
parentbb333700054e4c1e699d907e67f4e6be498968a1 (diff)
Update the text when the inputted value is out of range
When the inputted value is out of range but it would be fixed to the previous value then it would not update the text correctly to show the corrected value. This ensures that it is updated as appropriate. Before it would check if the value had actually changed after it had been fixed to the corrected value. So if it was corrected to the original value then it would not see it as having changed. Additionally the displayText also has the original text before the change, so we have to force through an update to ensure the contentItem's text is updated too. Change-Id: Ic38787d0803ab59cd998f4e2871c613f1642e764 Pick-to: 5.15 Fixes: QTBUG-85719 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quicktemplates2/qquickspinbox.cpp')
-rw-r--r--src/quicktemplates2/qquickspinbox.cpp37
1 files changed, 24 insertions, 13 deletions
diff --git a/src/quicktemplates2/qquickspinbox.cpp b/src/quicktemplates2/qquickspinbox.cpp
index d53916e1..f9821626 100644
--- a/src/quicktemplates2/qquickspinbox.cpp
+++ b/src/quicktemplates2/qquickspinbox.cpp
@@ -117,8 +117,8 @@ public:
int effectiveStepSize() const;
- void updateDisplayText();
- void setDisplayText(const QString &displayText);
+ void updateDisplayText(bool modified = false);
+ void setDisplayText(const QString &displayText, bool modified = false);
bool upEnabled() const;
void updateUpEnabled();
@@ -211,24 +211,34 @@ void QQuickSpinBoxPrivate::updateValue()
}
}
+// modified indicates if the value was modified by the user and not programatically
+// this is then passed on to updateDisplayText to indicate that the user has modified
+// the value so it may need to trigger an update of the contentItem's text too
+
bool QQuickSpinBoxPrivate::setValue(int newValue, bool allowWrap, bool modified)
{
Q_Q(QQuickSpinBox);
+ int correctedValue = newValue;
if (q->isComponentComplete())
- newValue = boundValue(newValue, allowWrap);
+ correctedValue = boundValue(newValue, allowWrap);
- if (value == newValue)
+ if (!modified && newValue == correctedValue && newValue == value)
return false;
- value = newValue;
+ const bool emitSignals = (value != correctedValue);
+ value = correctedValue;
- updateDisplayText();
+ updateDisplayText(modified);
updateUpEnabled();
updateDownEnabled();
- emit q->valueChanged();
- if (modified)
- emit q->valueModified();
+ // Only emit the signals if the corrected value is not the same as the
+ // original value to avoid unnecessary updates
+ if (emitSignals) {
+ emit q->valueChanged();
+ if (modified)
+ emit q->valueModified();
+ }
return true;
}
@@ -252,7 +262,7 @@ int QQuickSpinBoxPrivate::effectiveStepSize() const
return from > to ? -1 * stepSize : stepSize;
}
-void QQuickSpinBoxPrivate::updateDisplayText()
+void QQuickSpinBoxPrivate::updateDisplayText(bool modified)
{
Q_Q(QQuickSpinBox);
QString text;
@@ -264,13 +274,14 @@ void QQuickSpinBoxPrivate::updateDisplayText()
} else {
text = locale.toString(value);
}
- setDisplayText(text);
+ setDisplayText(text, modified);
}
-void QQuickSpinBoxPrivate::setDisplayText(const QString &text)
+void QQuickSpinBoxPrivate::setDisplayText(const QString &text, bool modified)
{
Q_Q(QQuickSpinBox);
- if (displayText == text)
+
+ if (!modified && displayText == text)
return;
displayText = text;