summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2018-06-30 20:00:19 +0200
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2018-08-04 19:31:28 +0000
commit5944c2503c8515903dae3a0400fd50a8eafa8276 (patch)
treed224151c8bd58a18ac8c4994318da347952f79a5 /src/widgets
parentfaff43348bfae5cfc709fabe9d2698fc3063c050 (diff)
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 <richard.gustavsen@qt.io>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/itemviews/qabstractitemdelegate.cpp25
1 files 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<QJsonValue>()) {
- 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;