forked from qt-creator/qt-creator
QML Live Preview: Find the debug ids of the root nodes
This commit is contained in:
@@ -173,22 +173,47 @@ void QmlJSLiveTextPreview::changeSelectedElements(QList<int> offsets, const QStr
|
|||||||
emit selectedItemsChanged(selectedReferences);
|
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)
|
void QmlJSLiveTextPreview::updateDebugIds(const QDeclarativeDebugObjectReference &rootReference)
|
||||||
{
|
{
|
||||||
QmlJS::Document::Ptr doc = m_initialDoc;
|
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();
|
||||||
|
doc->qmlProgram()->accept(&visitor);
|
||||||
|
|
||||||
|
m_debugIds = visitor.result;
|
||||||
|
Delta delta;
|
||||||
|
delta.doNotSendChanges = true;
|
||||||
|
m_debugIds = delta(doc, m_previousDoc, m_debugIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
const QmlJS::Document::Ptr &doc = m_previousDoc;
|
||||||
if (!doc->qmlProgram())
|
if (!doc->qmlProgram())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
MapObjectWithDebugReference visitor;
|
// Map the root nodes of the document.
|
||||||
visitor.root = rootReference;
|
if(doc->qmlProgram()->members && doc->qmlProgram()->members->member) {
|
||||||
visitor.filename = doc->fileName();
|
UiObjectMember* root = doc->qmlProgram()->members->member;
|
||||||
doc->qmlProgram()->accept(&visitor);
|
QList< QDeclarativeDebugObjectReference > r = findRootObjectRecursive(rootReference, doc);
|
||||||
|
if (!r.isEmpty())
|
||||||
m_debugIds = visitor.result;
|
m_debugIds[root] += r;
|
||||||
Delta delta;
|
}
|
||||||
delta.doNotSendChanges = true;
|
|
||||||
m_debugIds = delta(doc, m_previousDoc, m_debugIds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlJSLiveTextPreview::documentChanged(QmlJS::Document::Ptr doc)
|
void QmlJSLiveTextPreview::documentChanged(QmlJS::Document::Ptr doc)
|
||||||
|
Reference in New Issue
Block a user