From 3cb5d02df1f9bce56bb2083530d1dc495c527eb4 Mon Sep 17 00:00:00 2001 From: Kubat <mael.martin31@gmail.com> Date: Mon, 30 Aug 2021 14:12:38 +0200 Subject: [PATCH] UI: The property model takes into account the "ordered QJsonObjects" that are nothing more than QJsonArray with each element being a single QJsonObject --- src/UI/PropertyModel.cc | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/src/UI/PropertyModel.cc b/src/UI/PropertyModel.cc index 568c06ac..fc4d3ea7 100644 --- a/src/UI/PropertyModel.cc +++ b/src/UI/PropertyModel.cc @@ -99,12 +99,34 @@ PropertyModel::Item::fromJson(const QJsonValue &value, PropertyModel::Item *pare } else if (value.isArray()) { - for (int index = 0; const QJsonValue v : value.toArray()) { - Item *child = fromJson(v, root); - child->setKey(QString::number(index)); - child->setType(v.type()); - root->appendChild(child); - ++index; + // With arrays with one object per index, treat them as ordered QJsonObject + bool isOrderedQJsonObject = true; + for (const QJsonValue v : value.toArray()) { + if (!v.isObject() || v.toObject().count() != 1) + isOrderedQJsonObject = false; + } + + if (isOrderedQJsonObject) { + for (const QJsonValue v : value.toArray()) { + // `count == 1` was already checked + const QString key = v.toObject().keys().at(0); + const QJsonValue val = v.toObject().value(key); + + Item *child = fromJson(val, root); + child->setKey(key); + child->setType(val.type()); + root->appendChild(child); + } + } + + else { + for (int index = 0; const QJsonValue v : value.toArray()) { + Item *child = fromJson(v, root); + child->setKey(QString::number(index)); + child->setType(v.type()); + root->appendChild(child); + ++index; + } } } -- GitLab