Commit 16d5b516 authored by Aurindam Jana's avatar Aurindam Jana Committed by Kai Koehne
Browse files

QmlJSInspector: Show root in property inspector



Change-Id: I281ef1f74e8d8128b91c426057c4d727a77543a6
Reviewed-by: default avatarKai Koehne <kai.koehne@nokia.com>
parent 250b612d
......@@ -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;
......
......@@ -132,10 +132,11 @@ typedef QList<QmlDebugEngineReference> 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;
......
......@@ -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") {
......
......@@ -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();
......
......@@ -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]);
......
......@@ -378,8 +378,8 @@ void InspectorUi::objectTreeReady()
selectItems(QList<QmlDebugObjectReference>() <<
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<QmlDebugObjectReference > &objectsToSearch)
QmlDebugObjectReference InspectorUi::findParentRecursive(
int goalDebugId, const QList<QmlDebugObjectReference > &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 <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)
{
QList<QmlDebugObjectReference> 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<int> debugIds;
debugIds << debugId;
......
......@@ -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<QmlDebugObjectReference > &objectsToSearch);
private:
bool m_listeningToEditorManager;
QmlJsInspectorToolBar *m_toolBar;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment