diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2022-08-04 11:43:09 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2022-08-08 19:38:40 +0200 |
commit | a79de46ac59e045fbbbb8e0490ea6981b041be73 (patch) | |
tree | a516fdec4a4cf19f6e4f0186d5f2c17aff9e888e | |
parent | e2e4428f0ffa79a032f56812dd89f0b8b8af63f9 (diff) |
Don't skip QDoubleConverter's digit-count check for non-whole bound
Using convertDoubleTo() to get a whole number, from which to determine
the number of digits we're allowed before the fractional part, fails
if the double isn't a whole number, which lead to the skip being
checked. Use qFloor() of the double (as this should have as many
digits as the double had before its decimal point, which is what we
care about; qCeil() might round up to a power of ten).
This amends commit ff6d2cb0d5779d81e89d94d65c8d164602fa2567
Fixes: QTBUG-105341
Pick-to: 6.4 6.3 6.2
Change-Id: I4e0105d4602682c59e9830ec9a37556c96db884e
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r-- | src/gui/util/qvalidator.cpp | 6 | ||||
-rw-r--r-- | tests/auto/gui/util/qdoublevalidator/tst_qdoublevalidator.cpp | 1 |
2 files changed, 6 insertions, 1 deletions
diff --git a/src/gui/util/qvalidator.cpp b/src/gui/util/qvalidator.cpp index f71a66c98c..8be08ebd2a 100644 --- a/src/gui/util/qvalidator.cpp +++ b/src/gui/util/qvalidator.cpp @@ -658,7 +658,11 @@ QValidator::State QDoubleValidatorPrivate::validateWithLocale(QString &input, QL if (notation == QDoubleValidator::StandardNotation) { double max = qMax(qAbs(q->b), qAbs(q->t)); qlonglong v; - if (convertDoubleTo(max, &v)) { + // Need a whole number to pass to convertDoubleTo() or it fails. Use + // floor, as max is positive so this has the same number of digits + // before the decimal point, where qCeil() might take us up to a power + // of ten, adding a digit. + if (convertDoubleTo(qFloor(max), &v)) { qlonglong n = pow10(numDigits(v)); // 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 diff --git a/tests/auto/gui/util/qdoublevalidator/tst_qdoublevalidator.cpp b/tests/auto/gui/util/qdoublevalidator/tst_qdoublevalidator.cpp index 7818e83f09..225ac14c7f 100644 --- a/tests/auto/gui/util/qdoublevalidator/tst_qdoublevalidator.cpp +++ b/tests/auto/gui/util/qdoublevalidator/tst_qdoublevalidator.cpp @@ -143,6 +143,7 @@ void tst_QDoubleValidator::validate_data() QTest::newRow("data56") << "C" << 1229.0 << 1231.0 << -1 << QString("123E+") << ITM << INV; QTest::newRow("data57") << "C" << 1229.0 << 1231.0 << -1 << QString("123E+1") << ACC << INV; QTest::newRow("data58") << "C" << 0.0 << 100.0 << -1 << QString("0.0") << ACC << ACC; + QTest::newRow("overlong") << "C" << 0.0 << 99.9 << 2 << QString("1234.0") << 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; |