forked from qt-creator/qt-creator
QML Live Preview: Find the debug ids of the root nodes
This commit is contained in:
@@ -173,13 +173,25 @@ void QmlJSLiveTextPreview::changeSelectedElements(QList<int> offsets, const QStr
|
||||
emit selectedItemsChanged(selectedReferences);
|
||||
}
|
||||
|
||||
static QList<QDeclarativeDebugObjectReference> findRootObjectRecursive(const QDeclarativeDebugObjectReference &object, const Document::Ptr &doc)
|
||||
{
|
||||
QList<QDeclarativeDebugObjectReference> result;
|
||||
if (object.className() == doc->componentName())
|
||||
result += object;
|
||||
|
||||
foreach (const QDeclarativeDebugObjectReference &it, object.children()) {
|
||||
result += findRootObjectRecursive(it, doc);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void QmlJSLiveTextPreview::updateDebugIds(const QDeclarativeDebugObjectReference &rootReference)
|
||||
{
|
||||
QmlJS::Document::Ptr doc = m_initialDoc;
|
||||
|
||||
if (!doc->qmlProgram())
|
||||
if (!m_initialDoc->qmlProgram())
|
||||
return;
|
||||
|
||||
{ // Map all the object that comes from the document as it has been loaded by the server.
|
||||
const QmlJS::Document::Ptr &doc = m_initialDoc;
|
||||
MapObjectWithDebugReference visitor;
|
||||
visitor.root = rootReference;
|
||||
visitor.filename = doc->fileName();
|
||||
@@ -191,6 +203,19 @@ void QmlJSLiveTextPreview::updateDebugIds(const QDeclarativeDebugObjectReference
|
||||
m_debugIds = delta(doc, m_previousDoc, m_debugIds);
|
||||
}
|
||||
|
||||
const QmlJS::Document::Ptr &doc = m_previousDoc;
|
||||
if (!doc->qmlProgram())
|
||||
return;
|
||||
|
||||
// Map the root nodes of the document.
|
||||
if(doc->qmlProgram()->members && doc->qmlProgram()->members->member) {
|
||||
UiObjectMember* root = doc->qmlProgram()->members->member;
|
||||
QList< QDeclarativeDebugObjectReference > r = findRootObjectRecursive(rootReference, doc);
|
||||
if (!r.isEmpty())
|
||||
m_debugIds[root] += r;
|
||||
}
|
||||
}
|
||||
|
||||
void QmlJSLiveTextPreview::documentChanged(QmlJS::Document::Ptr doc)
|
||||
{
|
||||
if (doc->fileName() != m_previousDoc->fileName())
|
||||
|
Reference in New Issue
Block a user