diff options
author | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2017-12-14 21:15:25 +0100 |
---|---|---|
committer | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2018-01-03 07:53:26 +0000 |
commit | fb58845d8f2aa0cffe031d3b16f041dcb61a51f8 (patch) | |
tree | 8360ba505ede34a265d4e48868765103a7c732f2 /src/widgets | |
parent | 41b4e154d617a820cd7f7f732838647425a58227 (diff) |
QItemViews: Add ability to show QJsonValue::Bool/Double
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 <Friedemann.Kleint@qt.io>
Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/itemviews/qabstractitemdelegate.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
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 <qapplication.h> #include <qvalidator.h> +#include <qjsonvalue.h> #include <private/qtextengine_p.h> #include <private/qabstractitemdelegate_p.h> @@ -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<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(); + } if (role == Qt::DisplayRole) text.replace(QLatin1Char('\n'), QChar::LineSeparator); break; } + } return text; } |