QValidator: Don't fallback to C Locale when validating input
QIntValidator and QDoubleValidator used to accept C formatted input if the input wasn't valid in the default locale. This change removes this, only the default locale is now used. Change-Id: I8b2d8f9f3849abe3fcb5c12083aae542a76eaf90 Reviewed-by: Jonas Gastal <jgastal@profusion.mobi> Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>
This commit is contained in:
parent
9c1f3bce4d
commit
0436281771
3
dist/changes-5.0.0
vendored
3
dist/changes-5.0.0
vendored
@ -246,6 +246,9 @@ QtCore
|
||||
a valid QDate/QTime.
|
||||
|
||||
|
||||
* QIntValidator and QDoubleValidator no longer fall back to using the C locale if
|
||||
the requested locale fails to validate the input.
|
||||
|
||||
QtGui
|
||||
-----
|
||||
* Accessibility has been refactored. The hierachy of accessible objects is implemented via
|
||||
|
@ -321,9 +321,7 @@ void QValidator::fixup(QString &) const
|
||||
or individually with setBottom() and setTop().
|
||||
|
||||
QIntValidator uses its locale() to interpret the number. For example,
|
||||
in Arabic locales, QIntValidator will accept Arabic digits. In addition,
|
||||
QIntValidator is always guaranteed to accept a number formatted according
|
||||
to the "C" locale.
|
||||
in Arabic locales, QIntValidator will accept Arabic digits.
|
||||
|
||||
\sa QDoubleValidator, QRegExpValidator, {Line Edits Example}
|
||||
*/
|
||||
@ -403,9 +401,7 @@ QValidator::State QIntValidator::validate(QString & input, int&) const
|
||||
{
|
||||
QByteArray buff;
|
||||
if (!locale().d()->validateChars(input, QLocalePrivate::IntegerMode, &buff)) {
|
||||
QLocale cl(QLocale::C);
|
||||
if (!cl.d()->validateChars(input, QLocalePrivate::IntegerMode, &buff))
|
||||
return Invalid;
|
||||
return Invalid;
|
||||
}
|
||||
|
||||
if (buff.isEmpty())
|
||||
@ -444,9 +440,7 @@ void QIntValidator::fixup(QString &input) const
|
||||
{
|
||||
QByteArray buff;
|
||||
if (!locale().d()->validateChars(input, QLocalePrivate::IntegerMode, &buff)) {
|
||||
QLocale cl(QLocale::C);
|
||||
if (!cl.d()->validateChars(input, QLocalePrivate::IntegerMode, &buff))
|
||||
return;
|
||||
return;
|
||||
}
|
||||
bool ok, overflow;
|
||||
qlonglong entered = QLocalePrivate::bytearrayToLongLong(buff.constData(), 10, &ok, &overflow);
|
||||
@ -561,10 +555,6 @@ public:
|
||||
in the German locale, "1,234" will be accepted as the fractional number
|
||||
1.234. In Arabic locales, QDoubleValidator will accept Arabic digits.
|
||||
|
||||
In addition, QDoubleValidator is always guaranteed to accept a number
|
||||
formatted according to the "C" locale. QDoubleValidator will not accept
|
||||
numbers with thousand-separators.
|
||||
|
||||
\sa QIntValidator, QRegExpValidator, {Line Edits Example}
|
||||
*/
|
||||
|
||||
@ -658,11 +648,7 @@ QValidator::State QDoubleValidator::validate(QString & input, int &) const
|
||||
break;
|
||||
}
|
||||
|
||||
State currentLocaleValidation = d->validateWithLocale(input, numMode, locale());
|
||||
if (currentLocaleValidation == Acceptable || locale().language() == QLocale::C)
|
||||
return currentLocaleValidation;
|
||||
State cLocaleValidation = d->validateWithLocale(input, numMode, QLocale(QLocale::C));
|
||||
return qMax(currentLocaleValidation, cLocaleValidation);
|
||||
return d->validateWithLocale(input, numMode, locale());
|
||||
}
|
||||
|
||||
QValidator::State QDoubleValidatorPrivate::validateWithLocale(QString &input, QLocalePrivate::NumberMode numMode, const QLocale &locale) const
|
||||
|
@ -76,7 +76,7 @@ void tst_QDoubleValidator::validateThouSep_data()
|
||||
QTest::newRow("1.000de") << "de" << QString("1.000") << ACC;
|
||||
|
||||
QTest::newRow(".C") << "C" << QString(".") << ITM;
|
||||
QTest::newRow(".de") << "de" << QString(".") << ITM;
|
||||
QTest::newRow(".de") << "de" << QString(".") << INV;
|
||||
QTest::newRow(",C") << "C" << QString(",") << INV;
|
||||
QTest::newRow(",de") << "de" << QString(",") << ITM;
|
||||
}
|
||||
@ -173,7 +173,7 @@ void tst_QDoubleValidator::validate_data()
|
||||
QTest::newRow("data_de8") << "de" << -100.0 << 100.0 << 1 << QString("-100") << ACC << ACC;
|
||||
QTest::newRow("data_de9") << "de" << -100.0 << -10.0 << 1 << QString("10") << ITM << ITM;
|
||||
QTest::newRow("data_de10") << "de" << 0.3 << 0.5 << 5 << QString("0,34567") << ACC << ACC;
|
||||
QTest::newRow("data_de11") << "de" << -0.3 << -0.5 << 5 << QString("-0,345678") << ITM << INV;
|
||||
QTest::newRow("data_de11") << "de" << -0.3 << -0.5 << 5 << QString("-0,345678") << INV << INV;
|
||||
QTest::newRow("data_de12") << "de" << -0.32 << 0.32 << 1 << QString("0") << ACC << ACC;
|
||||
QTest::newRow("data_de13") << "de" << 0.0 << 100.0 << 1 << QString("3456a") << INV << INV;
|
||||
QTest::newRow("data_de14") << "de" << -100.0 << 100.0 << 1 << QString("-3456a") << INV << INV;
|
||||
@ -216,12 +216,9 @@ void tst_QDoubleValidator::validate_data()
|
||||
arabicNum += QChar(1636);
|
||||
QTest::newRow("arabic") << "ar" << 0.0 << 20.0 << 2 << arabicNum << ACC << ACC;
|
||||
|
||||
QTest::newRow("data_QTBUG_14935-1") << "de" << 0.0 << 1.0 << 5 << QString("0.31") << ACC << ACC;
|
||||
QTest::newRow("data_QTBUG_14935-2") << "de" << 0.0 << 1000000.0 << 5 << QString("3.123") << ACC << ACC;
|
||||
QTest::newRow("data_QTBUG_14935-3") << "de" << 0.0 << 1000000.0 << 5 << QString("123,345.678") << ACC << ACC;
|
||||
|
||||
QTest::newRow("data_de_problem-1") << "de" << 0.0 << 10.0 << 0 << QString("1.0") << ITM << ITM;
|
||||
QTest::newRow("data_de_problem-2") << "de" << 0.0 << 10.0 << 0 << QString("0.1") << INV << INV;
|
||||
// Confim no fallback to C locale
|
||||
QTest::newRow("data_C1") << "de" << 0.0 << 1000.0 << 2 << QString("1.000,00") << ACC << ACC;
|
||||
QTest::newRow("data_C2") << "de" << 0.0 << 1000.0 << 2 << QString("1,000.00") << INV << INV;
|
||||
}
|
||||
|
||||
void tst_QDoubleValidator::validate()
|
||||
@ -234,9 +231,6 @@ void tst_QDoubleValidator::validate()
|
||||
QFETCH(QValidator::State, scientific_state);
|
||||
QFETCH(QValidator::State, standard_state);
|
||||
|
||||
QEXPECT_FAIL("data_de_problem-1", "To be fixed. See QTBUG-15210.", Abort);
|
||||
QEXPECT_FAIL("data_de_problem-2", "To be fixed. See QTBUG-15210.", Abort);
|
||||
|
||||
QLocale::setDefault(QLocale(localeName));
|
||||
|
||||
QDoubleValidator dv(minimum, maximum, decimals, 0);
|
||||
|
@ -214,6 +214,12 @@ void tst_QIntValidator::validateFrench()
|
||||
QCOMPARE(validator.validate(s, i), QValidator::Intermediate);
|
||||
validator.fixup(s);
|
||||
QCOMPARE(s, validator.locale().toString(1000));
|
||||
|
||||
// Confim no fallback to C locale
|
||||
s = QLatin1String("1,000");
|
||||
QCOMPARE(validator.validate(s, i), QValidator::Invalid);
|
||||
validator.setLocale(QLocale::C);
|
||||
QCOMPARE(validator.validate(s, i), QValidator::Acceptable);
|
||||
}
|
||||
|
||||
void tst_QIntValidator::validate()
|
||||
|
Loading…
Reference in New Issue
Block a user