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

View File

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

View File

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

View File

@@ -34,24 +34,12 @@
namespace ModelEditor { namespace ModelEditor {
namespace Internal { namespace Internal {
ModelEditorFactory::ModelEditorFactory(UiController *uiController) ModelEditorFactory::ModelEditorFactory(UiController *uiController, ActionHandler *actionHandler)
{ {
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));
addMimeType(Constants::MIME_TYPE_MODEL); addMimeType(Constants::MIME_TYPE_MODEL);
m_uiController = uiController; setEditorCreator([uiController, actionHandler] { return new ModelEditor(uiController, actionHandler); });
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();
} }
} // namespace Internal } // namespace Internal

View File

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