From 320a0da060034c40daeadcff49b92ff71d8a2fa2 Mon Sep 17 00:00:00 2001 From: hjk Date: Tue, 16 Jan 2024 12:44:19 +0100 Subject: [PATCH] QmlJsEditor: Work around moc-produced 'using namepace' ... for QmlJsEditor::QmlJsEditor causing ambiguities. Change-Id: If15a0cb0410093857848b871d7f99c84b1b35826 Reviewed-by: Marcus Tillmanns --- src/plugins/qmljseditor/qmljseditor.cpp | 34 +++++++++++++++---- src/plugins/qmljseditor/qmljseditorplugin.cpp | 33 ++++-------------- src/plugins/qmljseditor/qmljseditorplugin.h | 4 +++ 3 files changed, 39 insertions(+), 32 deletions(-) diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp index 53e8b022edb..79d24891c78 100644 --- a/src/plugins/qmljseditor/qmljseditor.cpp +++ b/src/plugins/qmljseditor/qmljseditor.cpp @@ -51,6 +51,7 @@ #include #include #include +#include #include #include @@ -307,11 +308,6 @@ void QmlJSEditorWidget::updateOutlineIndexNow() } } -} // namespace QmlJSEditor - - -namespace QmlJSEditor { - void QmlJSEditorWidget::updateContextPane() { const SemanticInfo info = m_qmlJsEditorDocument->semanticInfo(); @@ -1181,11 +1177,37 @@ QmlJSEditorFactory::QmlJSEditorFactory(Utils::Id _id) | TextEditorActionHandler::FindUsage); } -void QmlJSEditorFactory::decorateEditor(TextEditorWidget *editor) +static void decorateEditor(TextEditorWidget *editor) { editor->textDocument()->resetSyntaxHighlighter([] { return new QmlJSHighlighter(); }); editor->textDocument()->setIndenter(createQmlJsIndenter(editor->textDocument()->document())); editor->setAutoCompleter(new AutoCompleter); } +namespace Internal { + +void inspectElement() +{ + if (auto widget = qobject_cast(EditorManager::currentEditor()->widget())) + widget->inspectElementUnderCursor(); +} + +void showContextPane() +{ + if (auto editor = qobject_cast(EditorManager::currentEditor()->widget())) + editor->showContextPane(); +} + +void setupQmlJSEditor() +{ + static QmlJSEditorFactory theQmlJSEditorFactory; + + TextEditor::SnippetProvider::registerGroup(Constants::QML_SNIPPETS_GROUP_ID, + Tr::tr("QML", "SnippetProvider"), + &decorateEditor); + +} + +} // namespace Internal + } // namespace QmlJSEditor diff --git a/src/plugins/qmljseditor/qmljseditorplugin.cpp b/src/plugins/qmljseditor/qmljseditorplugin.cpp index fe9e38bff7b..e75370ab14d 100644 --- a/src/plugins/qmljseditor/qmljseditorplugin.cpp +++ b/src/plugins/qmljseditor/qmljseditorplugin.cpp @@ -1,8 +1,9 @@ // Copyright (C) 2016 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +#include "qmljseditorplugin.h" + #include "qmljseditingsettingspage.h" -#include "qmljseditor.h" #include "qmljseditorconstants.h" #include "qmljseditordocument.h" #include "qmljseditortr.h" @@ -49,7 +50,6 @@ #include #include -using namespace QmlJSEditor::Constants; using namespace ProjectExplorer; using namespace Core; using namespace Utils; @@ -69,9 +69,7 @@ public: Command *addToolAction(QAction *a, Context &context, Id id, ActionContainer *c1, const QString &keySequence); - void renameUsages(); void reformatFile(); - void showContextPane(); QmlJSQuickFixAssistProvider m_quickFixAssistProvider; QmlTaskManager m_qmlTaskManager; @@ -83,7 +81,6 @@ public: QmlJS::JsonSchemaManager m_jsonManager{ {ICore::userResourcePath("json/").toString(), ICore::resourcePath("json/").toString()}}; - QmlJSEditorFactory m_qmlJSEditorFactory; QmlJSOutlineWidgetFactory m_qmlJSOutlineWidgetFactory; QmlJsEditingSettingsPage m_qmJSEditingSettingsPage; }; @@ -92,10 +89,6 @@ static QmlJSEditorPluginPrivate *dd = nullptr; QmlJSEditorPluginPrivate::QmlJSEditorPluginPrivate() { - TextEditor::SnippetProvider::registerGroup(Constants::QML_SNIPPETS_GROUP_ID, - Tr::tr("QML", "SnippetProvider"), - &QmlJSEditorFactory::decorateEditor); - QmlJS::ModelManagerInterface *modelManager = QmlJS::ModelManagerInterface::instance(); QmllsSettingsManager::instance(); @@ -150,17 +143,15 @@ QmlJSEditorPluginPrivate::QmlJSEditorPluginPrivate() cmd = ActionManager::registerAction(inspectElementAction, Id("QmlJSEditor.InspectElementUnderCursor"), context); - connect(inspectElementAction, &QAction::triggered, [] { - if (auto widget = qobject_cast(EditorManager::currentEditor()->widget())) - widget->inspectElementUnderCursor(); - }); + connect(inspectElementAction, &QAction::triggered, &Internal::inspectElement); + qmlToolsMenu->addAction(cmd); QAction *showQuickToolbar = new QAction(Tr::tr("Show Qt Quick Toolbar"), this); cmd = ActionManager::registerAction(showQuickToolbar, Constants::SHOW_QT_QUICK_HELPER, context); cmd->setDefaultKeySequence(useMacShortcuts ? QKeySequence(Qt::META | Qt::ALT | Qt::Key_Space) : QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_Space)); - connect(showQuickToolbar, &QAction::triggered, this, &QmlJSEditorPluginPrivate::showContextPane); + connect(showQuickToolbar, &QAction::triggered, this, &showContextPane); contextMenu->addAction(cmd); qmlToolsMenu->addAction(cmd); @@ -189,12 +180,6 @@ QmlJS::JsonSchemaManager *jsonManager() return &dd->m_jsonManager; } -void QmlJSEditorPluginPrivate::renameUsages() -{ - if (auto editor = qobject_cast(EditorManager::currentEditor()->widget())) - editor->renameSymbolUnderCursor(); -} - void QmlJSEditorPluginPrivate::reformatFile() { if (m_currentDocument) { @@ -263,12 +248,6 @@ void QmlJSEditorPluginPrivate::reformatFile() } } -void QmlJSEditorPluginPrivate::showContextPane() -{ - if (auto editor = qobject_cast(EditorManager::currentEditor()->widget())) - editor->showContextPane(); -} - Command *QmlJSEditorPluginPrivate::addToolAction(QAction *a, Context &context, Id id, ActionContainer *c1, const QString &keySequence) @@ -350,6 +329,8 @@ class QmlJSEditorPlugin final : public ExtensionSystem::IPlugin void initialize() final { dd = new QmlJSEditorPluginPrivate; + + setupQmlJSEditor(); } void extensionsInitialized() final diff --git a/src/plugins/qmljseditor/qmljseditorplugin.h b/src/plugins/qmljseditor/qmljseditorplugin.h index 1707d2e8027..483e51babe1 100644 --- a/src/plugins/qmljseditor/qmljseditorplugin.h +++ b/src/plugins/qmljseditor/qmljseditorplugin.h @@ -12,4 +12,8 @@ class QmlJSQuickFixAssistProvider; QmlJSQuickFixAssistProvider *quickFixAssistProvider(); QmlJS::JsonSchemaManager *jsonManager(); +void setupQmlJSEditor(); +void inspectElement(); +void showContextPane(); + } // QmlJSEditor::Internal