diff --git a/src/plugins/qmljsinspector/qmljsinspector.cpp b/src/plugins/qmljsinspector/qmljsinspector.cpp index 3759f2ab504d0d197e9bd773f1495276fee8ad3f..76c53c7ff5c6b108cb9a6a0dddbce7f90711f91e 100644 --- a/src/plugins/qmljsinspector/qmljsinspector.cpp +++ b/src/plugins/qmljsinspector/qmljsinspector.cpp @@ -143,7 +143,6 @@ Inspector::Inspector(QObject *parent) connect(m_clientProxy, SIGNAL(aboutToReloadEngines()), SLOT(aboutToReloadEngines())); connect(m_clientProxy, SIGNAL(enginesChanged()), SLOT(updateEngineList())); connect(m_clientProxy, SIGNAL(aboutToDisconnect()), SLOT(disconnectWidgets())); - connect(m_clientProxy, SIGNAL(objectTreeUpdated(QDeclarativeDebugObjectReference)), SLOT(objectTreeUpdated(QDeclarativeDebugObjectReference))); connect(Debugger::DebuggerPlugin::instance(), SIGNAL(stateChanged(int)), this, SLOT(debuggerStateChanged(int))); @@ -569,66 +568,3 @@ bool Inspector::addQuotesForData(const QVariant &value) const return false; } - -/*! - 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); - } -} - -void QmlJSInspector::Internal::Inspector::objectTreeUpdated(const QDeclarativeDebugObjectReference &ref) -{ - 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 = ref; - QString filename = doc->fileName(); - visitor.filename = filename; - doc->qmlProgram()->accept(&visitor); - allDebugIds[filename] = visitor.result; - } - - //FIXME - m_textPreview->m_initialTable = allDebugIds; - m_textPreview->m_debugIds.clear(); -} diff --git a/src/plugins/qmljsinspector/qmljsinspector.h b/src/plugins/qmljsinspector/qmljsinspector.h index ac8de8f6362fd185ee62b14ddcb586c505aa94a3..ea35ef0807c6bb4f292659609e66934ae6968dab 100644 --- a/src/plugins/qmljsinspector/qmljsinspector.h +++ b/src/plugins/qmljsinspector/qmljsinspector.h @@ -117,8 +117,6 @@ private slots: void disconnectWidgets(); void disconnected(); - void objectTreeUpdated(const QDeclarativeDebugObjectReference &ref); - private: Debugger::DebuggerRunControl *createDebuggerRunControl(ProjectExplorer::RunConfiguration *runConfig, const QString &executableFile = QString(), diff --git a/src/plugins/qmljsinspector/qmljslivetextpreview.cpp b/src/plugins/qmljsinspector/qmljslivetextpreview.cpp index 0858ed592546657adfa4e106b823c0d32779ad57..242c7be11f62a5411c294504cd8c4cd049203854 100644 --- a/src/plugins/qmljsinspector/qmljslivetextpreview.cpp +++ b/src/plugins/qmljsinspector/qmljslivetextpreview.cpp @@ -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()); diff --git a/src/plugins/qmljsinspector/qmljslivetextpreview.h b/src/plugins/qmljsinspector/qmljslivetextpreview.h index 6df8b139721adba33f643231c4462ddb6ecc9052..a5e060bc937432ab028e5abbabc4b10f9fcd441a 100644 --- a/src/plugins/qmljsinspector/qmljslivetextpreview.h +++ b/src/plugins/qmljsinspector/qmljslivetextpreview.h @@ -50,6 +50,7 @@ private slots: void changeSelectedElements(QList<int> offsets, const QString &wordAtCursor); void documentChanged(QmlJS::Document::Ptr doc); void setEditor(Core::IEditor *editor); + void updateDebugIds(const QDeclarativeDebugObjectReference &rootReference); private: QList<QDeclarativeDebugObjectReference > objectReferencesForOffset(quint32 offset) const;