diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2018-05-25 17:09:46 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2018-05-29 12:55:51 +0000 |
commit | a5ec1097a0e1fe8c18a18ebe6f891329e276d81c (patch) | |
tree | da45e187b79935b7a2a5f8b43b890fd0ec411a6f | |
parent | c6f12991b06c7a5d34c14252ce200f8c4c1b5dc5 (diff) | |
download | qt-creator-a5ec1097a0e1fe8c18a18ebe6f891329e276d81c.tar.gz |
Debugger: Support nested properties in QML inspector
There are various ways to generate nested arrays and objects in the QML
engine debug service. We can easily show them.
Task-number: QTBUG-68474
Change-Id: I3511a3f6f7631de4ab6a9d4b13ba9392ba4173dc
Reviewed-by: hjk <hjk@qt.io>
-rw-r--r-- | src/plugins/debugger/qml/qmlinspectoragent.cpp | 56 |
1 files changed, 49 insertions, 7 deletions
diff --git a/src/plugins/debugger/qml/qmlinspectoragent.cpp b/src/plugins/debugger/qml/qmlinspectoragent.cpp index 0f2d35c78a..72f224db51 100644 --- a/src/plugins/debugger/qml/qmlinspectoragent.cpp +++ b/src/plugins/debugger/qml/qmlinspectoragent.cpp @@ -381,6 +381,51 @@ void QmlInspectorAgent::newObject(int engineId, int /*objectId*/, int /*parentId m_delayQueryTimer.start(); } +static void sortChildrenIfNecessary(WatchItem *propertiesWatch) +{ + if (boolSetting(SortStructMembers)) { + propertiesWatch->sortChildren([](const WatchItem *item1, const WatchItem *item2) { + return item1->name < item2->name; + }); + } +} + +static bool insertChildren(WatchItem *parent, const QVariant &value) +{ + switch (value.type()) { + case QVariant::Map: { + const QVariantMap map = value.toMap(); + for (auto it = map.begin(), end = map.end(); it != end; ++it) { + WatchItem *child = new WatchItem; + child->name = it.key(); + child->value = it.value().toString(); + child->type = QLatin1String(it.value().typeName()); + child->valueEditable = false; + child->wantsChildren = insertChildren(child, it.value()); + parent->appendChild(child); + } + sortChildrenIfNecessary(parent); + return true; + } + case QVariant::List: { + const QVariantList list = value.toList(); + for (int i = 0, end = list.size(); i != end; ++i) { + WatchItem *child = new WatchItem; + const QVariant &value = list.at(i); + child->arrayIndex = i; + child->value = value.toString(); + child->type = QLatin1String(value.typeName()); + child->valueEditable = false; + child->wantsChildren = insertChildren(child, value); + parent->appendChild(child); + } + return true; + } + default: + return false; + } +} + void QmlInspectorAgent::onValueChanged(int debugId, const QByteArray &propertyName, const QVariant &value) { @@ -392,6 +437,8 @@ void QmlInspectorAgent::onValueChanged(int debugId, const QByteArray &propertyNa << value.toString(); if (WatchItem *item = watchHandler->findItem(iname)) { item->value = value.toString(); + item->removeChildren(); + item->wantsChildren = insertChildren(item, value); item->update(); } } @@ -658,16 +705,11 @@ void QmlInspectorAgent::addWatchData(const ObjectReference &obj, propertyWatch->exp = propertyName; propertyWatch->type = property.valueTypeName(); propertyWatch->value = property.value().toString(); - propertyWatch->wantsChildren = false; + propertyWatch->wantsChildren = insertChildren(propertyWatch, property.value()); propertiesWatch->appendChild(propertyWatch); } - if (boolSetting(SortStructMembers)) { - propertiesWatch->sortChildren([](const WatchItem *item1, const WatchItem *item2) { - return item1->name < item2->name; - }); - } - + sortChildrenIfNecessary(propertiesWatch); m_qmlEngine->watchHandler()->insertItem(propertiesWatch); } |