From 16d5b5165c2e6fd2b0c66a0d8f1fcedda08d05a1 Mon Sep 17 00:00:00 2001 From: Aurindam Jana Date: Wed, 28 Mar 2012 16:16:28 +0200 Subject: [PATCH] QmlJSInspector: Show root in property inspector Change-Id: I281ef1f74e8d8128b91c426057c4d727a77543a6 Reviewed-by: Kai Koehne --- .../qmljsdebugclient/qmlenginedebugclient.cpp | 7 +++ .../qmljsdebugclient/qmlenginedebugclient.h | 11 +++- .../qmljsinspector/qmljsclientproxy.cpp | 13 +++++ src/plugins/qmljsinspector/qmljsclientproxy.h | 1 + .../qmljscontextcrumblepath.cpp | 2 +- src/plugins/qmljsinspector/qmljsinspector.cpp | 54 +++++++++++++++---- src/plugins/qmljsinspector/qmljsinspector.h | 3 ++ 7 files changed, 79 insertions(+), 12 deletions(-) diff --git a/src/libs/qmljsdebugclient/qmlenginedebugclient.cpp b/src/libs/qmljsdebugclient/qmlenginedebugclient.cpp index 93048adc3ed..2593e4b63eb 100644 --- a/src/libs/qmljsdebugclient/qmlenginedebugclient.cpp +++ b/src/libs/qmljsdebugclient/qmlenginedebugclient.cpp @@ -31,6 +31,8 @@ #include "qmlenginedebugclient.h" +const float CURRENT_SUPPORTED_VERSION = 2.0; + namespace QmlJsDebugClient { struct QmlObjectData { @@ -76,6 +78,10 @@ void QmlEngineDebugClient::decode(QDataStream &ds, { QmlObjectData data; ds >> data; + int parentId = -1; + if (objectName() == QLatin1String("QmlDebugger") && + serviceVersion() >= CURRENT_SUPPORTED_VERSION ) + ds >> parentId; o.m_debugId = data.objectId; o.m_className = data.objectType; o.m_idString = data.idString; @@ -85,6 +91,7 @@ void QmlEngineDebugClient::decode(QDataStream &ds, o.m_source.m_columnNumber = data.columnNumber; o.m_contextDebugId = data.contextId; o.m_needsMoreData = simple; + o.m_parentId = parentId; if (simple) return; diff --git a/src/libs/qmljsdebugclient/qmlenginedebugclient.h b/src/libs/qmljsdebugclient/qmlenginedebugclient.h index 2e3854d224c..a2fa425cba1 100644 --- a/src/libs/qmljsdebugclient/qmlenginedebugclient.h +++ b/src/libs/qmljsdebugclient/qmlenginedebugclient.h @@ -132,10 +132,11 @@ typedef QList QmlDebugEngineReferenceList; class QmlDebugObjectReference { public: - QmlDebugObjectReference() : m_debugId(-1), m_contextDebugId(-1), m_needsMoreData(false) {} - QmlDebugObjectReference(int id) : m_debugId(id), m_contextDebugId(-1), m_needsMoreData(false) {} + QmlDebugObjectReference() : m_debugId(-1), m_parentId(-1), m_contextDebugId(-1), m_needsMoreData(false) {} + QmlDebugObjectReference(int id) : m_debugId(id), m_parentId(-1), m_contextDebugId(-1), m_needsMoreData(false) {} int debugId() const { return m_debugId; } + int parentId() const { return m_parentId; } QString className() const { return m_className; } QString idString() const { return m_idString; } QString name() const { return m_name; } @@ -161,9 +162,15 @@ public: return false; } + bool operator ==(const QmlDebugObjectReference &obj) + { + return m_debugId == obj.debugId(); + } + private: friend class QmlEngineDebugClient; int m_debugId; + int m_parentId; QString m_className; QString m_idString; QString m_name; diff --git a/src/plugins/qmljsinspector/qmljsclientproxy.cpp b/src/plugins/qmljsinspector/qmljsclientproxy.cpp index 858fd1dd917..b8f7960ca81 100644 --- a/src/plugins/qmljsinspector/qmljsclientproxy.cpp +++ b/src/plugins/qmljsinspector/qmljsclientproxy.cpp @@ -510,6 +510,19 @@ void ClientProxy::fetchContextObjectRecursive( } } +void ClientProxy::insertObjectInTreeIfNeeded(const QmlDebugObjectReference &object) +{ + if (!m_rootObjects.contains(object)) + return; + int count = m_rootObjects.count(); + for (int i = 0; i < count; i++) { + if (m_rootObjects[i].parentId() < 0 && m_rootObjects[i].insertObjectInTree(object)) { + m_rootObjects.removeOne(object); + break; + } + } +} + void ClientProxy::onResult(quint32 queryId, const QVariant &value, const QByteArray &type) { if (type == "FETCH_OBJECT_R") { diff --git a/src/plugins/qmljsinspector/qmljsclientproxy.h b/src/plugins/qmljsinspector/qmljsclientproxy.h index bdc48bb8f0f..8bb412de700 100644 --- a/src/plugins/qmljsinspector/qmljsclientproxy.h +++ b/src/plugins/qmljsinspector/qmljsclientproxy.h @@ -97,6 +97,7 @@ public: quint32 fetchContextObject(const QmlDebugObjectReference& obj); void addObjectToTree(const QmlDebugObjectReference &obj); void fetchContextObjectRecursive(const QmlDebugContextReference &context, bool clear); + void insertObjectInTreeIfNeeded(const QmlDebugObjectReference &object); signals: void objectTreeUpdated(); diff --git a/src/plugins/qmljsinspector/qmljscontextcrumblepath.cpp b/src/plugins/qmljsinspector/qmljscontextcrumblepath.cpp index d12e1682e2a..25f055a1612 100644 --- a/src/plugins/qmljsinspector/qmljscontextcrumblepath.cpp +++ b/src/plugins/qmljsinspector/qmljscontextcrumblepath.cpp @@ -52,7 +52,7 @@ void ContextCrumblePath::updateContextPath(const QStringList &path, const QList< m_isEmpty = path.isEmpty(); if (m_isEmpty) { - pushElement(tr("[no context]"), -1); + pushElement(tr("[no context]"), -2); } else { for (int i = 0; i < path.count(); i++) pushElement(path[i], debugIds[i]); diff --git a/src/plugins/qmljsinspector/qmljsinspector.cpp b/src/plugins/qmljsinspector/qmljsinspector.cpp index 9a6116a321f..598980bac51 100644 --- a/src/plugins/qmljsinspector/qmljsinspector.cpp +++ b/src/plugins/qmljsinspector/qmljsinspector.cpp @@ -378,8 +378,8 @@ void InspectorUi::objectTreeReady() selectItems(QList() << m_clientProxy->objectReferenceForId( m_crumblePath->dataForLastIndex().toInt())); - } else if (!m_clientProxy->rootObjectReference().isEmpty()) { - selectItems(m_clientProxy->rootObjectReference()); + } else { + showRoot(); } } @@ -523,24 +523,27 @@ void InspectorUi::reloadQmlViewer() m_clientProxy->reloadQmlViewer(); } -inline QmlDebugObjectReference findParentRecursive( int goalDebugId, - const QList &objectsToSearch) +QmlDebugObjectReference InspectorUi::findParentRecursive( + int goalDebugId, const QList &objectsToSearch) { if (goalDebugId == -1) return QmlDebugObjectReference(); foreach (const QmlDebugObjectReference &possibleParent, objectsToSearch) { // Am I a root object? No parent - if ( possibleParent.debugId() == goalDebugId ) + if ( possibleParent.debugId() == goalDebugId && possibleParent.parentId() < 0) return QmlDebugObjectReference(); // Is the goal one of my children? foreach (const QmlDebugObjectReference &child, possibleParent.children()) - if ( child.debugId() == goalDebugId ) + if ( child.debugId() == goalDebugId ) { + m_clientProxy->insertObjectInTreeIfNeeded(child); return possibleParent; + } // no luck? pass this on - QmlDebugObjectReference candidate = findParentRecursive(goalDebugId, possibleParent.children()); + QmlDebugObjectReference candidate = findParentRecursive( + goalDebugId, possibleParent.children()); if (candidate.debugId() != -1) return candidate; } @@ -605,7 +608,7 @@ void InspectorUi::showObject(const QmlDebugObjectReference &obj) bool InspectorUi::isRoot(const QmlDebugObjectReference &obj) const { foreach (const QmlDebugObjectReference &rootObj, m_clientProxy->rootObjectReference()) - if (obj.debugId() == rootObj.debugId()) + if (obj.debugId() == rootObj.debugId() && obj.parentId() < 0) return true; return false; } @@ -625,6 +628,9 @@ void InspectorUi::populateCrumblePath(const QmlDebugObjectReference &objRef) crumbleData.push_front( ref.debugId() ); crumbleStrings.push_front( displayName(ref) ); } + //Prepend Root + crumbleData.push_front(-1); + crumbleStrings.push_front(QLatin1String("/")); m_crumblePath->updateContextPath(crumbleStrings, crumbleData); crumbleStrings.clear(); @@ -639,6 +645,33 @@ void InspectorUi::populateCrumblePath(const QmlDebugObjectReference &objRef) m_crumblePath->addChildren(crumbleStrings, crumbleData); } +void InspectorUi::showRoot() +{ + QStringList crumbleStrings; + QList crumbleData; + + crumbleData << -1; + crumbleStrings << QLatin1String("/"); + + m_crumblePath->updateContextPath(crumbleStrings, crumbleData); + crumbleStrings.clear(); + crumbleData.clear(); + + // now append the children + foreach (const QmlDebugObjectReference &child, m_clientProxy->rootObjectReference()) { + if (child.parentId() != -1) + continue; + crumbleData.push_back(child.debugId()); + crumbleStrings.push_back( displayName(child) ); + } + + m_crumblePath->addChildren(crumbleStrings, crumbleData); + m_propertyInspector->clear(); + Debugger::QmlAdapter *qmlAdapter = m_clientProxy->qmlAdapter(); + if (qmlAdapter) + qmlAdapter->setCurrentSelectedDebugInfo(-1, QLatin1String("/")); +} + void InspectorUi::selectItems(const QList &objectIds) { QList objectReferences; @@ -776,9 +809,12 @@ void InspectorUi::crumblePathElementClicked(const QVariant &data) { bool ok; const int debugId = data.toInt(&ok); - if (!ok || debugId == -1) + if (!ok || debugId == -2) return; + if (debugId == -1) + return showRoot(); + QList debugIds; debugIds << debugId; diff --git a/src/plugins/qmljsinspector/qmljsinspector.h b/src/plugins/qmljsinspector/qmljsinspector.h index aaa8c7625c3..b2555424a17 100644 --- a/src/plugins/qmljsinspector/qmljsinspector.h +++ b/src/plugins/qmljsinspector/qmljsinspector.h @@ -135,6 +135,7 @@ private slots: void showDebuggerTooltip(const QPoint &mousePos, TextEditor::ITextEditor *editor, int cursorPos); private: + void showRoot(); void resetViews(); void initializeDocuments(); @@ -150,6 +151,8 @@ private: void showObject(const QmlDebugObjectReference &obj); + QmlDebugObjectReference findParentRecursive( + int goalDebugId, const QList &objectsToSearch); private: bool m_listeningToEditorManager; QmlJsInspectorToolBar *m_toolBar;