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 Change-Id: I4e0105d4602682c59e9830ec9a37556c96db884e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit a79de46ac59e045fbbbb8e0490ea6981b041be73) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
02163f6b11
commit
590d01c36c
@ -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
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user