From 5944c2503c8515903dae3a0400fd50a8eafa8276 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sat, 30 Jun 2018 20:00:19 +0200 Subject: QAbstractItemDelegate: only handle as json when type is QMetaType::QJsonValue Only handle QVariants which has the type QMetaType::QJsonValue as json values. Otherwise other types like e.g. QMetaType::Long/LongLong will also be converted to a QJsonValue and maybe end up being displayed in scientific notation. Task-number: QTBUG-65082 Change-Id: I5d6458cd7e48fec262cda00b584a1a3c45404400 Reviewed-by: Richard Moe Gustavsen --- src/widgets/itemviews/qabstractitemdelegate.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/widgets/itemviews/qabstractitemdelegate.cpp b/src/widgets/itemviews/qabstractitemdelegate.cpp index c9f321c3f6..7bc0ece4b3 100644 --- a/src/widgets/itemviews/qabstractitemdelegate.cpp +++ b/src/widgets/itemviews/qabstractitemdelegate.cpp @@ -599,18 +599,21 @@ QString QAbstractItemDelegatePrivate::textForRole(Qt::ItemDataRole role, const Q case QVariant::DateTime: text = locale.toString(value.toDateTime(), formatType); break; - default: { - if (value.canConvert()) { - const QJsonValue val = value.toJsonValue(); - if (val.isBool()) - text = QVariant(val.toBool()).toString(); - else if (val.isDouble()) - text = locale.toString(val.toDouble(), 'g', precision); - else if (val.isString()) - text = val.toString(); - } else { - text = value.toString(); + case QVariant::Type(QMetaType::QJsonValue): { + const QJsonValue val = value.toJsonValue(); + if (val.isBool()) { + text = QVariant(val.toBool()).toString(); + break; + } + if (val.isDouble()) { + text = locale.toString(val.toDouble(), 'g', precision); + break; } + // val is a string (or null) here + Q_FALLTHROUGH(); + } + default: { + text = value.toString(); if (role == Qt::DisplayRole) text.replace(QLatin1Char('\n'), QChar::LineSeparator); break; -- cgit v1.2.3