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>bb10
parent
faff43348b
commit
5944c2503c
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue