diff options
author | Ahmad Samir <[email protected]> | 2023-03-18 11:58:05 +0200 |
---|---|---|
committer | Ahmad Samir <[email protected]> | 2023-07-24 00:04:47 +0200 |
commit | f1077737426ca18511cc074186ed180dd2119975 (patch) | |
tree | 56f6b1927c222dffddb0b9acd993cbd24ece2cd4 | |
parent | 3d284d9b8d3430f57a00b742a8e9fa45d633b8d5 (diff) |
QValidator: return State::Intermediate for certain trailing characters
E.g. a group separator, a -/+ sign, or 'e' (exponent). Input ending with
one of these characters now returns Intermediate, as it can become
Acceptable if the user types more characters.
Remove a check from initialResultCheck(), as it's now covered by
QLocaleData::validateChars() checking that the last character in the
buffer is -/+, this works the same if buffer's size is 1.
Extended unittests based on the linked bug report; the other cases for
"last" are already covered by existing unittests.
Task-number: QTBUG-111371
Change-Id: I9b6979c29f07a5f57b040004cd3dbf4e27147c21
Reviewed-by: Edward Welbourne <[email protected]>
-rw-r--r-- | src/corelib/text/qlocale.cpp | 6 | ||||
-rw-r--r-- | src/gui/util/qvalidator.cpp | 3 | ||||
-rw-r--r-- | tests/auto/gui/util/qintvalidator/tst_qintvalidator.cpp | 3 |
3 files changed, 8 insertions, 4 deletions
diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index 0ba597f742f..d15bdd93cd7 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -4297,6 +4297,12 @@ QLocaleData::validateChars(QStringView str, NumberMode numMode, int decDigits, } result.state = ParsingResult::Acceptable; + + // Intermediate if it ends with any character that requires a digit after + // it to be valid e.g. group separator, sign, or exponent + if (last == ',' || last == '-' || last == '+' || last == 'e') + result.state = ParsingResult::Intermediate; + return result; } diff --git a/src/gui/util/qvalidator.cpp b/src/gui/util/qvalidator.cpp index 079c0dedc3d..2a81006657a 100644 --- a/src/gui/util/qvalidator.cpp +++ b/src/gui/util/qvalidator.cpp @@ -377,9 +377,6 @@ std::optional<QValidator::State> initialResultCheck(T min, T max, const ParsingR if (signConflicts) return QValidator::Invalid; - if (buff.size() == 1 && (ch == '-' || ch == '+')) - return QValidator::Intermediate; - if (result.state == ParsingResult::Intermediate) return QValidator::Intermediate; diff --git a/tests/auto/gui/util/qintvalidator/tst_qintvalidator.cpp b/tests/auto/gui/util/qintvalidator/tst_qintvalidator.cpp index 5b0f30cf9a0..756b1a9c014 100644 --- a/tests/auto/gui/util/qintvalidator/tst_qintvalidator.cpp +++ b/tests/auto/gui/util/qintvalidator/tst_qintvalidator.cpp @@ -167,7 +167,8 @@ void tst_QIntValidator::validateFrench() int i; // Grouping separator is a narrow no-break space; QLocale accepts a space as it. QString s = QLatin1String("1 "); - QCOMPARE(validator.validate(s, i), QValidator::Acceptable); + // Shouldn't end with a group separator + QCOMPARE(validator.validate(s, i), QValidator::Intermediate); validator.fixup(s); QCOMPARE(s, s); |