diff options
author | J-P Nurmi <jpnurmi@digia.com> | 2013-11-26 17:30:03 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-12-04 12:51:19 +0100 |
commit | eb69975cbc667d36e56795e2af2761835916e152 (patch) | |
tree | d098a01f5d256f75b4a687e296aa61973fee2d14 /src | |
parent | 79fbed6f38d8d7fea2c7829fe285c8244deab95c (diff) | |
download | qtquickcontrols-eb69975cbc667d36e56795e2af2761835916e152.tar.gz qtquickcontrols-eb69975cbc667d36e56795e2af2761835916e152.tar.bz2 qtquickcontrols-eb69975cbc667d36e56795e2af2761835916e152.zip |
SpinBox: attempt to fixup the input as appropriate
So for example "-0", which is a valid intermediate value, becomes
"0" when the spinbox is accepted (enter) or it loses focus.
Task-number: QTBUG-34774
Change-Id: Ie153294755aae2bf94ba1cb53c40a8fc5f1f5862
Reviewed-by: Liang Qi <liang.qi@digia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/controls/Private/qquickspinboxvalidator.cpp | 14 | ||||
-rw-r--r-- | src/controls/Private/qquickspinboxvalidator_p.h | 3 |
2 files changed, 14 insertions, 3 deletions
diff --git a/src/controls/Private/qquickspinboxvalidator.cpp b/src/controls/Private/qquickspinboxvalidator.cpp index 16db3f08..342ae8c0 100644 --- a/src/controls/Private/qquickspinboxvalidator.cpp +++ b/src/controls/Private/qquickspinboxvalidator.cpp @@ -69,7 +69,7 @@ QQuickSpinBoxValidator::~QQuickSpinBoxValidator() QString QQuickSpinBoxValidator::text() const { - return m_prefix + locale().toString(m_value, 'f', m_validator.decimals()) + m_suffix; + return textFromValue(m_value); } qreal QQuickSpinBoxValidator::value() const @@ -178,7 +178,7 @@ void QQuickSpinBoxValidator::setSuffix(const QString &suffix) void QQuickSpinBoxValidator::fixup(QString &input) const { - input.remove(locale().groupSeparator()); + input = textFromValue(m_value).remove(locale().groupSeparator()); } QValidator::State QQuickSpinBoxValidator::validate(QString &input, int &pos) const @@ -207,8 +207,11 @@ QValidator::State QQuickSpinBoxValidator::validate(QString &input, int &pos) con if (state == QValidator::Acceptable) { bool ok = false; qreal val = locale().toDouble(value, &ok); - if (ok) + if (ok) { const_cast<QQuickSpinBoxValidator *>(this)->setValue(val); + if (input != textFromValue(val)) + state = QValidator::Intermediate; + } } return state; } @@ -229,4 +232,9 @@ void QQuickSpinBoxValidator::decrement() setValue(m_value - m_step); } +QString QQuickSpinBoxValidator::textFromValue(qreal value) const +{ + return m_prefix + locale().toString(value, 'f', m_validator.decimals()) + m_suffix; +} + QT_END_NAMESPACE diff --git a/src/controls/Private/qquickspinboxvalidator_p.h b/src/controls/Private/qquickspinboxvalidator_p.h index 09468fce..2ffac73e 100644 --- a/src/controls/Private/qquickspinboxvalidator_p.h +++ b/src/controls/Private/qquickspinboxvalidator_p.h @@ -107,6 +107,9 @@ Q_SIGNALS: void suffixChanged(); void textChanged(); +protected: + QString textFromValue(qreal value) const; + private: qreal m_value; qreal m_step; |