summaryrefslogtreecommitdiffstats
path: root/src/gui/widgets
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dietrich-de@nokia.com>2010-11-02 16:25:54 (GMT)
committerGabriel de Dietrich <gabriel.dietrich-de@nokia.com>2010-11-02 16:50:17 (GMT)
commit445ef8847979dab72893aab1924d46d0fe1a8a3e (patch)
tree52141d20819c3037b35bd54a1494e738c0f81400 /src/gui/widgets
parent8e2b95b1115bc07f81d0fa22cc2929bb28d3e9bb (diff)
downloadQt-445ef8847979dab72893aab1924d46d0fe1a8a3e.zip
Qt-445ef8847979dab72893aab1924d46d0fe1a8a3e.tar.gz
Qt-445ef8847979dab72893aab1924d46d0fe1a8a3e.tar.bz2
With some locales, QDoubleValidator would not accept "C" locale valid numbers
Locales using dot as thousands delimiter and comma as decimal separator are prone to this error. This is a regression introduced by commit b81b8e43ad57183ed66. Auto-tests included. Reviewed-by: Olivier Task-number: QTBUG_14935
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/qvalidator.cpp45
1 files changed, 27 insertions, 18 deletions
diff --git a/src/gui/widgets/qvalidator.cpp b/src/gui/widgets/qvalidator.cpp
index b75db45..130d091 100644
--- a/src/gui/widgets/qvalidator.cpp
+++ b/src/gui/widgets/qvalidator.cpp
@@ -499,6 +499,8 @@ public:
}
QDoubleValidator::Notation notation;
+
+ QValidator::State validateWithLocale(QString & input, QLocalePrivate::NumberMode numMode, const QLocale &locale) const;
};
@@ -654,42 +656,49 @@ 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);
+}
+
+QValidator::State QDoubleValidatorPrivate::validateWithLocale(QString &input, QLocalePrivate::NumberMode numMode, const QLocale &locale) const
+{
+ Q_Q(const QDoubleValidator);
QByteArray buff;
- if (!locale().d()->validateChars(input, numMode, &buff, dec)) {
- QLocale cl(QLocale::C);
- if (!cl.d()->validateChars(input, numMode, &buff, dec))
- return Invalid;
- }
+ if (!locale.d()->validateChars(input, numMode, &buff, q->dec))
+ return QValidator::Invalid;
if (buff.isEmpty())
- return Intermediate;
+ return QValidator::Intermediate;
- if (b >= 0 && buff.startsWith('-'))
- return Invalid;
+ if (q->b >= 0 && buff.startsWith('-'))
+ return QValidator::Invalid;
- if (t < 0 && buff.startsWith('+'))
- return Invalid;
+ if (q->t < 0 && buff.startsWith('+'))
+ return QValidator::Invalid;
bool ok, overflow;
double i = QLocalePrivate::bytearrayToDouble(buff.constData(), &ok, &overflow);
if (overflow)
- return Invalid;
+ return QValidator::Invalid;
if (!ok)
- return Intermediate;
+ return QValidator::Intermediate;
- if (i >= b && i <= t)
- return Acceptable;
+ if (i >= q->b && i <= q->t)
+ return QValidator::Acceptable;
- if (d->notation == StandardNotation) {
- double max = qMax(qAbs(b), qAbs(t));
+ if (notation == QDoubleValidator::StandardNotation) {
+ double max = qMax(qAbs(q->b), qAbs(q->t));
if (max < LLONG_MAX) {
qlonglong n = pow10(numDigits(qlonglong(max))) - 1;
if (qAbs(i) > n)
- return Invalid;
+ return QValidator::Invalid;
}
}
- return Intermediate;
+ return QValidator::Intermediate;
}