forked from qt-creator/qt-creator
Moved debug id -> AST mapping code to livepreview class
This commit is contained in:
@@ -23,12 +23,59 @@ using namespace QmlJS::AST;
|
||||
namespace QmlJSInspector {
|
||||
namespace Internal {
|
||||
|
||||
/*!
|
||||
Associates the UiObjectMember* to their QDeclarativeDebugObjectReference.
|
||||
*/
|
||||
class MapObjectWithDebugReference : public Visitor
|
||||
{
|
||||
public:
|
||||
virtual void endVisit(UiObjectDefinition *ast) ;
|
||||
virtual void endVisit(UiObjectBinding *ast) ;
|
||||
|
||||
QDeclarativeDebugObjectReference root;
|
||||
QString filename;
|
||||
QHash<UiObjectMember *, QList<QDeclarativeDebugObjectReference> > result;
|
||||
private:
|
||||
void processRecursive(const QDeclarativeDebugObjectReference &object, UiObjectMember *ast);
|
||||
};
|
||||
|
||||
void MapObjectWithDebugReference::endVisit(UiObjectDefinition* ast)
|
||||
{
|
||||
if (ast->qualifiedTypeNameId->name->asString().at(0).isUpper())
|
||||
processRecursive(root, ast);
|
||||
}
|
||||
void MapObjectWithDebugReference::endVisit(UiObjectBinding* ast)
|
||||
{
|
||||
if (ast->qualifiedId->name->asString().at(0).isUpper())
|
||||
processRecursive(root, ast);
|
||||
}
|
||||
|
||||
void MapObjectWithDebugReference::processRecursive(const QDeclarativeDebugObjectReference& object, UiObjectMember* ast)
|
||||
{
|
||||
// If this is too slow, it can be speed up by indexing
|
||||
// the QDeclarativeDebugObjectReference by filename/loc in a fist pass
|
||||
|
||||
SourceLocation loc = ast->firstSourceLocation();
|
||||
if (object.source().lineNumber() == int(loc.startLine) && object.source().columnNumber() == int(loc.startColumn) && object.source().url().toLocalFile() == filename) {
|
||||
result[ast] += object;
|
||||
}
|
||||
|
||||
foreach (const QDeclarativeDebugObjectReference &it, object.children()) {
|
||||
processRecursive(it, ast);
|
||||
}
|
||||
}
|
||||
|
||||
QmlJSLiveTextPreview::QmlJSLiveTextPreview(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
Core::EditorManager *editorManager = Core::EditorManager::instance();
|
||||
connect(editorManager->instance(), SIGNAL(currentEditorChanged(Core::IEditor*)),
|
||||
ClientProxy *clientProxy = ClientProxy::instance();
|
||||
connect(editorManager->instance(),
|
||||
SIGNAL(currentEditorChanged(Core::IEditor*)),
|
||||
SLOT(setEditor(Core::IEditor*)));
|
||||
connect(clientProxy,
|
||||
SIGNAL(objectTreeUpdated(QDeclarativeDebugObjectReference)),
|
||||
SLOT(updateDebugIds(QDeclarativeDebugObjectReference)));
|
||||
}
|
||||
|
||||
QmlJS::ModelManagerInterface *QmlJSLiveTextPreview::modelManager()
|
||||
@@ -132,6 +179,26 @@ void QmlJSLiveTextPreview::setEditor(Core::IEditor *editor)
|
||||
}
|
||||
}
|
||||
|
||||
void QmlJSLiveTextPreview::updateDebugIds(const QDeclarativeDebugObjectReference &rootReference)
|
||||
{
|
||||
QmlJS::ModelManagerInterface *m = QmlJS::ModelManagerInterface::instance();
|
||||
Snapshot snapshot = m->snapshot();
|
||||
QHash<QString, QHash<UiObjectMember *, QList< QDeclarativeDebugObjectReference> > > allDebugIds;
|
||||
foreach(const Document::Ptr &doc, snapshot) {
|
||||
if (!doc->qmlProgram())
|
||||
continue;
|
||||
MapObjectWithDebugReference visitor;
|
||||
visitor.root = rootReference;
|
||||
QString filename = doc->fileName();
|
||||
visitor.filename = filename;
|
||||
doc->qmlProgram()->accept(&visitor);
|
||||
allDebugIds[filename] = visitor.result;
|
||||
}
|
||||
|
||||
m_initialTable = allDebugIds;
|
||||
m_debugIds.clear();
|
||||
}
|
||||
|
||||
void QmlJSLiveTextPreview::documentChanged(QmlJS::Document::Ptr doc)
|
||||
{
|
||||
Core::ICore *core = Core::ICore::instance();
|
||||
@@ -140,7 +207,9 @@ void QmlJSLiveTextPreview::documentChanged(QmlJS::Document::Ptr doc)
|
||||
if (!core->hasContext(dbgcontext))
|
||||
return;
|
||||
|
||||
if (doc && m_previousDoc && doc->fileName() == m_previousDoc->fileName() && doc->qmlProgram() && m_previousDoc->qmlProgram()) {
|
||||
if (doc && m_previousDoc && doc->fileName() == m_previousDoc->fileName()
|
||||
&& doc->qmlProgram() && m_previousDoc->qmlProgram())
|
||||
{
|
||||
if (m_debugIds.isEmpty())
|
||||
m_debugIds = m_initialTable.value(doc->fileName());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user