forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -46,7 +46,7 @@ add_qtc_plugin(Designer
|
|||||||
editordata.h
|
editordata.h
|
||||||
editorwidget.cpp editorwidget.h
|
editorwidget.cpp editorwidget.h
|
||||||
formeditorfactory.cpp formeditorfactory.h
|
formeditorfactory.cpp formeditorfactory.h
|
||||||
formeditorplugin.cpp formeditorplugin.h
|
formeditorplugin.cpp
|
||||||
formeditorstack.cpp formeditorstack.h
|
formeditorstack.cpp formeditorstack.h
|
||||||
formeditor.cpp formeditor.h
|
formeditor.cpp formeditor.h
|
||||||
formtemplatewizardpage.cpp formtemplatewizardpage.h
|
formtemplatewizardpage.cpp formtemplatewizardpage.h
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ QtcPlugin {
|
|||||||
"editordata.h",
|
"editordata.h",
|
||||||
"editorwidget.cpp", "editorwidget.h",
|
"editorwidget.cpp", "editorwidget.h",
|
||||||
"formeditorfactory.cpp", "formeditorfactory.h",
|
"formeditorfactory.cpp", "formeditorfactory.h",
|
||||||
"formeditorplugin.cpp", "formeditorplugin.h",
|
"formeditorplugin.cpp",
|
||||||
"formeditorstack.cpp", "formeditorstack.h",
|
"formeditorstack.cpp", "formeditorstack.h",
|
||||||
"formeditor.cpp", "formeditor.h",
|
"formeditor.cpp", "formeditor.h",
|
||||||
"formtemplatewizardpage.cpp", "formtemplatewizardpage.h",
|
"formtemplatewizardpage.cpp", "formtemplatewizardpage.h",
|
||||||
|
|||||||
@@ -63,5 +63,7 @@ QList<Core::IOptionsPage *> optionsPages();
|
|||||||
void setQtPluginPath(const QString &qtPluginPath);
|
void setQtPluginPath(const QString &qtPluginPath);
|
||||||
void addPluginPath(const QString &pluginPath);
|
void addPluginPath(const QString &pluginPath);
|
||||||
|
|
||||||
|
QObject *createGoToSlotTest();
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace Designer
|
} // namespace Designer
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
// Copyright (C) 2016 The Qt Company Ltd.
|
// Copyright (C) 2016 The Qt Company Ltd.
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
#include "formeditorplugin.h"
|
|
||||||
|
|
||||||
#include "designerconstants.h"
|
#include "designerconstants.h"
|
||||||
#include "designertr.h"
|
#include "designertr.h"
|
||||||
#include "formeditorfactory.h"
|
#include "formeditorfactory.h"
|
||||||
@@ -28,6 +26,8 @@
|
|||||||
|
|
||||||
#include <cppeditor/cppeditorconstants.h>
|
#include <cppeditor/cppeditorconstants.h>
|
||||||
|
|
||||||
|
#include <extensionsystem/iplugin.h>
|
||||||
|
|
||||||
#include <projectexplorer/jsonwizard/jsonwizardfactory.h>
|
#include <projectexplorer/jsonwizard/jsonwizardfactory.h>
|
||||||
|
|
||||||
#include <utils/mimeconstants.h>
|
#include <utils/mimeconstants.h>
|
||||||
@@ -45,103 +45,7 @@ using namespace Core;
|
|||||||
using namespace Designer::Constants;
|
using namespace Designer::Constants;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
namespace Designer {
|
namespace Designer::Internal {
|
||||||
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
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
// Find out current existing editor file
|
// Find out current existing editor file
|
||||||
static FilePath currentFile()
|
static FilePath currentFile()
|
||||||
@@ -185,12 +89,113 @@ static FilePath otherFile()
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormEditorPlugin::switchSourceForm()
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
const FilePath fileToOpen = otherFile();
|
||||||
if (!fileToOpen.isEmpty())
|
if (!fileToOpen.isEmpty())
|
||||||
EditorManager::openEditor(fileToOpen);
|
EditorManager::openEditor(fileToOpen);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // Internal
|
FormEditorPluginPrivate *d = nullptr;
|
||||||
} // Designer
|
};
|
||||||
|
|
||||||
|
} // Designer::Internal
|
||||||
|
|
||||||
|
#include "formeditorplugin.moc"
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
// Copyright (C) 2016 The Qt Company Ltd.
|
// Copyright (C) 2016 The Qt Company Ltd.
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
#include "formeditorplugin.h"
|
|
||||||
|
|
||||||
#include "formeditor.h"
|
#include "formeditor.h"
|
||||||
|
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
@@ -30,7 +28,7 @@ using namespace Designer;
|
|||||||
using namespace Designer::Internal;
|
using namespace Designer::Internal;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
namespace {
|
namespace Designer::Internal {
|
||||||
|
|
||||||
QTC_DECLARE_MYTESTDATADIR("../../../tests/designer/")
|
QTC_DECLARE_MYTESTDATADIR("../../../tests/designer/")
|
||||||
|
|
||||||
@@ -207,14 +205,18 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // anonymous namespace
|
class GoToSlotTest final : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
namespace Designer {
|
private slots:
|
||||||
namespace Internal {
|
void test_gotoslot();
|
||||||
|
void test_gotoslot_data();
|
||||||
|
};
|
||||||
|
|
||||||
/// Check: Executes "Go To Slot..." on a QPushButton in a *.ui file and checks if the respective
|
/// Check: Executes "Go To Slot..." on a QPushButton in a *.ui file and checks if the respective
|
||||||
/// header and source files are correctly updated.
|
/// header and source files are correctly updated.
|
||||||
void FormEditorPlugin::test_gotoslot()
|
void GoToSlotTest::test_gotoslot()
|
||||||
{
|
{
|
||||||
class SystemSettingsMgr {
|
class SystemSettingsMgr {
|
||||||
public:
|
public:
|
||||||
@@ -235,7 +237,7 @@ void FormEditorPlugin::test_gotoslot()
|
|||||||
(GoToSlotTestCase(Utils::transform(files, FilePath::fromString)));
|
(GoToSlotTestCase(Utils::transform(files, FilePath::fromString)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormEditorPlugin::test_gotoslot_data()
|
void GoToSlotTest::test_gotoslot_data()
|
||||||
{
|
{
|
||||||
typedef QLatin1String _;
|
typedef QLatin1String _;
|
||||||
QTest::addColumn<QStringList>("files");
|
QTest::addColumn<QStringList>("files");
|
||||||
@@ -269,5 +271,11 @@ void FormEditorPlugin::test_gotoslot_data()
|
|||||||
testDataDir.file(_("form.ui"))});
|
testDataDir.file(_("form.ui"))});
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
QObject *createGoToSlotTest()
|
||||||
} // namespace Designer
|
{
|
||||||
|
return new GoToSlotTest;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // Designer::Internal
|
||||||
|
|
||||||
|
#include "gotoslot_test.moc"
|
||||||
|
|||||||
Reference in New Issue
Block a user