QmlJSInspector: Show root in property inspector

Change-Id: I281ef1f74e8d8128b91c426057c4d727a77543a6
Reviewed-by: Kai Koehne <kai.koehne@nokia.com>
This commit is contained in:
Aurindam Jana
2012-03-28 16:16:28 +02:00
committed by Kai Koehne
parent 250b612dd0
commit 16d5b5165c
7 changed files with 79 additions and 12 deletions

View File

@@ -31,6 +31,8 @@
#include "qmlenginedebugclient.h" #include "qmlenginedebugclient.h"
const float CURRENT_SUPPORTED_VERSION = 2.0;
namespace QmlJsDebugClient { namespace QmlJsDebugClient {
struct QmlObjectData { struct QmlObjectData {
@@ -76,6 +78,10 @@ void QmlEngineDebugClient::decode(QDataStream &ds,
{ {
QmlObjectData data; QmlObjectData data;
ds >> data; ds >> data;
int parentId = -1;
if (objectName() == QLatin1String("QmlDebugger") &&
serviceVersion() >= CURRENT_SUPPORTED_VERSION )
ds >> parentId;
o.m_debugId = data.objectId; o.m_debugId = data.objectId;
o.m_className = data.objectType; o.m_className = data.objectType;
o.m_idString = data.idString; o.m_idString = data.idString;
@@ -85,6 +91,7 @@ void QmlEngineDebugClient::decode(QDataStream &ds,
o.m_source.m_columnNumber = data.columnNumber; o.m_source.m_columnNumber = data.columnNumber;
o.m_contextDebugId = data.contextId; o.m_contextDebugId = data.contextId;
o.m_needsMoreData = simple; o.m_needsMoreData = simple;
o.m_parentId = parentId;
if (simple) if (simple)
return; return;

View File

@@ -132,10 +132,11 @@ typedef QList<QmlDebugEngineReference> QmlDebugEngineReferenceList;
class QmlDebugObjectReference class QmlDebugObjectReference
{ {
public: public:
QmlDebugObjectReference() : m_debugId(-1), 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_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 debugId() const { return m_debugId; }
int parentId() const { return m_parentId; }
QString className() const { return m_className; } QString className() const { return m_className; }
QString idString() const { return m_idString; } QString idString() const { return m_idString; }
QString name() const { return m_name; } QString name() const { return m_name; }
@@ -161,9 +162,15 @@ public:
return false; return false;
} }
bool operator ==(const QmlDebugObjectReference &obj)
{
return m_debugId == obj.debugId();
}
private: private:
friend class QmlEngineDebugClient; friend class QmlEngineDebugClient;
int m_debugId; int m_debugId;
int m_parentId;
QString m_className; QString m_className;
QString m_idString; QString m_idString;
QString m_name; QString m_name;

View File

@@ -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) void ClientProxy::onResult(quint32 queryId, const QVariant &value, const QByteArray &type)
{ {
if (type == "FETCH_OBJECT_R") { if (type == "FETCH_OBJECT_R") {

View File

@@ -97,6 +97,7 @@ public:
quint32 fetchContextObject(const QmlDebugObjectReference& obj); quint32 fetchContextObject(const QmlDebugObjectReference& obj);
void addObjectToTree(const QmlDebugObjectReference &obj); void addObjectToTree(const QmlDebugObjectReference &obj);
void fetchContextObjectRecursive(const QmlDebugContextReference &context, bool clear); void fetchContextObjectRecursive(const QmlDebugContextReference &context, bool clear);
void insertObjectInTreeIfNeeded(const QmlDebugObjectReference &object);
signals: signals:
void objectTreeUpdated(); void objectTreeUpdated();

View File

@@ -52,7 +52,7 @@ void ContextCrumblePath::updateContextPath(const QStringList &path, const QList<
m_isEmpty = path.isEmpty(); m_isEmpty = path.isEmpty();
if (m_isEmpty) { if (m_isEmpty) {
pushElement(tr("[no context]"), -1); pushElement(tr("[no context]"), -2);
} else { } else {
for (int i = 0; i < path.count(); i++) for (int i = 0; i < path.count(); i++)
pushElement(path[i], debugIds[i]); pushElement(path[i], debugIds[i]);

View File

@@ -378,8 +378,8 @@ void InspectorUi::objectTreeReady()
selectItems(QList<QmlDebugObjectReference>() << selectItems(QList<QmlDebugObjectReference>() <<
m_clientProxy->objectReferenceForId( m_clientProxy->objectReferenceForId(
m_crumblePath->dataForLastIndex().toInt())); m_crumblePath->dataForLastIndex().toInt()));
} else if (!m_clientProxy->rootObjectReference().isEmpty()) { } else {
selectItems(m_clientProxy->rootObjectReference()); showRoot();
} }
} }
@@ -523,24 +523,27 @@ void InspectorUi::reloadQmlViewer()
m_clientProxy->reloadQmlViewer(); m_clientProxy->reloadQmlViewer();
} }
inline QmlDebugObjectReference findParentRecursive( int goalDebugId, QmlDebugObjectReference InspectorUi::findParentRecursive(
const QList<QmlDebugObjectReference > &objectsToSearch) int goalDebugId, const QList<QmlDebugObjectReference > &objectsToSearch)
{ {
if (goalDebugId == -1) if (goalDebugId == -1)
return QmlDebugObjectReference(); return QmlDebugObjectReference();
foreach (const QmlDebugObjectReference &possibleParent, objectsToSearch) { foreach (const QmlDebugObjectReference &possibleParent, objectsToSearch) {
// Am I a root object? No parent // Am I a root object? No parent
if ( possibleParent.debugId() == goalDebugId ) if ( possibleParent.debugId() == goalDebugId && possibleParent.parentId() < 0)
return QmlDebugObjectReference(); return QmlDebugObjectReference();
// Is the goal one of my children? // Is the goal one of my children?
foreach (const QmlDebugObjectReference &child, possibleParent.children()) foreach (const QmlDebugObjectReference &child, possibleParent.children())
if ( child.debugId() == goalDebugId ) if ( child.debugId() == goalDebugId ) {
m_clientProxy->insertObjectInTreeIfNeeded(child);
return possibleParent; return possibleParent;
}
// no luck? pass this on // no luck? pass this on
QmlDebugObjectReference candidate = findParentRecursive(goalDebugId, possibleParent.children()); QmlDebugObjectReference candidate = findParentRecursive(
goalDebugId, possibleParent.children());
if (candidate.debugId() != -1) if (candidate.debugId() != -1)
return candidate; return candidate;
} }
@@ -605,7 +608,7 @@ void InspectorUi::showObject(const QmlDebugObjectReference &obj)
bool InspectorUi::isRoot(const QmlDebugObjectReference &obj) const bool InspectorUi::isRoot(const QmlDebugObjectReference &obj) const
{ {
foreach (const QmlDebugObjectReference &rootObj, m_clientProxy->rootObjectReference()) foreach (const QmlDebugObjectReference &rootObj, m_clientProxy->rootObjectReference())
if (obj.debugId() == rootObj.debugId()) if (obj.debugId() == rootObj.debugId() && obj.parentId() < 0)
return true; return true;
return false; return false;
} }
@@ -625,6 +628,9 @@ void InspectorUi::populateCrumblePath(const QmlDebugObjectReference &objRef)
crumbleData.push_front( ref.debugId() ); crumbleData.push_front( ref.debugId() );
crumbleStrings.push_front( displayName(ref) ); crumbleStrings.push_front( displayName(ref) );
} }
//Prepend Root
crumbleData.push_front(-1);
crumbleStrings.push_front(QLatin1String("/"));
m_crumblePath->updateContextPath(crumbleStrings, crumbleData); m_crumblePath->updateContextPath(crumbleStrings, crumbleData);
crumbleStrings.clear(); crumbleStrings.clear();
@@ -639,6 +645,33 @@ void InspectorUi::populateCrumblePath(const QmlDebugObjectReference &objRef)
m_crumblePath->addChildren(crumbleStrings, crumbleData); m_crumblePath->addChildren(crumbleStrings, crumbleData);
} }
void InspectorUi::showRoot()
{
QStringList crumbleStrings;
QList <int> 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<int> &objectIds) void InspectorUi::selectItems(const QList<int> &objectIds)
{ {
QList<QmlDebugObjectReference> objectReferences; QList<QmlDebugObjectReference> objectReferences;
@@ -776,9 +809,12 @@ void InspectorUi::crumblePathElementClicked(const QVariant &data)
{ {
bool ok; bool ok;
const int debugId = data.toInt(&ok); const int debugId = data.toInt(&ok);
if (!ok || debugId == -1) if (!ok || debugId == -2)
return; return;
if (debugId == -1)
return showRoot();
QList<int> debugIds; QList<int> debugIds;
debugIds << debugId; debugIds << debugId;

View File

@@ -135,6 +135,7 @@ private slots:
void showDebuggerTooltip(const QPoint &mousePos, TextEditor::ITextEditor *editor, int cursorPos); void showDebuggerTooltip(const QPoint &mousePos, TextEditor::ITextEditor *editor, int cursorPos);
private: private:
void showRoot();
void resetViews(); void resetViews();
void initializeDocuments(); void initializeDocuments();
@@ -150,6 +151,8 @@ private:
void showObject(const QmlDebugObjectReference &obj); void showObject(const QmlDebugObjectReference &obj);
QmlDebugObjectReference findParentRecursive(
int goalDebugId, const QList<QmlDebugObjectReference > &objectsToSearch);
private: private:
bool m_listeningToEditorManager; bool m_listeningToEditorManager;
QmlJsInspectorToolBar *m_toolBar; QmlJsInspectorToolBar *m_toolBar;