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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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