forked from qt-creator/qt-creator
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:
@@ -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()
|
||||
|
@@ -52,7 +52,7 @@ class ActionHandler :
|
||||
class ActionHandlerPrivate;
|
||||
|
||||
public:
|
||||
ActionHandler(const Core::Context &context, QObject *parent = nullptr);
|
||||
ActionHandler();
|
||||
~ActionHandler();
|
||||
|
||||
public:
|
||||
|
@@ -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());
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user