diff options
-rw-r--r-- | src/gui/util/qvalidator.cpp | 18 | ||||
-rw-r--r-- | tests/auto/gui/util/qdoublevalidator/tst_qdoublevalidator.cpp | 8 |
2 files changed, 21 insertions, 5 deletions
diff --git a/src/gui/util/qvalidator.cpp b/src/gui/util/qvalidator.cpp index 7982ad967e..2d228bf871 100644 --- a/src/gui/util/qvalidator.cpp +++ b/src/gui/util/qvalidator.cpp @@ -624,10 +624,10 @@ QDoubleValidator::~QDoubleValidator() that is within the valid range and is in the correct format. Returns \l Intermediate if \a input contains a double that is - outside the range or is in the wrong format; e.g. with too many - digits after the decimal point or is empty. + outside the range or is in the wrong format; e.g. is empty. - Returns \l Invalid if the \a input is not a double. + Returns \l Invalid if the \a input is not a double or with too many + digits after the decimal point. Note: If the valid range consists of just positive doubles (e.g. 0.0 to 100.0) and \a input is a negative double then \l Invalid is returned. If notation() @@ -690,8 +690,16 @@ QValidator::State QDoubleValidatorPrivate::validateWithLocale(QString &input, QL 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) + qlonglong n = pow10(numDigits(qlonglong(max))); + // In order to get the highest possible number in the intermediate + // range we need to get 10 to the power of the number of digits + // after the decimal's and subtract that from the top number. + // + // For example, where q->dec == 2 and with a range of 0.0 - 9.0 + // then the minimum possible number is 0.00 and the maximum + // possible is 9.99. Therefore 9.999 and 10.0 should be seen as + // invalid. + if (qAbs(i) > (n - std::pow(10, -q->dec))) return QValidator::Invalid; } } diff --git a/tests/auto/gui/util/qdoublevalidator/tst_qdoublevalidator.cpp b/tests/auto/gui/util/qdoublevalidator/tst_qdoublevalidator.cpp index 4705fc3ed7..012a7e2ce3 100644 --- a/tests/auto/gui/util/qdoublevalidator/tst_qdoublevalidator.cpp +++ b/tests/auto/gui/util/qdoublevalidator/tst_qdoublevalidator.cpp @@ -155,6 +155,10 @@ void tst_QDoubleValidator::validate_data() QTest::newRow("data48") << "C" << 0.0 << 100.0 << 1 << QString("0.0") << ACC << ACC; QTest::newRow("data49") << "C" << 0.0 << 100.0 << 0 << QString(".") << ITM << ITM; QTest::newRow("data50") << "C" << 0.0 << 100.0 << 1 << QString(".") << ITM << ITM; + QTest::newRow("data51") << "C" << 0.0 << 2.0 << 2 << QString("9.99") << ITM << ITM; + QTest::newRow("data52") << "C" << 100.0 << 200.0 << 4 << QString("999.9999") << ITM << ITM; + QTest::newRow("data53") << "C" << 0.0 << 2.0 << 2 << QString("9.9999") << INV << INV; + QTest::newRow("data54") << "C" << 100.0 << 200.0 << 4 << QString("9999.9999") << ITM << INV; QTest::newRow("data_de0") << "de" << 0.0 << 100.0 << 1 << QString("50,0") << ACC << ACC; QTest::newRow("data_de1") << "de" << 00.0 << 100.0 << 1 << QString("500,0") << ITM << ITM; @@ -206,6 +210,10 @@ void tst_QDoubleValidator::validate_data() QTest::newRow("data_de43") << "de" << 0.01 << 0.09 << 2 << QString("0") << ITM << ITM; QTest::newRow("data_de44") << "de" << 0.0 << 10.0 << 1 << QString("11") << ITM << ITM; QTest::newRow("data_de45") << "de" << 0.0 << 10.0 << 2 << QString("11") << ITM << ITM; + QTest::newRow("data_de46") << "de" << 0.0 << 2.0 << 2 << QString("9,99") << ITM << ITM; + QTest::newRow("data_de47") << "de" << 100.0 << 200.0 << 4 << QString("999,9999") << ITM << ITM; + QTest::newRow("data_de48") << "de" << 0.0 << 2.0 << 2 << QString("9,9999") << INV << INV; + QTest::newRow("data_de49") << "de" << 100.0 << 200.0 << 4 << QString("9999,9999") << ITM << INV; QString arabicNum; arabicNum += QChar(1633); // "18.4" in arabic |