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>
This commit is contained in:
Ulf Hermann
2018-05-25 17:09:46 +02:00
parent c6f12991b0
commit a5ec1097a0

View File

@@ -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);
}