From fb58845d8f2aa0cffe031d3b16f041dcb61a51f8 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Thu, 14 Dec 2017 21:15:25 +0100 Subject: QItemViews: Add ability to show QJsonValue::Bool/Double MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Q(Tree|Table|List)View was able to display a simple QJsonValue::String, but not QJsonValue::Bool/Double. This is an inconsistent behavior which is fixed with this patch. Task-number: QTBUG-65082 Change-Id: I22c2fe2890f11e283cae4f7ea947aa67ff36f367 Reviewed-by: Friedemann Kleint Reviewed-by: Thorbjørn Lund Martsum Reviewed-by: Richard Moe Gustavsen --- src/widgets/itemviews/qabstractitemdelegate.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/itemviews/qabstractitemdelegate.cpp b/src/widgets/itemviews/qabstractitemdelegate.cpp index 6cb7c8600d..3268fda2fc 100644 --- a/src/widgets/itemviews/qabstractitemdelegate.cpp +++ b/src/widgets/itemviews/qabstractitemdelegate.cpp @@ -58,6 +58,7 @@ #endif #include #include +#include #include #include @@ -588,12 +589,23 @@ QString QAbstractItemDelegatePrivate::textForRole(Qt::ItemDataRole role, const Q case QVariant::DateTime: text = locale.toString(value.toDateTime(), formatType); break; - default: - text = value.toString(); + 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(); + } if (role == Qt::DisplayRole) text.replace(QLatin1Char('\n'), QChar::LineSeparator); break; } + } return text; } -- cgit v1.2.3