Designer: Remove FormEditorW class

Just wrapped static functions.

Change-Id: Ic60a2d7185aab5576e48894c74a9314a4b1c2324
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
hjk
2023-05-03 10:50:16 +02:00
parent a03bea81c7
commit 95e8280d12
11 changed files with 79 additions and 81 deletions

View File

@@ -25,7 +25,7 @@ DesignerContext::DesignerContext(const Core::Context &context,
void DesignerContext::contextHelp(const HelpCallback &callback) const
{
const QDesignerFormEditorInterface *core = FormEditorW::designerEditor();
const QDesignerFormEditorInterface *core = designerEditor();
callback(core->integration()->contextHelpId());
}

View File

@@ -28,7 +28,7 @@ EditorWidget::EditorWidget(QWidget *parent) :
setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
QWidget * const*subs = FormEditorW::designerSubWindows();
QWidget * const * subs = designerSubWindows();
for (int i = 0; i < DesignerSubWindowCount; i++) {
QWidget *subWindow = subs[i];
subWindow->setWindowTitle(subs[i]->windowTitle());

View File

@@ -1,18 +1,16 @@
// 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 "designertr.h"
#include "formeditorfactory.h"
#include "designerconstants.h"
#include "designertr.h"
#include "formeditorw.h"
#include "formwindoweditor.h"
#include <coreplugin/coreconstants.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <utils/fsengine/fileiconprovider.h>
#include <QCoreApplication>
#include <QDebug>
using namespace Core;
using namespace Designer::Constants;
using namespace Utils;
@@ -25,7 +23,7 @@ FormEditorFactory::FormEditorFactory()
setId(K_DESIGNER_XML_EDITOR_ID);
setDisplayName(Tr::tr(C_DESIGNER_XML_DISPLAY_NAME));
addMimeType(FORM_MIMETYPE);
setEditorCreator([] { return FormEditorW::createEditor(); });
setEditorCreator([] { return Designer::Internal::createEditor(); });
FileIconProvider::registerIconOverlayForSuffix(ProjectExplorer::Constants::FILEOVERLAY_UI, "ui");
}

View File

@@ -1,9 +1,11 @@
// 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"
#include "formeditorplugin.h"
#include "formeditorw.h"
#include "formtemplatewizardpage.h"
@@ -54,7 +56,7 @@ public:
FormEditorPlugin::~FormEditorPlugin()
{
FormEditorW::deleteInstance();
deleteInstance();
delete d;
}

View File

@@ -2,6 +2,8 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "formeditorstack.h"
#include "designerconstants.h"
#include "formwindoweditor.h"
#include "formeditorw.h"
#include "formwindowfile.h"

View File

@@ -123,9 +123,9 @@ public:
}
};
// --------- FormEditorW
// FormEditorData
class FormEditorData
class FormEditorData : public QObject
{
public:
FormEditorData();
@@ -173,7 +173,7 @@ public:
QDesignerFormEditorInterface *m_formeditor = nullptr;
QtCreatorIntegration *m_integration = nullptr;
QDesignerFormWindowManagerInterface *m_fwm = nullptr;
FormEditorW::InitializationStage m_initStage = FormEditorW::RegisterPlugins;
InitializationStage m_initStage = RegisterPlugins;
QWidget *m_designerSubWindows[DesignerSubWindowCount];
@@ -202,7 +202,6 @@ public:
};
static FormEditorData *d = nullptr;
static FormEditorW *m_instance = nullptr;
FormEditorData::FormEditorData() :
m_formeditor(QDesignerComponents::createFormEditor(nullptr))
@@ -238,7 +237,7 @@ FormEditorData::FormEditorData() :
if (editor && editor->document()->id() == Constants::K_DESIGNER_XML_EDITOR_ID) {
FormWindowEditor *xmlEditor = qobject_cast<FormWindowEditor *>(editor);
QTC_ASSERT(xmlEditor, return);
FormEditorW::ensureInitStage(FormEditorW::FullyInitialized);
ensureInitStage(FullyInitialized);
SharedTools::WidgetHost *fw = m_editorWidget->formWindowEditorForXmlEditor(xmlEditor);
QTC_ASSERT(fw, return);
m_editorWidget->setVisibleEditor(xmlEditor);
@@ -251,7 +250,7 @@ FormEditorData::FormEditorData() :
FormEditorData::~FormEditorData()
{
if (m_initStage == FormEditorW::FullyInitialized) {
if (m_initStage == FullyInitialized) {
QSettings *s = ICore::settings();
s->beginGroup(settingsGroupC);
m_editorWidget->saveSettings(s);
@@ -324,18 +323,18 @@ void FormEditorData::setupViewActions()
void FormEditorData::fullInit()
{
QTC_ASSERT(m_initStage == FormEditorW::RegisterPlugins, return);
QTC_ASSERT(m_initStage == RegisterPlugins, return);
QElapsedTimer *initTime = nullptr;
if (Designer::Constants::Internal::debug) {
initTime = new QElapsedTimer;
initTime->start();
}
QDesignerComponents::createTaskMenu(m_formeditor, m_instance);
QDesignerComponents::createTaskMenu(m_formeditor, this);
QDesignerComponents::initializePlugins(m_formeditor);
QDesignerComponents::initializeResources();
initDesignerSubWindows();
m_integration = new QtCreatorIntegration(m_formeditor, m_instance);
m_integration = new QtCreatorIntegration(m_formeditor, this);
m_formeditor->setIntegration(m_integration);
// Connect Qt Designer help request to HelpManager.
QObject::connect(m_integration, &QtCreatorIntegration::creatorHelpRequested,
@@ -397,13 +396,13 @@ void FormEditorData::fullInit()
Context designerContexts = m_contexts;
designerContexts.add(Core::Constants::C_EDITORMANAGER);
ICore::addContextObject(new DesignerContext(designerContexts, m_modeWidget, m_instance));
ICore::addContextObject(new DesignerContext(designerContexts, m_modeWidget, this));
DesignMode::registerDesignWidget(m_modeWidget, QStringList(FORM_MIMETYPE), m_contexts);
setupViewActions();
m_initStage = FormEditorW::FullyInitialized;
m_initStage = FullyInitialized;
}
void FormEditorData::initDesignerSubWindows()
@@ -438,22 +437,21 @@ void FormEditorData::initDesignerSubWindows()
ae->setObjectName("ActionEditor");
m_formeditor->setActionEditor(ae);
m_designerSubWindows[ActionEditorSubWindow] = ae;
m_initStage = FormEditorW::SubwindowsInitialized;
m_initStage = SubwindowsInitialized;
}
QList<IOptionsPage *> FormEditorW::optionsPages()
QList<IOptionsPage *> optionsPages()
{
return d->m_settingsPages;
}
void FormEditorW::ensureInitStage(InitializationStage s)
void ensureInitStage(InitializationStage s)
{
if (Designer::Constants::Internal::debug)
qDebug() << Q_FUNC_INFO << s;
if (!d) {
m_instance = new FormEditorW;
if (!d)
d = new FormEditorData;
}
if (d->m_initStage >= s)
return;
QApplication::setOverrideCursor(Qt::WaitCursor);
@@ -461,15 +459,13 @@ void FormEditorW::ensureInitStage(InitializationStage s)
QApplication::restoreOverrideCursor();
}
void FormEditorW::deleteInstance()
void deleteInstance()
{
delete d;
d = nullptr;
delete m_instance;
m_instance = nullptr;
}
IEditor *FormEditorW::createEditor()
IEditor *createEditor()
{
ensureInitStage(FullyInitialized);
return d->createEditor();
@@ -489,7 +485,7 @@ void FormEditorData::setupActions()
bindShortcut(ActionManager::registerAction(m_fwm->actionPaste(), Core::Constants::PASTE, m_contexts), m_fwm->actionPaste());
bindShortcut(ActionManager::registerAction(m_fwm->actionSelectAll(), Core::Constants::SELECTALL, m_contexts), m_fwm->actionSelectAll());
m_actionPrint = new QAction(m_instance);
m_actionPrint = new QAction(this);
bindShortcut(ActionManager::registerAction(m_actionPrint, Core::Constants::PRINT, m_contexts), m_actionPrint);
QObject::connect(m_actionPrint, &QAction::triggered, [this]() { print(); });
@@ -502,7 +498,7 @@ void FormEditorData::setupActions()
command->setAttribute(Command::CA_Hide);
medit->addAction(command, Core::Constants::G_EDIT_COPYPASTE);
m_actionGroupEditMode = new QActionGroup(m_instance);
m_actionGroupEditMode = new QActionGroup(this);
m_actionGroupEditMode->setExclusive(true);
QObject::connect(m_actionGroupEditMode, &QActionGroup::triggered,
[this](QAction *a) { activateEditMode(a->data().toInt()); });
@@ -601,7 +597,7 @@ void FormEditorData::setupActions()
QString(), Core::Constants::G_DEFAULT_THREE);
mformtools->addSeparator(m_contexts, Core::Constants::G_DEFAULT_THREE);
m_actionAboutPlugins = new QAction(Tr::tr("About Qt Designer Plugins..."), m_instance);
m_actionAboutPlugins = new QAction(Tr::tr("About Qt Designer Plugins..."), d);
addToolAction(m_actionAboutPlugins, m_contexts, "FormEditor.AboutPlugins", mformtools,
QString(), Core::Constants::G_DEFAULT_THREE);
QObject::connect(m_actionAboutPlugins, &QAction::triggered,
@@ -760,19 +756,19 @@ IEditor *FormEditorData::createEditor()
return formWindowEditor;
}
QDesignerFormEditorInterface *FormEditorW::designerEditor()
QDesignerFormEditorInterface *designerEditor()
{
ensureInitStage(FullyInitialized);
return d->m_formeditor;
}
QWidget * const *FormEditorW::designerSubWindows()
QWidget * const *designerSubWindows()
{
ensureInitStage(SubwindowsInitialized);
return d->m_designerSubWindows;
}
SharedTools::WidgetHost *FormEditorW::activeWidgetHost()
SharedTools::WidgetHost *activeWidgetHost()
{
ensureInitStage(FullyInitialized);
if (d->m_editorWidget)
@@ -780,7 +776,7 @@ SharedTools::WidgetHost *FormEditorW::activeWidgetHost()
return nullptr;
}
FormWindowEditor *FormEditorW::activeEditor()
FormWindowEditor *activeEditor()
{
ensureInitStage(FullyInitialized);
if (d->m_editorWidget)

View File

@@ -3,12 +3,11 @@
#pragma once
#include "designerconstants.h"
#include <QObject>
#include <QtGlobal>
QT_BEGIN_NAMESPACE
class QDesignerFormEditorInterface;
class QWidget;
QT_END_NAMESPACE
namespace Core {
@@ -24,11 +23,10 @@ class FormWindowEditor;
namespace Internal {
/** FormEditorW is a singleton that stores the Designer CoreInterface and
* performs centralized operations. The instance() function will return an
* instance. However, it must be manually deleted when unloading the
* plugin. Since fully initializing Designer at startup is expensive, the
* class has an internal partial initialisation stage "RegisterPlugins"
/** This is an interface to the Designer CoreInterface to
* performs centralized operations.
* Since fully initializing Designer at startup is expensive, the
* setup has an internal partial initialization stage "RegisterPlugins"
* which is there to register the Creator plugin objects
* that must be present at startup (settings pages, actions).
* The plugin uses this stage at first by calling ensureInitStage().
@@ -38,32 +36,29 @@ namespace Internal {
*
* The form editor shows a read-only XML editor in edit mode and Qt Designer
* in Design mode. */
class FormEditorW : public QObject
{
public:
enum InitializationStage {
enum InitializationStage {
// Register Creator plugins (settings pages, actions)
RegisterPlugins,
// Subwindows of the designer are initialized
SubwindowsInitialized,
// Fully initialized for handling editor requests
FullyInitialized
};
// Create an instance and initialize up to stage s
static void ensureInitStage(InitializationStage s);
// Deletes an existing instance if there is one.
static void deleteInstance();
static Core::IEditor *createEditor();
static QDesignerFormEditorInterface *designerEditor();
static QWidget * const *designerSubWindows();
static SharedTools::WidgetHost *activeWidgetHost();
static FormWindowEditor *activeEditor();
static QList<Core::IOptionsPage *> optionsPages();
};
// Create an instance and initialize up to stage s
void ensureInitStage(InitializationStage s);
// Deletes an existing instance if there is one.
void deleteInstance();
Core::IEditor *createEditor();
QDesignerFormEditorInterface *designerEditor();
QWidget * const *designerSubWindows();
SharedTools::WidgetHost *activeWidgetHost();
FormWindowEditor *activeEditor();
QList<Core::IOptionsPage *> optionsPages();
} // namespace Internal
} // namespace Designer

View File

@@ -58,7 +58,7 @@ bool FormPageFactory::validateData(Utils::Id typeId, const QVariant &data, QStri
FormTemplateWizardPage::FormTemplateWizardPage(QWidget * parent) :
Utils::WizardPage(parent),
m_newFormWidget(QDesignerNewFormWidgetInterface::createNewFormWidget(FormEditorW::designerEditor())),
m_newFormWidget(QDesignerNewFormWidgetInterface::createNewFormWidget(designerEditor())),
m_templateSelected(m_newFormWidget->hasCurrentTemplate())
{
setTitle(Tr::tr("Choose a Form Template"));

View File

@@ -147,7 +147,7 @@ public:
waitForFilesInGlobalSnapshot({cppFile, hFile});
// Execute "Go To Slot"
QDesignerIntegrationInterface *integration = FormEditorW::designerEditor()->integration();
QDesignerIntegrationInterface *integration = designerEditor()->integration();
QVERIFY(integration);
integration->emitNavigateToSlot("pushButton", "clicked()", QStringList());

View File

@@ -1,10 +1,13 @@
// 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 "qtcreatorintegration.h"
#include "designerconstants.h"
#include "designertr.h"
#include "formeditorw.h"
#include "formwindoweditor.h"
#include "qtcreatorintegration.h"
#include <widgethost.h>
#include <designer/cpp/formclasswizardpage.h>
@@ -156,14 +159,14 @@ void QtCreatorIntegration::slotDesignerHelpRequested(const QString &manual, cons
void QtCreatorIntegration::updateSelection()
{
if (SharedTools::WidgetHost *host = FormEditorW::activeWidgetHost())
if (SharedTools::WidgetHost *host = activeWidgetHost())
host->updateFormWindowSelectionHandles(true);
QDesignerIntegration::updateSelection();
}
QWidget *QtCreatorIntegration::containerWindow(QWidget * /*widget*/) const
{
if (SharedTools::WidgetHost *host = FormEditorW::activeWidgetHost())
if (SharedTools::WidgetHost *host = activeWidgetHost())
return host->integrationContainer();
return nullptr;
}
@@ -435,7 +438,7 @@ void QtCreatorIntegration::slotNavigateToSlot(const QString &objectName, const Q
{
QString errorMessage;
if (!navigateToSlot(objectName, signalSignature, parameterNames, &errorMessage) && !errorMessage.isEmpty())
QMessageBox::warning(FormEditorW::designerEditor()->topLevel(), Tr::tr("Error finding/adding a slot."), errorMessage);
QMessageBox::warning(designerEditor()->topLevel(), Tr::tr("Error finding/adding a slot."), errorMessage);
}
// Build name of the class as generated by uic, insert Ui namespace
@@ -480,7 +483,7 @@ bool QtCreatorIntegration::navigateToSlot(const QString &objectName,
{
using DocumentMap = QMap<int, Document::Ptr>;
const Utils::FilePath currentUiFile = FormEditorW::activeEditor()->document()->filePath();
const Utils::FilePath currentUiFile = activeEditor()->document()->filePath();
#if 0
return Designer::Internal::navigateToSlot(currentUiFile.toString(), objectName,
signalSignature, parameterNames, errorMessage);
@@ -533,7 +536,7 @@ bool QtCreatorIntegration::navigateToSlot(const QString &objectName,
return false;
}
QDesignerFormWindowInterface *fwi = FormEditorW::activeWidgetHost()->formWindow();
QDesignerFormWindowInterface *fwi = activeWidgetHost()->formWindow();
QString uiClass;
const Class *cl = nullptr;

View File

@@ -1,9 +1,11 @@
// 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 "settingspage.h"
#include "designerconstants.h"
#include "designertr.h"
#include "formeditorw.h"
#include "settingspage.h"
#include <coreplugin/icontext.h>
@@ -54,9 +56,9 @@ QList<Core::IOptionsPage *> SettingsPageProvider::pages() const
if (!m_initialized) {
// get options pages from designer
m_initialized = true;
FormEditorW::ensureInitStage(FormEditorW::RegisterPlugins);
ensureInitStage(RegisterPlugins);
}
return FormEditorW::optionsPages();
return optionsPages();
}
bool SettingsPageProvider::matches(const QRegularExpression &regex) const