diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro index fb8e76952b5..a906d325f31 100644 --- a/src/plugins/plugins.pro +++ b/src/plugins/plugins.pro @@ -258,7 +258,7 @@ plugin_qmldesigner.depends += plugin_cpptools plugin_qmljsinspector.subdir = qmljsinspector plugin_qmljsinspector.depends += plugin_debugger -plugin_qmljsinspector.depends += plugin_qmljseditor +plugin_qmljsinspector.depends += plugin_qmljstools plugin_mercurial.subdir = mercurial plugin_mercurial.depends = plugin_vcsbase diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp index fbab50c1262..8d7a86bef77 100644 --- a/src/plugins/qmljseditor/qmljseditor.cpp +++ b/src/plugins/qmljseditor/qmljseditor.cpp @@ -457,12 +457,9 @@ QmlJSTextEditorWidget::QmlJSTextEditorWidget(QWidget *parent) : m_modelManager(0), m_futureSemanticInfoRevision(0), m_contextPane(0), - m_updateSelectedElements(false), m_findReferences(new FindReferences(this)), m_semanticHighlighter(new SemanticHighlighter(this)) { - qRegisterMetaType("QmlJSTools::SemanticInfo"); - m_semanticInfoUpdater = new SemanticInfoUpdater(this); m_semanticInfoUpdater->start(); @@ -850,15 +847,6 @@ void QmlJSTextEditorWidget::updateUses() m_updateUsesTimer->start(); } -bool QmlJSTextEditorWidget::updateSelectedElements() const -{ - return m_updateSelectedElements; -} - -void QmlJSTextEditorWidget::setUpdateSelectedElements(bool value) -{ - m_updateSelectedElements = value; -} void QmlJSTextEditorWidget::updateUsesNow() { @@ -977,7 +965,7 @@ protected: void QmlJSTextEditorWidget::setSelectedElements() { - if (!m_updateSelectedElements) + if (!receivers(SIGNAL(selectedElementsChanged(QList,QString)))) return; QTextCursor tc = textCursor(); diff --git a/src/plugins/qmljseditor/qmljseditor.h b/src/plugins/qmljseditor/qmljseditor.h index 058ab759197..6b8bd6b1c5f 100644 --- a/src/plugins/qmljseditor/qmljseditor.h +++ b/src/plugins/qmljseditor/qmljseditor.h @@ -92,6 +92,9 @@ class QMLJSEDITOR_EXPORT QmlJSTextEditorWidget : public TextEditor::BaseTextEdit { Q_OBJECT + // used e.g. in qmljsprofiler + Q_PROPERTY(QmlJSTools::SemanticInfo semanticInfo READ semanticInfo) + public: QmlJSTextEditorWidget(QWidget *parent = 0); ~QmlJSTextEditorWidget(); @@ -105,9 +108,6 @@ public: Internal::QmlOutlineModel *outlineModel() const; QModelIndex outlineModelIndex(); - bool updateSelectedElements() const; - void setUpdateSelectedElements(bool value); - static QVector highlighterFormatCategories(); TextEditor::IAssistInterface *createAssistInterface(TextEditor::AssistKind assistKind, @@ -193,7 +193,6 @@ private: QmlJS::IContextPane *m_contextPane; int m_oldCursorPosition; - bool m_updateSelectedElements; FindReferences *m_findReferences; Internal::SemanticHighlighter *m_semanticHighlighter; diff --git a/src/plugins/qmljsinspector/QmlJSInspector.pluginspec.in b/src/plugins/qmljsinspector/QmlJSInspector.pluginspec.in index d1da4351485..98d166e4ee5 100644 --- a/src/plugins/qmljsinspector/QmlJSInspector.pluginspec.in +++ b/src/plugins/qmljsinspector/QmlJSInspector.pluginspec.in @@ -21,6 +21,6 @@ will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. http://qt.nokia.com - + diff --git a/src/plugins/qmljsinspector/qmljsinspector.cpp b/src/plugins/qmljsinspector/qmljsinspector.cpp index 95049e71b26..dcc07ea023f 100644 --- a/src/plugins/qmljsinspector/qmljsinspector.cpp +++ b/src/plugins/qmljsinspector/qmljsinspector.cpp @@ -193,15 +193,33 @@ void InspectorUi::onEngineStateChanged(Debugger::DebuggerState state) m_propertyInspector->reset(); } +// Get semantic info from QmlJSTextEditorWidget +// (we use the meta object system here to avoid having to link +// against qmljseditor) +QmlJSTools::SemanticInfo getSemanticInfo(QPlainTextEdit *qmlJSTextEdit) +{ + QmlJSTools::SemanticInfo info; + QTC_ASSERT(QLatin1String(qmlJSTextEdit->metaObject()->className()) + == QLatin1String("QmlJSEditor::QmlJSTextEditorWidget"), + return info); + QTC_ASSERT(qmlJSTextEdit->metaObject()->indexOfProperty("semanticInfo") != -1, return info); + + info = qmlJSTextEdit->property("semanticInfo").value(); + return info; +} + void InspectorUi::showDebuggerTooltip(const QPoint &mousePos, TextEditor::ITextEditor *editor, int cursorPos) { Q_UNUSED(mousePos); if (m_clientProxy && editor->id() == QmlJSEditor::Constants::C_QMLJSEDITOR_ID) { - QmlJSEditor::QmlJSTextEditorWidget *qmlEditor = - static_cast(editor->widget()); + TextEditor::BaseTextEditor *baseTextEditor = + static_cast(editor); + QPlainTextEdit *editWidget = qobject_cast(baseTextEditor->widget()); - QTextCursor tc(qmlEditor->document()); + QmlJSTools::SemanticInfo semanticInfo = getSemanticInfo(editWidget); + + QTextCursor tc(editWidget->document()); tc.setPosition(cursorPos); tc.movePosition(QTextCursor::StartOfWord); tc.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor); @@ -210,13 +228,13 @@ void InspectorUi::showDebuggerTooltip(const QPoint &mousePos, TextEditor::ITextE QString query; QLatin1Char doubleQuote('"'); - QmlJS::AST::Node *qmlNode = qmlEditor->semanticInfo().astNodeAt(cursorPos); + QmlJS::AST::Node *qmlNode = semanticInfo.astNodeAt(cursorPos); if (!qmlNode) return; QmlDebugObjectReference ref; if (QmlJS::AST::Node *node - = qmlEditor->semanticInfo().declaringMemberNoProperties(cursorPos)) { + = semanticInfo.declaringMemberNoProperties(cursorPos)) { if (QmlJS::AST::UiObjectMember *objMember = node->uiObjectMemberCast()) { ref = m_clientProxy->objectReferenceForLocation( objMember->firstSourceLocation().startLine, @@ -727,11 +745,14 @@ QmlDebugObjectReference InspectorUi::objectReferenceForLocation(const QString &f if (textEditor && m_clientProxy && textEditor->id() == QmlJSEditor::Constants::C_QMLJSEDITOR_ID) { if (cursorPosition == -1) cursorPosition = textEditor->position(); - QmlJSEditor::QmlJSTextEditorWidget *qmlEditor = - static_cast(textEditor->widget()); + TextEditor::BaseTextEditor *baseTextEditor = + static_cast(editor); + QPlainTextEdit *editWidget = qobject_cast(baseTextEditor->widget()); + + QmlJSTools::SemanticInfo semanticInfo = getSemanticInfo(editWidget); if (QmlJS::AST::Node *node - = qmlEditor->semanticInfo().declaringMemberNoProperties(cursorPosition)) { + = semanticInfo.declaringMemberNoProperties(cursorPosition)) { if (QmlJS::AST::UiObjectMember *objMember = node->uiObjectMemberCast()) { return m_clientProxy->objectReferenceForLocation( objMember->firstSourceLocation().startLine, diff --git a/src/plugins/qmljsinspector/qmljsinspector.pro b/src/plugins/qmljsinspector/qmljsinspector.pro index c50cc52088b..f82d39c8106 100644 --- a/src/plugins/qmljsinspector/qmljsinspector.pro +++ b/src/plugins/qmljsinspector/qmljsinspector.pro @@ -42,6 +42,7 @@ RESOURCES += qmljsinspector.qrc include(../../qtcreatorplugin.pri) include(../../libs/qmljsdebugclient/qmljsdebugclient.pri) +include(../../libs/qmleditorwidgets/qmleditorwidgets.pri) include(../../plugins/debugger/debugger.pri) -include(../../plugins/qmljseditor/qmljseditor.pri) +include(../../plugins/qmljstools/qmljstools.pri) diff --git a/src/plugins/qmljsinspector/qmljsinspector.qbs b/src/plugins/qmljsinspector/qmljsinspector.qbs index 08e742744bf..f5dc9516dce 100644 --- a/src/plugins/qmljsinspector/qmljsinspector.qbs +++ b/src/plugins/qmljsinspector/qmljsinspector.qbs @@ -7,14 +7,11 @@ QtcPlugin { Depends { name: "qt"; submodules: ['widgets'] } Depends { name: "Core" } - Depends { name: "ProjectExplorer" } - Depends { name: "QmlProjectManager" } - Depends { name: "TextEditor" } Depends { name: "Debugger" } - Depends { name: "QmlJS" } - Depends { name: "QmlJSEditor" } - Depends { name: "symbianutils" } Depends { name: "LanguageUtils" } + Depends { name: "TextEditor" } + Depends { name: "QmlJS" } + Depends { name: "QmlJSTools" } Depends { name: "QmlEditorWidgets" } Depends { name: "QmlJSDebugClient" } diff --git a/src/plugins/qmljsinspector/qmljslivetextpreview.cpp b/src/plugins/qmljsinspector/qmljslivetextpreview.cpp index 0496e30b485..657c860618e 100644 --- a/src/plugins/qmljsinspector/qmljslivetextpreview.cpp +++ b/src/plugins/qmljsinspector/qmljslivetextpreview.cpp @@ -39,7 +39,6 @@ #include "qmljsinspectorconstants.h" #include -#include #include #include #include @@ -54,6 +53,8 @@ #include +#include + #include using namespace QmlJS; @@ -142,29 +143,34 @@ QmlJS::ModelManagerInterface *QmlJSLiveTextPreview::modelManager() void QmlJSLiveTextPreview::associateEditor(Core::IEditor *editor) { + using namespace TextEditor; if (editor->id() == QmlJSEditor::Constants::C_QMLJSEDITOR_ID) { - QmlJSEditor::QmlJSTextEditorWidget* qmljsEditor = qobject_cast(editor->widget()); - if (qmljsEditor && !m_editors.contains(qmljsEditor)) { - qmljsEditor->setUpdateSelectedElements(true); - m_editors << qmljsEditor; - connect(qmljsEditor, - SIGNAL(selectedElementsChanged(QList,QString)), - SLOT(changeSelectedElements(QList,QString))); + QTC_ASSERT(QLatin1String(editor->widget()->metaObject()->className()) == + QLatin1String("QmlJSEditor::QmlJSTextEditorWidget"), + return); + + BaseTextEditorWidget *editWidget = qobject_cast(editor->widget()); + QTC_ASSERT(editWidget, return); + + if (!m_editors.contains(editWidget)) { + m_editors << editWidget; + if (m_clientProxy.data()) + connect(editWidget, SIGNAL(selectedElementsChanged(QList,QString)), + SLOT(changeSelectedElements(QList,QString))); } } } void QmlJSLiveTextPreview::unassociateEditor(Core::IEditor *oldEditor) { + using namespace TextEditor; if (oldEditor && oldEditor->id() == QmlJSEditor::Constants::C_QMLJSEDITOR_ID) { - QmlJSEditor::QmlJSTextEditorWidget* qmljsEditor = qobject_cast(oldEditor->widget()); - if (qmljsEditor && m_editors.contains(qmljsEditor)) { - m_editors.removeOne(qmljsEditor); - qmljsEditor->setUpdateSelectedElements(false); - disconnect(qmljsEditor, - SIGNAL(selectedElementsChanged(QList,QString)), - this, - SLOT(changeSelectedElements(QList,QString))); + BaseTextEditorWidget *editWidget = qobject_cast(oldEditor->widget()); + QTC_ASSERT(editWidget, return); + + if (m_editors.contains(editWidget)) { + m_editors.removeOne(editWidget); + disconnect(editWidget, 0, this, 0); } } } @@ -593,7 +599,7 @@ void QmlJSLiveTextPreview::documentChanged(QmlJS::Document::Ptr doc) void QmlJSLiveTextPreview::showExperimentalWarning() { - foreach (QWeakPointer editor, m_editors) + foreach (QWeakPointer editor, m_editors) if (editor) { Core::InfoBarEntry info( Constants::INFO_EXPERIMENTAL, @@ -624,7 +630,7 @@ void QmlJSLiveTextPreview::showSyncWarning(UnsyncronizableChangeType unsyncroniz errorMessage.append(tr("You can continue debugging, but behavior can be unexpected.")); - foreach (QWeakPointer editor, m_editors) + foreach (QWeakPointer editor, m_editors) if (editor) editor.data()->editorDocument()->infoBar()->addInfo(Core::InfoBarEntry( QLatin1String(Constants::INFO_OUT_OF_SYNC), errorMessage)); @@ -632,7 +638,7 @@ void QmlJSLiveTextPreview::showSyncWarning(UnsyncronizableChangeType unsyncroniz void QmlJSLiveTextPreview::reloadQmlViewer() { - foreach (QWeakPointer editor, m_editors) + foreach (QWeakPointer editor, m_editors) if (editor) editor.data()->editorDocument()->infoBar()->removeInfo(Constants::INFO_OUT_OF_SYNC); emit reloadQmlViewerRequested(); @@ -640,7 +646,7 @@ void QmlJSLiveTextPreview::reloadQmlViewer() void QmlJSLiveTextPreview::disableLivePreview() { - foreach (QWeakPointer editor, m_editors) + foreach (QWeakPointer editor, m_editors) if (editor) editor.data()->editorDocument()->infoBar()->removeInfo(Constants::INFO_OUT_OF_SYNC); emit disableLivePreviewRequested(); @@ -671,15 +677,15 @@ void QmlJSLiveTextPreview::setClientProxy(ClientProxy *clientProxy) connect(m_clientProxy.data(), SIGNAL(objectTreeUpdated()), SLOT(updateDebugIds())); - foreach (const QWeakPointer &qmlEditor, m_editors) { - if (qmlEditor) - qmlEditor.data()->setUpdateSelectedElements(true); - } + foreach (QWeakPointer editWidget, m_editors) + if (editWidget) + connect(editWidget.data(), SIGNAL(selectedElementsChanged(QList,QString)), + this, SLOT(changeSelectedElements(QList,QString))); } else { - foreach (const QWeakPointer &qmlEditor, m_editors) { - if (qmlEditor) - qmlEditor.data()->setUpdateSelectedElements(false); - } + foreach (QWeakPointer editWidget, m_editors) + if (editWidget) + disconnect(editWidget.data(), SIGNAL(selectedElementsChanged(QList,QString)), + this, SLOT(changeSelectedElements(QList,QString))); } } diff --git a/src/plugins/qmljsinspector/qmljslivetextpreview.h b/src/plugins/qmljsinspector/qmljslivetextpreview.h index 6ada1e56ade..d6a50ffb059 100644 --- a/src/plugins/qmljsinspector/qmljslivetextpreview.h +++ b/src/plugins/qmljsinspector/qmljslivetextpreview.h @@ -35,6 +35,7 @@ #include #include +#include #include #include @@ -50,10 +51,6 @@ namespace QmlJS { class ModelManagerInterface; } -namespace QmlJSEditor { - class QmlJSTextEditorWidget; -} - namespace QmlJSInspector { namespace Internal { @@ -115,7 +112,7 @@ private: QmlJS::Document::Ptr m_initialDoc; //the document that was loaded by the server QString m_filename; - QList > m_editors; + QList > m_editors; bool m_applyChangesToQmlInspector; QmlJS::Document::Ptr m_docWithUnappliedChanges; diff --git a/src/plugins/qmljstools/qmljsmodelmanager.cpp b/src/plugins/qmljstools/qmljsmodelmanager.cpp index ea67158e796..d5e71b54258 100644 --- a/src/plugins/qmljstools/qmljsmodelmanager.cpp +++ b/src/plugins/qmljstools/qmljsmodelmanager.cpp @@ -34,6 +34,7 @@ #include "qmljstoolsconstants.h" #include "qmljsplugindumper.h" #include "qmljsfindexportedcpptypes.h" +#include "qmljssemanticinfo.h" #include #include @@ -130,6 +131,7 @@ ModelManager::ModelManager(QObject *parent): qRegisterMetaType("QmlJS::Document::Ptr"); qRegisterMetaType("QmlJS::LibraryInfo"); + qRegisterMetaType("QmlJSTools::SemanticInfo"); loadQmlTypeDescriptions(); diff --git a/src/plugins/qmljstools/qmljssemanticinfo.h b/src/plugins/qmljstools/qmljssemanticinfo.h index 2a38f7bc836..86eefee6662 100644 --- a/src/plugins/qmljstools/qmljssemanticinfo.h +++ b/src/plugins/qmljstools/qmljssemanticinfo.h @@ -101,4 +101,6 @@ private: } // namespace QmlJSTools +Q_DECLARE_METATYPE(QmlJSTools::SemanticInfo) + #endif // QMLJSSEMANTICINFO_H