Make QTextStream use group separators in floating-point numbers
Like for integers, this is activated only on QLocales other than C. [ChangeLog][QtCore][QTextStream] QTextStream now uses group separators when writing floating-point numbers when the locale is not the C locale. The old behavior can be restored by setting QLocale::OmitGroupSeparator on the locale. Change-Id: Ie451b91017746c3a9b11b6211b2ddd09cd295cd2 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com> Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
This commit is contained in:
parent
8a031696a1
commit
1d111091b5
@ -2414,6 +2414,8 @@ QTextStream &QTextStream::operator<<(double f)
|
||||
flags |= QLocaleData::CapitalEorX;
|
||||
if (numberFlags() & ForcePoint)
|
||||
flags |= QLocaleData::Alternate;
|
||||
if (locale() != QLocale::c() && !(locale().numberOptions() & QLocale::OmitGroupSeparator))
|
||||
flags |= QLocaleData::ThousandsGroup;
|
||||
|
||||
const QLocaleData *dd = d->locale.d->m_data;
|
||||
QString num = dd->doubleToString(f, d->params.realNumberPrecision, form, -1, flags);
|
||||
|
@ -1788,8 +1788,6 @@ void tst_QTextStream::writeSeekWriteNoBOM()
|
||||
QCOMPARE(out16.buffer(), first);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
void tst_QTextStream::generateOperatorCharData(bool for_QString)
|
||||
{
|
||||
@ -2304,12 +2302,14 @@ void tst_QTextStream::generateRealNumbersDataWrite()
|
||||
{
|
||||
QTest::addColumn<double>("number");
|
||||
QTest::addColumn<QByteArray>("data");
|
||||
QTest::addColumn<QByteArray>("dataWithSeparators");
|
||||
|
||||
QTest::newRow("0") << 0.0 << QByteArray("0");
|
||||
QTest::newRow("3.14") << 3.14 << QByteArray("3.14");
|
||||
QTest::newRow("-3.14") << -3.14 << QByteArray("-3.14");
|
||||
QTest::newRow("1.2e+10") << 1.2e+10 << QByteArray("1.2e+10");
|
||||
QTest::newRow("-1.2e+10") << -1.2e+10 << QByteArray("-1.2e+10");
|
||||
QTest::newRow("0") << 0.0 << QByteArray("0") << QByteArray("0");
|
||||
QTest::newRow("3.14") << 3.14 << QByteArray("3.14") << QByteArray("3.14");
|
||||
QTest::newRow("-3.14") << -3.14 << QByteArray("-3.14") << QByteArray("-3.14");
|
||||
QTest::newRow("1.2e+10") << 1.2e+10 << QByteArray("1.2e+10") << QByteArray("1.2e+10");
|
||||
QTest::newRow("-1.2e+10") << -1.2e+10 << QByteArray("-1.2e+10") << QByteArray("-1.2e+10");
|
||||
QTest::newRow("12345") << 12345. << QByteArray("12345") << QByteArray("12,345");
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
@ -2320,14 +2320,22 @@ void tst_QTextStream::generateRealNumbersDataWrite()
|
||||
{ \
|
||||
QFETCH(double, number); \
|
||||
QFETCH(QByteArray, data); \
|
||||
QFETCH(QByteArray, dataWithSeparators); \
|
||||
\
|
||||
QBuffer buffer; \
|
||||
buffer.open(QBuffer::WriteOnly); \
|
||||
QTextStream stream(&buffer); \
|
||||
stream.setLocale(QLocale::c()); \
|
||||
float f = (float)number; \
|
||||
stream << f; \
|
||||
stream.flush(); \
|
||||
QCOMPARE(buffer.data().constData(), data.constData()); \
|
||||
\
|
||||
buffer.reset(); \
|
||||
stream.setLocale(QLocale("en-US")); \
|
||||
stream << f; \
|
||||
stream.flush(); \
|
||||
QCOMPARE(buffer.data(), dataWithSeparators); \
|
||||
}
|
||||
IMPLEMENT_STREAM_LEFT_REAL_OPERATOR_TEST(float, float)
|
||||
IMPLEMENT_STREAM_LEFT_REAL_OPERATOR_TEST(double, float)
|
||||
|
Loading…
x
Reference in New Issue
Block a user