summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dist/changes-5.0.03
-rw-r--r--src/gui/util/qvalidator.cpp22
-rw-r--r--tests/auto/widgets/widgets/qdoublevalidator/tst_qdoublevalidator.cpp16
-rw-r--r--tests/auto/widgets/widgets/qintvalidator/tst_qintvalidator.cpp6
4 files changed, 18 insertions, 29 deletions
diff --git a/dist/changes-5.0.0 b/dist/changes-5.0.0
index ae83dddd5b..3874f88032 100644
--- a/dist/changes-5.0.0
+++ b/dist/changes-5.0.0
@@ -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
diff --git a/src/gui/util/qvalidator.cpp b/src/gui/util/qvalidator.cpp
index 619b19157d..faff264723 100644
--- a/src/gui/util/qvalidator.cpp
+++ b/src/gui/util/qvalidator.cpp
@@ -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
diff --git a/tests/auto/widgets/widgets/qdoublevalidator/tst_qdoublevalidator.cpp b/tests/auto/widgets/widgets/qdoublevalidator/tst_qdoublevalidator.cpp
index 23ff419da2..deb8a3bb6f 100644
--- a/tests/auto/widgets/widgets/qdoublevalidator/tst_qdoublevalidator.cpp
+++ b/tests/auto/widgets/widgets/qdoublevalidator/tst_qdoublevalidator.cpp
@@ -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);
diff --git a/tests/auto/widgets/widgets/qintvalidator/tst_qintvalidator.cpp b/tests/auto/widgets/widgets/qintvalidator/tst_qintvalidator.cpp
index 39404c33a8..6aec414ae6 100644
--- a/tests/auto/widgets/widgets/qintvalidator/tst_qintvalidator.cpp
+++ b/tests/auto/widgets/widgets/qintvalidator/tst_qintvalidator.cpp
@@ -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()