ModelEditor: Simplify setup of some plugin singletons

Change-Id: Ica4d10155160d06be52daf4b56b714d07ad92290
Reviewed-by: Jochen Becher <jochen_becher@gmx.de>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
hjk
2020-02-11 17:56:55 +01:00
parent a7bd6864c1
commit 9510c7293f
5 changed files with 11 additions and 33 deletions

View File

@@ -45,7 +45,7 @@ namespace Internal {
class ActionHandler::ActionHandlerPrivate {
public:
Core::Context context;
Core::Context context{Constants::MODEL_EDITOR_ID};
QAction *undoAction = nullptr;
QAction *redoAction = nullptr;
QAction *cutAction = nullptr;
@@ -60,11 +60,9 @@ public:
QAction *exportSelectedElementsAction = nullptr;
};
ActionHandler::ActionHandler(const Core::Context &context, QObject *parent)
: QObject(parent),
d(new ActionHandlerPrivate)
ActionHandler::ActionHandler()
: d(new ActionHandlerPrivate)
{
d->context = context;
}
ActionHandler::~ActionHandler()

View File

@@ -52,7 +52,7 @@ class ActionHandler :
class ActionHandlerPrivate;
public:
ActionHandler(const Core::Context &context, QObject *parent = nullptr);
ActionHandler();
~ActionHandler();
public:

View File

@@ -32,6 +32,7 @@
#include "modelsmanager.h"
#include "settingscontroller.h"
#include "uicontroller.h"
#include "actionhandler.h"
#include "qmt/infrastructure/uid.h"
@@ -59,7 +60,8 @@ class ModelEditorPluginPrivate final
public:
ModelsManager modelsManager;
UiController uiController;
ModelEditorFactory modelFactory{&uiController};
ActionHandler actionHandler;
ModelEditorFactory modelFactory{&uiController, &actionHandler};
SettingsController settingsController;
};
@@ -93,10 +95,7 @@ bool ModelEditorPlugin::initialize(const QStringList &arguments, QString *errorS
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->actionHandler.createActions();
d->settingsController.load(Core::ICore::settings());
}

View File

@@ -34,24 +34,12 @@
namespace ModelEditor {
namespace Internal {
ModelEditorFactory::ModelEditorFactory(UiController *uiController)
ModelEditorFactory::ModelEditorFactory(UiController *uiController, ActionHandler *actionHandler)
{
setId(Constants::MODEL_EDITOR_ID);
setDisplayName(QCoreApplication::translate("OpenWith::Editors", Constants::MODEL_EDITOR_DISPLAY_NAME));
addMimeType(Constants::MIME_TYPE_MODEL);
m_uiController = uiController;
m_actionHandler = new ActionHandler(Core::Context(Constants::MODEL_EDITOR_ID), this);
setEditorCreator([this] { return new ModelEditor(m_uiController, m_actionHandler); });
}
ModelEditorFactory::~ModelEditorFactory()
{
delete m_actionHandler;
}
void ModelEditorFactory::extensionsInitialized()
{
m_actionHandler->createActions();
setEditorCreator([uiController, actionHandler] { return new ModelEditor(uiController, actionHandler); });
}
} // namespace Internal

View File

@@ -37,14 +37,7 @@ class UiController;
class ModelEditorFactory : public Core::IEditorFactory
{
public:
explicit ModelEditorFactory(UiController *uiController);
~ModelEditorFactory();
void extensionsInitialized();
private:
UiController *m_uiController = nullptr;
ActionHandler *m_actionHandler = nullptr;
ModelEditorFactory(UiController *uiController, ActionHandler *actionHandler);
};
} // namespace Internal