diff --git a/src/plugins/clangformat/CMakeLists.txt b/src/plugins/clangformat/CMakeLists.txt index 55812e4cb69..ca735eaafca 100644 --- a/src/plugins/clangformat/CMakeLists.txt +++ b/src/plugins/clangformat/CMakeLists.txt @@ -10,7 +10,7 @@ add_qtc_plugin(ClangFormat clangformatconstants.h clangformatfile.cpp clangformatfile.h clangformatindenter.cpp clangformatindenter.h - clangformatplugin.cpp clangformatplugin.h + clangformatplugin.cpp clangformatsettings.cpp clangformatsettings.h clangformattr.h clangformatutils.cpp clangformatutils.h diff --git a/src/plugins/clangformat/clangformat.qbs b/src/plugins/clangformat/clangformat.qbs index 057035cd1a6..57f39bc5b1e 100644 --- a/src/plugins/clangformat/clangformat.qbs +++ b/src/plugins/clangformat/clangformat.qbs @@ -46,7 +46,6 @@ QtcPlugin { "clangformatindenter.cpp", "clangformatindenter.h", "clangformatplugin.cpp", - "clangformatplugin.h", "clangformatsettings.cpp", "clangformatsettings.h", "clangformattr.h", diff --git a/src/plugins/clangformat/clangformatplugin.cpp b/src/plugins/clangformat/clangformatplugin.cpp index 2272d998e94..7d43a1e23a9 100644 --- a/src/plugins/clangformat/clangformatplugin.cpp +++ b/src/plugins/clangformat/clangformatplugin.cpp @@ -1,8 +1,6 @@ // 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 "clangformatplugin.h" - #include "clangformatconfigwidget.h" #include "clangformatconstants.h" #include "clangformatglobalconfigwidget.h" @@ -21,6 +19,8 @@ #include #include +#include + #include #include @@ -36,7 +36,7 @@ using namespace Utils; namespace ClangFormat { -class ClangFormatStyleFactory : public CppCodeStylePreferencesFactory +class ClangFormatStyleFactory final : public CppCodeStylePreferencesFactory { public: Indenter *createIndenter(QTextDocument *doc) const override @@ -57,37 +57,47 @@ public: } }; -ClangFormatPlugin::~ClangFormatPlugin() +class ClangFormatPlugin final : public ExtensionSystem::IPlugin { - TextEditorSettings::unregisterCodeStyleFactory(CppEditor::Constants::CPP_SETTINGS_ID); - delete m_factory; -} + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "ClangFormat.json") -void ClangFormatPlugin::initialize() -{ - TextEditorSettings::unregisterCodeStyleFactory(CppEditor::Constants::CPP_SETTINGS_ID); - m_factory = new ClangFormatStyleFactory; - TextEditorSettings::registerCodeStyleFactory(m_factory); - - ActionContainer *contextMenu = ActionManager::actionContainer(CppEditor::Constants::M_CONTEXT); - if (contextMenu) { - contextMenu->addSeparator(); - - ActionBuilder openConfig(this, Constants::OPEN_CURRENT_CONFIG_ID); - openConfig.setText(Tr::tr("Open Used .clang-format Configuration File")); - openConfig.addToContainer(CppEditor::Constants::M_CONTEXT); - openConfig.addOnTriggered(this, [] { - if (const IDocument *doc = EditorManager::currentDocument()) { - const FilePath filePath = doc->filePath(); - if (!filePath.isEmpty()) - EditorManager::openEditor(configForFile(filePath)); - } - }); + ~ClangFormatPlugin() final + { + TextEditorSettings::unregisterCodeStyleFactory(CppEditor::Constants::CPP_SETTINGS_ID); + delete m_factory; } + void initialize() final + { + TextEditorSettings::unregisterCodeStyleFactory(CppEditor::Constants::CPP_SETTINGS_ID); + m_factory = new ClangFormatStyleFactory; + TextEditorSettings::registerCodeStyleFactory(m_factory); + + ActionContainer *contextMenu = ActionManager::actionContainer(CppEditor::Constants::M_CONTEXT); + if (contextMenu) { + contextMenu->addSeparator(); + + ActionBuilder openConfig(this, Constants::OPEN_CURRENT_CONFIG_ID); + openConfig.setText(Tr::tr("Open Used .clang-format Configuration File")); + openConfig.addToContainer(CppEditor::Constants::M_CONTEXT); + openConfig.addOnTriggered(this, [] { + if (const IDocument *doc = EditorManager::currentDocument()) { + const FilePath filePath = doc->filePath(); + if (!filePath.isEmpty()) + EditorManager::openEditor(configForFile(filePath)); + } + }); + } + #ifdef WITH_TESTS - addTestCreator(Internal::createClangFormatTest); + addTestCreator(Internal::createClangFormatTest); #endif -} + } + + TextEditor::ICodeStylePreferencesFactory *m_factory = nullptr; +}; } // ClangFormat + +#include "clangformatplugin.moc" diff --git a/src/plugins/clangformat/clangformatplugin.h b/src/plugins/clangformat/clangformatplugin.h deleted file mode 100644 index afb5afbe739..00000000000 --- a/src/plugins/clangformat/clangformatplugin.h +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 - -#pragma once - -#include - -namespace TextEditor { class ICodeStylePreferencesFactory; } - -namespace ClangFormat { - -class ClangFormatPlugin : public ExtensionSystem::IPlugin -{ - Q_OBJECT - Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "ClangFormat.json") - - ~ClangFormatPlugin() override; - void initialize() final; - - TextEditor::ICodeStylePreferencesFactory *m_factory = nullptr; -}; - -} // namespace ClangTools