Observe QLocale::RejectGroupSeparator in QInt/DoubleValidator.
Pass it as additional boolean parameter to QLocaleData::validateChars(). Task-number: QTBUG-42522 Change-Id: I4b2367f4e2fdcbd17e343d215edad57e6687697a Reviewed-by: Mitch Curtis <mitch.curtis@digia.com>
This commit is contained in:
parent
aef2ed9108
commit
94e40c7c78
@ -3144,7 +3144,7 @@ bool QLocaleData::numberToCLocale(const QChar *str, int len,
|
||||
}
|
||||
|
||||
bool QLocaleData::validateChars(const QString &str, NumberMode numMode, QByteArray *buff,
|
||||
int decDigits) const
|
||||
int decDigits, bool rejectGroupSeparators) const
|
||||
{
|
||||
buff->clear();
|
||||
buff->reserve(str.length());
|
||||
@ -3205,7 +3205,7 @@ bool QLocaleData::validateChars(const QString &str, NumberMode numMode, QByteArr
|
||||
|
||||
case ',':
|
||||
//it can only be placed after a digit which is before the decimal point
|
||||
if (!lastWasDigit || decPointCnt > 0)
|
||||
if (rejectGroupSeparators || !lastWasDigit || decPointCnt > 0)
|
||||
return false;
|
||||
break;
|
||||
|
||||
|
@ -251,7 +251,9 @@ public:
|
||||
inline char digitToCLocale(QChar c) const;
|
||||
|
||||
// this function is used in QIntValidator (QtGui)
|
||||
Q_CORE_EXPORT bool validateChars(const QString &str, NumberMode numMode, QByteArray *buff, int decDigits = -1) const;
|
||||
Q_CORE_EXPORT bool validateChars(const QString &str, NumberMode numMode,
|
||||
QByteArray *buff, int decDigits = -1,
|
||||
bool rejectGroupSeparators = false) const;
|
||||
|
||||
public:
|
||||
quint16 m_language_id, m_script_id, m_country_id;
|
||||
|
@ -398,7 +398,8 @@ static qlonglong pow10(int exp)
|
||||
QValidator::State QIntValidator::validate(QString & input, int&) const
|
||||
{
|
||||
QByteArray buff;
|
||||
if (!locale().d->m_data->validateChars(input, QLocaleData::IntegerMode, &buff)) {
|
||||
if (!locale().d->m_data->validateChars(input, QLocaleData::IntegerMode, &buff,
|
||||
-1, locale().numberOptions() & QLocale::RejectGroupSeparator)) {
|
||||
return Invalid;
|
||||
}
|
||||
|
||||
@ -437,7 +438,8 @@ QValidator::State QIntValidator::validate(QString & input, int&) const
|
||||
void QIntValidator::fixup(QString &input) const
|
||||
{
|
||||
QByteArray buff;
|
||||
if (!locale().d->m_data->validateChars(input, QLocaleData::IntegerMode, &buff)) {
|
||||
if (!locale().d->m_data->validateChars(input, QLocaleData::IntegerMode, &buff,
|
||||
-1, locale().numberOptions() & QLocale::RejectGroupSeparator)) {
|
||||
return;
|
||||
}
|
||||
bool ok, overflow;
|
||||
@ -658,8 +660,10 @@ QValidator::State QDoubleValidatorPrivate::validateWithLocale(QString &input, QL
|
||||
{
|
||||
Q_Q(const QDoubleValidator);
|
||||
QByteArray buff;
|
||||
if (!locale.d->m_data->validateChars(input, numMode, &buff, q->dec))
|
||||
if (!locale.d->m_data->validateChars(input, numMode, &buff, q->dec,
|
||||
locale.numberOptions() & QLocale::RejectGroupSeparator)) {
|
||||
return QValidator::Invalid;
|
||||
}
|
||||
|
||||
if (buff.isEmpty())
|
||||
return QValidator::Intermediate;
|
||||
|
@ -59,30 +59,39 @@ void tst_QDoubleValidator::validateThouSep_data()
|
||||
{
|
||||
QTest::addColumn<QString>("localeName");
|
||||
QTest::addColumn<QString>("value");
|
||||
QTest::addColumn<bool>("rejectGroupSeparator");
|
||||
QTest::addColumn<QValidator::State>("result");
|
||||
|
||||
QTest::newRow("1,000C") << "C" << QString("1,000") << ACC;
|
||||
QTest::newRow("1.000C") << "C" << QString("1.000") << ACC;
|
||||
QTest::newRow("1,000C") << "C" << QString("1,000") << false << ACC;
|
||||
QTest::newRow("1,000.1C") << "C" << QString("1,000.1") << false << ACC;
|
||||
QTest::newRow("1,000.1C_reject") << "C" << QString("1,000.1") << true << INV;
|
||||
QTest::newRow("1.000C") << "C" << QString("1.000") << false << ACC;
|
||||
|
||||
QTest::newRow("1,000de") << "de" << QString("1,000") << ACC;
|
||||
QTest::newRow("1.000de") << "de" << QString("1.000") << ACC;
|
||||
QTest::newRow("1,000de") << "de" << QString("1,000") << false << ACC;
|
||||
QTest::newRow("1.000de") << "de" << QString("1.000") << false << ACC;
|
||||
|
||||
QTest::newRow(".C") << "C" << QString(".") << ITM;
|
||||
QTest::newRow(".de") << "de" << QString(".") << INV;
|
||||
QTest::newRow(",C") << "C" << QString(",") << INV;
|
||||
QTest::newRow(",de") << "de" << QString(",") << ITM;
|
||||
QTest::newRow(".C") << "C" << QString(".") << false << ITM;
|
||||
QTest::newRow(".de") << "de" << QString(".") << false << INV;
|
||||
QTest::newRow("1.000,1de") << "de" << QString("1.000,1") << false << ACC;
|
||||
QTest::newRow("1.000,1de_reject") << "de" << QString("1.000,1") << true << INV;
|
||||
QTest::newRow(",C") << "C" << QString(",") << false << INV;
|
||||
QTest::newRow(",de") << "de" << QString(",") << false << ITM;
|
||||
}
|
||||
|
||||
void tst_QDoubleValidator::validateThouSep()
|
||||
{
|
||||
QFETCH(QString, localeName);
|
||||
QFETCH(QString, value);
|
||||
QFETCH(bool, rejectGroupSeparator);
|
||||
QFETCH(QValidator::State, result);
|
||||
int dummy = 0;
|
||||
|
||||
QDoubleValidator iv(-10000, 10000, 3, 0);
|
||||
iv.setNotation(QDoubleValidator::ScientificNotation);
|
||||
iv.setLocale(QLocale(localeName));
|
||||
QLocale locale(localeName);
|
||||
if (rejectGroupSeparator)
|
||||
locale.setNumberOptions(QLocale::RejectGroupSeparator);
|
||||
iv.setLocale(locale);
|
||||
|
||||
QCOMPARE(iv.validate(value, dummy), result);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user