ModelEditor: Move closer to standard plugin setup

The private structure was already there, just delay initialization
and make the members direct.

Change-Id: Ic0d71fe27f15a5c270544469d046b3298e6b2c65
Reviewed-by: Jochen Becher <jochen_becher@gmx.de>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2020-01-23 09:39:52 +01:00
parent b093941435
commit 5ea999402c
8 changed files with 27 additions and 45 deletions

View File

@@ -25,12 +25,13 @@
#include "modeleditor_plugin.h"
#include "jsextension.h"
#include "modeleditor_constants.h"
#include "modeleditorfactory.h"
#include "modeleditor_global.h"
#include "modelsmanager.h"
#include "settingscontroller.h"
#include "modeleditor_constants.h"
#include "uicontroller.h"
#include "jsextension.h"
#include "qmt/infrastructure/uid.h"
@@ -45,32 +46,24 @@
#include <QAction>
#include <QApplication>
#include <QMessageBox>
#include <QMainWindow>
#include <QMenu>
#include <QItemSelection>
#include <QClipboard>
#include <QFontDatabase>
#include <QtPlugin>
namespace ModelEditor {
namespace Internal {
ModelEditorPlugin *pluginInstance = nullptr;
class ModelEditorPlugin::ModelEditorPluginPrivate
class ModelEditorPluginPrivate final
{
public:
ModelsManager *modelsManager = nullptr;
UiController *uiController = nullptr;
ModelEditorFactory *modelFactory = nullptr;
SettingsController *settingsController = nullptr;
ModelsManager modelsManager;
UiController uiController;
ModelEditorFactory modelFactory{&uiController};
SettingsController settingsController;
};
ModelEditorPlugin::ModelEditorPlugin()
: ExtensionSystem::IPlugin(),
d(new ModelEditorPluginPrivate)
{
pluginInstance = this;
qRegisterMetaType<QItemSelection>("QItemSelection");
@@ -86,18 +79,14 @@ bool ModelEditorPlugin::initialize(const QStringList &arguments, QString *errorS
{
Q_UNUSED(arguments)
Q_UNUSED(errorString)
d->modelsManager = new ModelsManager(this);
d->uiController = new UiController(this);
d->modelFactory = new ModelEditorFactory(d->uiController, this);
d->settingsController = new SettingsController(this);
d = new ModelEditorPluginPrivate;
Core::JsExpander::registerGlobalObject<JsExtension>("Modeling");
connect(d->settingsController, &SettingsController::saveSettings,
d->uiController, &UiController::saveSettings);
connect(d->settingsController, &SettingsController::loadSettings,
d->uiController, &UiController::loadSettings);
connect(&d->settingsController, &SettingsController::saveSettings,
&d->uiController, &UiController::saveSettings);
connect(&d->settingsController, &SettingsController::loadSettings,
&d->uiController, &UiController::loadSettings);
return true;
}
@@ -107,20 +96,20 @@ void ModelEditorPlugin::extensionsInitialized()
// Retrieve objects from the plugin manager's object pool
// In the extensionsInitialized method, a plugin can be sure that all
// plugins that depend on it are completely initialized.
d->modelFactory->extensionsInitialized();
d->settingsController->load(Core::ICore::settings());
d->modelFactory.extensionsInitialized();
d->settingsController.load(Core::ICore::settings());
}
ExtensionSystem::IPlugin::ShutdownFlag ModelEditorPlugin::aboutToShutdown()
{
d->settingsController->save(Core::ICore::settings());
d->settingsController.save(Core::ICore::settings());
QApplication::clipboard()->clear();
return SynchronousShutdown;
}
ModelsManager *ModelEditorPlugin::modelsManager()
{
return pluginInstance->d->modelsManager;
return &pluginInstance->d->modelsManager;
}
} // namespace Internal

View File

@@ -25,8 +25,6 @@
#pragma once
#include "modeleditor_global.h"
#include <extensionsystem/iplugin.h>
namespace ModelEditor {
@@ -34,12 +32,10 @@ namespace Internal {
class ModelsManager;
class ModelEditorPlugin :
public ExtensionSystem::IPlugin
class ModelEditorPlugin : public ExtensionSystem::IPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "ModelEditor.json")
class ModelEditorPluginPrivate;
public:
ModelEditorPlugin();
@@ -52,7 +48,7 @@ public:
static ModelsManager *modelsManager();
private:
ModelEditorPluginPrivate *d;
class ModelEditorPluginPrivate *d = nullptr;
};
} // namespace Internal

View File

@@ -41,9 +41,8 @@ public:
ActionHandler *actionHandler = nullptr;
};
ModelEditorFactory::ModelEditorFactory(UiController *uiController, QObject *parent)
: Core::IEditorFactory(parent),
d(new ModelEditorFactoryPrivate())
ModelEditorFactory::ModelEditorFactory(UiController *uiController)
: d(new ModelEditorFactoryPrivate())
{
setId(Constants::MODEL_EDITOR_ID);
setDisplayName(QCoreApplication::translate("OpenWith::Editors", Constants::MODEL_EDITOR_DISPLAY_NAME));

View File

@@ -40,7 +40,7 @@ class ModelEditorFactory :
class ModelEditorFactoryPrivate;
public:
explicit ModelEditorFactory(UiController *uiController, QObject *parent = nullptr);
explicit ModelEditorFactory(UiController *uiController);
~ModelEditorFactory();
Core::IEditor *createEditor() override;

View File

@@ -32,8 +32,7 @@
namespace ModelEditor {
namespace Internal {
SettingsController::SettingsController(QObject *parent)
: QObject(parent)
SettingsController::SettingsController()
{
}

View File

@@ -40,7 +40,7 @@ class SettingsController :
Q_OBJECT
public:
explicit SettingsController(QObject *parent = nullptr);
SettingsController();
signals:
void resetSettings();

View File

@@ -39,9 +39,8 @@ public:
QByteArray rightHorizSplitterState;
};
UiController::UiController(QObject *parent)
: QObject(parent),
d(new UiControllerPrivate)
UiController::UiController()
: d(new UiControllerPrivate)
{
}

View File

@@ -41,7 +41,7 @@ class UiController :
class UiControllerPrivate;
public:
explicit UiController(QObject *parent = nullptr);
UiController();
~UiController();
signals: