forked from qt-creator/qt-creator
QmlInspector: Fetch data when needed
Fetch data on demand for 4.x. Since, parentIds are not known, the tree will be reset when new objects are created. Related changes in Qt side: https://codereview.qt-project.org/#change,35982 Task-number: QTCREATORBUG-7779 Change-Id: I8b53604979bbbc2e6f01bc7b785929811a76f398 Reviewed-by: Christiaan Janssen <christiaan.janssen@digia.com>
This commit is contained in:
@@ -98,6 +98,17 @@ void QmlInspectorAgent::assignValue(const WatchData *data,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int parentIdForIname(const QByteArray &iname)
|
||||||
|
{
|
||||||
|
// Extract the parent id
|
||||||
|
int lastIndex = iname.lastIndexOf('.');
|
||||||
|
int secondLastIndex = iname.lastIndexOf('.', lastIndex - 1);
|
||||||
|
int parentId = -1;
|
||||||
|
if (secondLastIndex != -1)
|
||||||
|
parentId = iname.mid(secondLastIndex + 1, lastIndex - secondLastIndex - 1).toInt();
|
||||||
|
return parentId;
|
||||||
|
}
|
||||||
|
|
||||||
void QmlInspectorAgent::updateWatchData(const WatchData &data)
|
void QmlInspectorAgent::updateWatchData(const WatchData &data)
|
||||||
{
|
{
|
||||||
if (debug)
|
if (debug)
|
||||||
@@ -105,6 +116,15 @@ void QmlInspectorAgent::updateWatchData(const WatchData &data)
|
|||||||
|
|
||||||
if (data.id && !m_fetchDataIds.contains(data.id)) {
|
if (data.id && !m_fetchDataIds.contains(data.id)) {
|
||||||
// objects
|
// objects
|
||||||
|
using namespace QmlDebug::Constants;
|
||||||
|
if (m_engineClient->objectName() == QLatin1String(QDECLARATIVE_ENGINE)) {
|
||||||
|
int parentId = parentIdForIname(data.iname);
|
||||||
|
if (parentId != -1) {
|
||||||
|
QList<int> childIds = m_debugIdChildIds.value(parentId);
|
||||||
|
childIds << data.id;
|
||||||
|
m_debugIdChildIds.insert(parentId, childIds);
|
||||||
|
}
|
||||||
|
}
|
||||||
m_fetchDataIds << data.id;
|
m_fetchDataIds << data.id;
|
||||||
fetchObject(data.id);
|
fetchObject(data.id);
|
||||||
}
|
}
|
||||||
@@ -441,10 +461,10 @@ void QmlInspectorAgent::onResult(quint32 queryId, const QVariant &value,
|
|||||||
foreach (QVariant var, objList) {
|
foreach (QVariant var, objList) {
|
||||||
// TODO: check which among the list is the actual
|
// TODO: check which among the list is the actual
|
||||||
// object that needs to be selected.
|
// object that needs to be selected.
|
||||||
objectTreeFetched(qvariant_cast<ObjectReference>(var));
|
insertObjectInTree(qvariant_cast<ObjectReference>(var));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
objectTreeFetched(qvariant_cast<ObjectReference>(value));
|
insertObjectInTree(qvariant_cast<ObjectReference>(value));
|
||||||
}
|
}
|
||||||
} else if (queryId == m_engineQueryId) {
|
} else if (queryId == m_engineQueryId) {
|
||||||
m_engineQueryId = 0;
|
m_engineQueryId = 0;
|
||||||
@@ -456,7 +476,7 @@ void QmlInspectorAgent::onResult(quint32 queryId, const QVariant &value,
|
|||||||
} else if (queryId == m_rootContextQueryId) {
|
} else if (queryId == m_rootContextQueryId) {
|
||||||
m_rootContextQueryId = 0;
|
m_rootContextQueryId = 0;
|
||||||
clearObjectTree();
|
clearObjectTree();
|
||||||
fetchObjectsInContextRecursive(qvariant_cast<ContextReference>(value));
|
updateObjectTree(qvariant_cast<ContextReference>(value));
|
||||||
} else {
|
} else {
|
||||||
emit expressionResult(queryId, value);
|
emit expressionResult(queryId, value);
|
||||||
}
|
}
|
||||||
@@ -584,8 +604,7 @@ void QmlInspectorAgent::fetchContextObjectsForLocation(const QString &file,
|
|||||||
m_objectTreeQueryIds << queryId;
|
m_objectTreeQueryIds << queryId;
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetch the root objects from the context + any child contexts
|
void QmlInspectorAgent::updateObjectTree(const ContextReference &context)
|
||||||
void QmlInspectorAgent::fetchObjectsInContextRecursive(const ContextReference &context)
|
|
||||||
{
|
{
|
||||||
if (debug)
|
if (debug)
|
||||||
qDebug() << __FUNCTION__ << '(' << context << ')';
|
qDebug() << __FUNCTION__ << '(' << context << ')';
|
||||||
@@ -594,22 +613,14 @@ void QmlInspectorAgent::fetchObjectsInContextRecursive(const ContextReference &c
|
|||||||
|| !debuggerCore()->boolSetting(ShowQmlObjectTree))
|
|| !debuggerCore()->boolSetting(ShowQmlObjectTree))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (const ObjectReference & obj, context.objects()) {
|
foreach (const ObjectReference & obj, context.objects())
|
||||||
using namespace QmlDebug::Constants;
|
insertObjectInTree(obj);
|
||||||
// qt <= 4.8.3
|
|
||||||
if (m_engineClient->objectName() == QLatin1String(QDECLARATIVE_ENGINE)) {
|
|
||||||
m_objectTreeQueryIds << m_engineClient->queryObjectRecursive(obj.debugId());
|
|
||||||
} else {
|
|
||||||
// Fetch only root objects for qt > 4.8.3
|
|
||||||
if (obj.parentId() == -1)
|
|
||||||
fetchObject(obj.debugId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
foreach (const ContextReference &child, context.contexts())
|
foreach (const ContextReference &child, context.contexts())
|
||||||
fetchObjectsInContextRecursive(child);
|
updateObjectTree(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlInspectorAgent::objectTreeFetched(const ObjectReference &object)
|
void QmlInspectorAgent::insertObjectInTree(const ObjectReference &object)
|
||||||
{
|
{
|
||||||
if (debug)
|
if (debug)
|
||||||
qDebug() << __FUNCTION__ << '(' << object << ')';
|
qDebug() << __FUNCTION__ << '(' << object << ')';
|
||||||
@@ -737,8 +748,9 @@ void QmlInspectorAgent::buildDebugIdHashRecursive(const ObjectReference &ref)
|
|||||||
m_debugIdLocations.insert(ref.debugId(), FileReference(filePath, lineNum, colNum));
|
m_debugIdLocations.insert(ref.debugId(), FileReference(filePath, lineNum, colNum));
|
||||||
|
|
||||||
// qt <= 4.8.3
|
// qt <= 4.8.3
|
||||||
if (m_newObjectsCreated && m_engineClient->objectName() == QLatin1String(QDECLARATIVE_ENGINE)) {
|
if (m_newObjectsCreated
|
||||||
QList<int> childIds;
|
&& m_engineClient->objectName() == QLatin1String(QDECLARATIVE_ENGINE)) {
|
||||||
|
QList<int> childIds = m_debugIdChildIds.value(ref.debugId());
|
||||||
foreach (const ObjectReference &c, ref.children()) {
|
foreach (const ObjectReference &c, ref.children()) {
|
||||||
childIds << c.debugId();
|
childIds << c.debugId();
|
||||||
}
|
}
|
||||||
@@ -868,10 +880,10 @@ bool QmlInspectorAgent::isConnected() const
|
|||||||
void QmlInspectorAgent::clearObjectTree()
|
void QmlInspectorAgent::clearObjectTree()
|
||||||
{
|
{
|
||||||
// clear view
|
// clear view
|
||||||
m_debuggerEngine->watchHandler()->removeChildren("inspect");
|
m_debuggerEngine->watchHandler()->cleanup();
|
||||||
|
|
||||||
m_objectTreeQueryIds.clear();
|
m_objectTreeQueryIds.clear();
|
||||||
|
m_fetchDataIds.clear();
|
||||||
int old_count = m_debugIdHash.count();
|
int old_count = m_debugIdHash.count();
|
||||||
m_debugIdHash.clear();
|
m_debugIdHash.clear();
|
||||||
m_debugIdHash.reserve(old_count + 1);
|
m_debugIdHash.reserve(old_count + 1);
|
||||||
|
@@ -110,9 +110,9 @@ private slots:
|
|||||||
void onValueChanged(int debugId, const QByteArray &propertyName, const QVariant &value);
|
void onValueChanged(int debugId, const QByteArray &propertyName, const QVariant &value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void fetchObjectsInContextRecursive(const QmlDebug::ContextReference &context);
|
void updateObjectTree(const QmlDebug::ContextReference &context);
|
||||||
|
|
||||||
void objectTreeFetched(const QmlDebug::ObjectReference &result);
|
void insertObjectInTree(const QmlDebug::ObjectReference &result);
|
||||||
|
|
||||||
void buildDebugIdHashRecursive(const QmlDebug::ObjectReference &ref);
|
void buildDebugIdHashRecursive(const QmlDebug::ObjectReference &ref);
|
||||||
QList<WatchData> buildWatchData(const QmlDebug::ObjectReference &obj,
|
QList<WatchData> buildWatchData(const QmlDebug::ObjectReference &obj,
|
||||||
|
Reference in New Issue
Block a user