aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/designer
diff options
context:
space:
mode:
authorhjk <hjk@qt.io>2024-01-12 18:47:55 +0100
committerhjk <hjk@qt.io>2024-01-15 12:50:49 +0000
commitd5938cf2bc281de87fc2318d4a7fece6437a2478 (patch)
tree11362bec5394994d2cccf329dc2eb6268f4c0fba /src/plugins/designer
parent34fd4e8ebfc972459b72c12e2585e7d58e470916 (diff)
Designer: Hide plugin class definition in .cpp
Change-Id: I722fa069e5bd00b3f5f2cbfbe38c0a2e0247dcb5 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Diffstat (limited to 'src/plugins/designer')
-rw-r--r--src/plugins/designer/CMakeLists.txt2
-rw-r--r--src/plugins/designer/designer.qbs2
-rw-r--r--src/plugins/designer/formeditor.h2
-rw-r--r--src/plugins/designer/formeditorplugin.cpp215
-rw-r--r--src/plugins/designer/formeditorplugin.h37
-rw-r--r--src/plugins/designer/gotoslot_test.cpp28
6 files changed, 132 insertions, 154 deletions
diff --git a/src/plugins/designer/CMakeLists.txt b/src/plugins/designer/CMakeLists.txt
index 581f7ec2a7e..3afdfd04877 100644
--- a/src/plugins/designer/CMakeLists.txt
+++ b/src/plugins/designer/CMakeLists.txt
@@ -46,7 +46,7 @@ add_qtc_plugin(Designer
editordata.h
editorwidget.cpp editorwidget.h
formeditorfactory.cpp formeditorfactory.h
- formeditorplugin.cpp formeditorplugin.h
+ formeditorplugin.cpp
formeditorstack.cpp formeditorstack.h
formeditor.cpp formeditor.h
formtemplatewizardpage.cpp formtemplatewizardpage.h
diff --git a/src/plugins/designer/designer.qbs b/src/plugins/designer/designer.qbs
index bde63fa3eea..2013ccd9f35 100644
--- a/src/plugins/designer/designer.qbs
+++ b/src/plugins/designer/designer.qbs
@@ -53,7 +53,7 @@ QtcPlugin {
"editordata.h",
"editorwidget.cpp", "editorwidget.h",
"formeditorfactory.cpp", "formeditorfactory.h",
- "formeditorplugin.cpp", "formeditorplugin.h",
+ "formeditorplugin.cpp",
"formeditorstack.cpp", "formeditorstack.h",
"formeditor.cpp", "formeditor.h",
"formtemplatewizardpage.cpp", "formtemplatewizardpage.h",
diff --git a/src/plugins/designer/formeditor.h b/src/plugins/designer/formeditor.h
index 875c8e50904..863c6b120c3 100644
--- a/src/plugins/designer/formeditor.h
+++ b/src/plugins/designer/formeditor.h
@@ -63,5 +63,7 @@ QList<Core::IOptionsPage *> optionsPages();
void setQtPluginPath(const QString &qtPluginPath);
void addPluginPath(const QString &pluginPath);
+QObject *createGoToSlotTest();
+
} // namespace Internal
} // namespace Designer
diff --git a/src/plugins/designer/formeditorplugin.cpp b/src/plugins/designer/formeditorplugin.cpp
index 0f9c77b0b44..9b47bf864a9 100644
--- a/src/plugins/designer/formeditorplugin.cpp
+++ b/src/plugins/designer/formeditorplugin.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 "formeditorplugin.h"
-
#include "designerconstants.h"
#include "designertr.h"
#include "formeditorfactory.h"
@@ -28,6 +26,8 @@
#include <cppeditor/cppeditorconstants.h>
+#include <extensionsystem/iplugin.h>
+
#include <projectexplorer/jsonwizard/jsonwizardfactory.h>
#include <utils/mimeconstants.h>
@@ -45,103 +45,7 @@ using namespace Core;
using namespace Designer::Constants;
using namespace Utils;
-namespace Designer {
-namespace Internal {
-
-class FormEditorPluginPrivate
-{
-public:
- QAction actionSwitchSource{Tr::tr("Switch Source/Form"), nullptr};
-
- FormEditorFactory formEditorFactory;
- SettingsPageProvider settingsPageProvider;
- QtDesignerFormClassCodeGenerator formClassCodeGenerator;
- FormPageFactory formPageFactory;
-};
-
-FormEditorPlugin::~FormEditorPlugin()
-{
- deleteInstance();
- delete d;
-}
-
-static void parseArguments(const QStringList &arguments)
-{
- const auto doWithNext = [arguments](auto it, const std::function<void(QString)> &fun) {
- ++it;
- if (it != arguments.cend())
- fun(*it);
- };
- for (auto it = arguments.cbegin(); it != arguments.cend(); ++it) {
- if (*it == "-designer-qt-pluginpath")
- doWithNext(it, [](const QString &path) { setQtPluginPath(path); });
-#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
- // -designer-pluginpath is only supported when building with Qt >= 6.7.0, which added the
- // required API
- else if (*it == "-designer-pluginpath")
- doWithNext(it, [](const QString &path) { addPluginPath(path); });
-#endif
- }
-}
-
-bool FormEditorPlugin::initialize([[maybe_unused]] const QStringList &arguments,
- [[maybe_unused]] QString *errorString)
-{
- d = new FormEditorPluginPrivate;
-
-#ifdef CPP_ENABLED
- IWizardFactory::registerFactoryCreator([]() -> IWizardFactory * {
- IWizardFactory *wizard = new FormClassWizard;
- wizard->setCategory(Core::Constants::WIZARD_CATEGORY_QT);
- wizard->setDisplayCategory(::Core::Tr::tr(Core::Constants::WIZARD_TR_CATEGORY_QT));
- wizard->setDisplayName(Tr::tr("Qt Designer Form Class"));
- wizard->setIcon({}, "ui/h");
- wizard->setId("C.FormClass");
- wizard->setDescription(Tr::tr("Creates a Qt Designer form along with a matching class (C++ header and source file) "
- "for implementation purposes. You can add the form and class to an existing Qt Widget Project."));
-
- return wizard;
- });
-#endif
-
- // Ensure that loading designer translations is done before FormEditorW is instantiated
- const QString locale = ICore::userInterfaceLanguage();
- if (!locale.isEmpty()) {
- auto qtr = new QTranslator(this);
- const QString creatorTrPath = ICore::resourcePath("translations").toString();
- const QString qtTrPath = QLibraryInfo::path(QLibraryInfo::TranslationsPath);
- const QString trFile = "designer_" + locale;
- if (qtr->load(trFile, qtTrPath) || qtr->load(trFile, creatorTrPath))
- QCoreApplication::installTranslator(qtr);
- }
-
- parseArguments(arguments);
- return true;
-}
-
-void FormEditorPlugin::extensionsInitialized()
-{
- DesignMode::setDesignModeIsRequired();
- // 4) test and make sure everything works (undo, saving, editors, opening/closing multiple files, dirtiness etc)
-
- ActionContainer *mtools = ActionManager::actionContainer(Core::Constants::M_TOOLS);
- ActionContainer *mformtools = ActionManager::createMenu(M_FORMEDITOR);
- mformtools->menu()->setTitle(Tr::tr("For&m Editor"));
- mtools->addMenu(mformtools);
-
- connect(&d->actionSwitchSource, &QAction::triggered, this, &FormEditorPlugin::switchSourceForm);
- Context context(C_FORMEDITOR, Core::Constants::C_EDITORMANAGER);
- Command *cmd = ActionManager::registerAction(&d->actionSwitchSource,
- "FormEditor.FormSwitchSource", context);
- cmd->setDefaultKeySequence(Tr::tr("Shift+F4"));
- mformtools->addAction(cmd, Core::Constants::G_DEFAULT_THREE);
-}
-
-////////////////////////////////////////////////////
-//
-// PRIVATE functions
-//
-////////////////////////////////////////////////////
+namespace Designer::Internal {
// Find out current existing editor file
static FilePath currentFile()
@@ -185,12 +89,113 @@ static FilePath otherFile()
return {};
}
-void FormEditorPlugin::switchSourceForm()
+static void parseArguments(const QStringList &arguments)
{
- const FilePath fileToOpen = otherFile();
- if (!fileToOpen.isEmpty())
- EditorManager::openEditor(fileToOpen);
+ const auto doWithNext = [arguments](auto it, const std::function<void(QString)> &fun) {
+ ++it;
+ if (it != arguments.cend())
+ fun(*it);
+ };
+ for (auto it = arguments.cbegin(); it != arguments.cend(); ++it) {
+ if (*it == "-designer-qt-pluginpath")
+ doWithNext(it, [](const QString &path) { setQtPluginPath(path); });
+#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
+ // -designer-pluginpath is only supported when building with Qt >= 6.7.0, which added the
+ // required API
+ else if (*it == "-designer-pluginpath")
+ doWithNext(it, [](const QString &path) { addPluginPath(path); });
+#endif
+ }
}
-} // Internal
-} // Designer
+class FormEditorPluginPrivate
+{
+public:
+ QAction actionSwitchSource{Tr::tr("Switch Source/Form"), nullptr};
+
+ FormEditorFactory formEditorFactory;
+ SettingsPageProvider settingsPageProvider;
+ QtDesignerFormClassCodeGenerator formClassCodeGenerator;
+ FormPageFactory formPageFactory;
+};
+
+class FormEditorPlugin final : public ExtensionSystem::IPlugin
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "Designer.json")
+
+ ~FormEditorPlugin() final
+ {
+ deleteInstance();
+ delete d;
+ }
+
+ bool initialize(const QStringList &arguments, QString *) final
+ {
+ d = new FormEditorPluginPrivate;
+
+#ifdef CPP_ENABLED
+ IWizardFactory::registerFactoryCreator([]() -> IWizardFactory * {
+ IWizardFactory *wizard = new FormClassWizard;
+ wizard->setCategory(Core::Constants::WIZARD_CATEGORY_QT);
+ wizard->setDisplayCategory(::Core::Tr::tr(Core::Constants::WIZARD_TR_CATEGORY_QT));
+ wizard->setDisplayName(Tr::tr("Qt Designer Form Class"));
+ wizard->setIcon({}, "ui/h");
+ wizard->setId("C.FormClass");
+ wizard->setDescription(Tr::tr("Creates a Qt Designer form along with a matching class (C++ header and source file) "
+ "for implementation purposes. You can add the form and class to an existing Qt Widget Project."));
+
+ return wizard;
+ });
+#endif
+
+ // Ensure that loading designer translations is done before FormEditorW is instantiated
+ const QString locale = ICore::userInterfaceLanguage();
+ if (!locale.isEmpty()) {
+ auto qtr = new QTranslator(this);
+ const QString creatorTrPath = ICore::resourcePath("translations").toString();
+ const QString qtTrPath = QLibraryInfo::path(QLibraryInfo::TranslationsPath);
+ const QString trFile = "designer_" + locale;
+ if (qtr->load(trFile, qtTrPath) || qtr->load(trFile, creatorTrPath))
+ QCoreApplication::installTranslator(qtr);
+ }
+
+#ifdef WITH_TESTS
+ addTestCreator(createGoToSlotTest);
+#endif
+
+ parseArguments(arguments);
+ return true;
+ }
+
+ void extensionsInitialized() final
+ {
+ DesignMode::setDesignModeIsRequired();
+ // 4) test and make sure everything works (undo, saving, editors, opening/closing multiple files, dirtiness etc)
+
+ ActionContainer *mtools = ActionManager::actionContainer(Core::Constants::M_TOOLS);
+ ActionContainer *mformtools = ActionManager::createMenu(M_FORMEDITOR);
+ mformtools->menu()->setTitle(Tr::tr("For&m Editor"));
+ mtools->addMenu(mformtools);
+
+ connect(&d->actionSwitchSource, &QAction::triggered, this, &FormEditorPlugin::switchSourceForm);
+ Context context(C_FORMEDITOR, Core::Constants::C_EDITORMANAGER);
+ Command *cmd = ActionManager::registerAction(&d->actionSwitchSource,
+ "FormEditor.FormSwitchSource", context);
+ cmd->setDefaultKeySequence(Tr::tr("Shift+F4"));
+ mformtools->addAction(cmd, Core::Constants::G_DEFAULT_THREE);
+ }
+
+ void switchSourceForm()
+ {
+ const FilePath fileToOpen = otherFile();
+ if (!fileToOpen.isEmpty())
+ EditorManager::openEditor(fileToOpen);
+ }
+
+ FormEditorPluginPrivate *d = nullptr;
+};
+
+} // Designer::Internal
+
+#include "formeditorplugin.moc"
diff --git a/src/plugins/designer/formeditorplugin.h b/src/plugins/designer/formeditorplugin.h
deleted file mode 100644
index 754aeecaee4..00000000000
--- a/src/plugins/designer/formeditorplugin.h
+++ /dev/null
@@ -1,37 +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 <extensionsystem/iplugin.h>
-
-namespace Designer {
-namespace Internal {
-
-class FormEditorPlugin : public ExtensionSystem::IPlugin
-{
- Q_OBJECT
- Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "Designer.json")
-
-public:
- FormEditorPlugin() = default;
- ~FormEditorPlugin() override;
-
-#ifdef WITH_TESTS
-private slots:
- void test_gotoslot();
- void test_gotoslot_data();
-#endif
-
-private:
- bool initialize(const QStringList &arguments, QString *errorString) override;
- void extensionsInitialized() override;
-
- void switchSourceForm();
- void initializeTemplates();
-
- class FormEditorPluginPrivate *d = nullptr;
-};
-
-} // namespace Internal
-} // namespace Designer
diff --git a/src/plugins/designer/gotoslot_test.cpp b/src/plugins/designer/gotoslot_test.cpp
index 49fccf58716..0ee669d36dd 100644
--- a/src/plugins/designer/gotoslot_test.cpp
+++ b/src/plugins/designer/gotoslot_test.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 "formeditorplugin.h"
-
#include "formeditor.h"
#include <coreplugin/editormanager/editormanager.h>
@@ -30,7 +28,7 @@ using namespace Designer;
using namespace Designer::Internal;
using namespace Utils;
-namespace {
+namespace Designer::Internal {
QTC_DECLARE_MYTESTDATADIR("../../../tests/designer/")
@@ -207,14 +205,18 @@ public:
}
};
-} // anonymous namespace
+class GoToSlotTest final : public QObject
+{
+ Q_OBJECT
-namespace Designer {
-namespace Internal {
+private slots:
+ void test_gotoslot();
+ void test_gotoslot_data();
+};
/// Check: Executes "Go To Slot..." on a QPushButton in a *.ui file and checks if the respective
/// header and source files are correctly updated.
-void FormEditorPlugin::test_gotoslot()
+void GoToSlotTest::test_gotoslot()
{
class SystemSettingsMgr {
public:
@@ -235,7 +237,7 @@ void FormEditorPlugin::test_gotoslot()
(GoToSlotTestCase(Utils::transform(files, FilePath::fromString)));
}
-void FormEditorPlugin::test_gotoslot_data()
+void GoToSlotTest::test_gotoslot_data()
{
typedef QLatin1String _;
QTest::addColumn<QStringList>("files");
@@ -269,5 +271,11 @@ void FormEditorPlugin::test_gotoslot_data()
testDataDir.file(_("form.ui"))});
}
-} // namespace Internal
-} // namespace Designer
+QObject *createGoToSlotTest()
+{
+ return new GoToSlotTest;
+}
+
+} // Designer::Internal
+
+#include "gotoslot_test.moc"