diff options
author | hjk <hjk@qt.io> | 2018-01-23 09:09:46 +0100 |
---|---|---|
committer | hjk <hjk@qt.io> | 2018-01-23 09:18:55 +0000 |
commit | 2b76504bd2c764f1a01b1a5e474307be110b84c5 (patch) | |
tree | f7f1a476c91ed7a039c2a04d4fd69563ef0686a0 | |
parent | fba61c5b55052c382e030748fa6e2703abb5401d (diff) |
DesignMode: Apply 'static pattern'
Also:
- and replace some occurrences of DesignMode::instance()->id() by
Core::Constants::MODE_DESIGN for less dependence on the lifetime
of the DesignMode object (and less indirection)
- remove storage if DesignMode::instance() values when direct
use of the static functions suffice
- remove some unused items from the interface
- use member-initialization in DesignMode::Private.
Change-Id: Ie66c06da0fc0a3ccc588b8079e51db6b39284152
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
-rw-r--r-- | src/plugins/coreplugin/coreplugin.cpp | 4 | ||||
-rw-r--r-- | src/plugins/coreplugin/designmode.cpp | 25 | ||||
-rw-r--r-- | src/plugins/coreplugin/designmode.h | 21 | ||||
-rw-r--r-- | src/plugins/designer/formeditorplugin.cpp | 2 | ||||
-rw-r--r-- | src/plugins/designer/formeditorw.cpp | 8 | ||||
-rw-r--r-- | src/plugins/qmldesigner/qmldesignerplugin.cpp | 6 | ||||
-rw-r--r-- | src/plugins/scxmleditor/scxmleditordata.cpp | 7 | ||||
-rw-r--r-- | src/plugins/scxmleditor/scxmleditordata.h | 3 | ||||
-rw-r--r-- | src/plugins/scxmleditor/scxmleditorplugin.cpp | 2 |
9 files changed, 28 insertions, 50 deletions
diff --git a/src/plugins/coreplugin/coreplugin.cpp b/src/plugins/coreplugin/coreplugin.cpp index 577a9f9487..379e198d13 100644 --- a/src/plugins/coreplugin/coreplugin.cpp +++ b/src/plugins/coreplugin/coreplugin.cpp @@ -91,7 +91,7 @@ CorePlugin::~CorePlugin() } if (m_designMode) { - if (m_designMode->designModeIsRequired()) + if (DesignMode::designModeIsRequired()) removeObject(m_designMode); delete m_designMode; } @@ -226,7 +226,7 @@ bool CorePlugin::initialize(const QStringList &arguments, QString *errorMessage) void CorePlugin::extensionsInitialized() { - if (m_designMode->designModeIsRequired()) + if (DesignMode::designModeIsRequired()) addObject(m_designMode); Find::extensionsInitialized(); m_locator->extensionsInitialized(); diff --git a/src/plugins/coreplugin/designmode.cpp b/src/plugins/coreplugin/designmode.cpp index 08d3ec20e6..33a016129c 100644 --- a/src/plugins/coreplugin/designmode.cpp +++ b/src/plugins/coreplugin/designmode.cpp @@ -40,8 +40,6 @@ #include <QStackedWidget> -static Core::DesignMode *m_instance = 0; - namespace Core { struct DesignEditorInfo @@ -60,17 +58,15 @@ public: public: QPointer<IEditor> m_currentEditor; - bool m_isActive; - bool m_isRequired; + bool m_isActive = false; + bool m_isRequired = false; QList<DesignEditorInfo*> m_editors; QStackedWidget *m_stackWidget; Context m_activeContext; }; DesignModePrivate::DesignModePrivate() - : m_isActive(false), - m_isRequired(false), - m_stackWidget(new QStackedWidget) + : m_stackWidget(new QStackedWidget) {} DesignModePrivate::~DesignModePrivate() @@ -78,10 +74,13 @@ DesignModePrivate::~DesignModePrivate() delete m_stackWidget; } +static DesignMode *m_instance = nullptr; +static DesignModePrivate *d = nullptr; + DesignMode::DesignMode() - : d(new DesignModePrivate) { m_instance = this; + d = new DesignModePrivate; ICore::addPreCloseListener([]() -> bool { m_instance->currentEditorChanged(0); @@ -121,19 +120,11 @@ void DesignMode::setDesignModeIsRequired() d->m_isRequired = true; } -bool DesignMode::designModeIsRequired() const +bool DesignMode::designModeIsRequired() { return d->m_isRequired; } -QStringList DesignMode::registeredMimeTypes() const -{ - QStringList rc; - foreach (const DesignEditorInfo *i, d->m_editors) - rc += i->mimeTypes; - return rc; -} - /** * Registers a widget to be displayed when an editor with a file specified in * mimeTypes is opened. This also appends the additionalContext in ICore to diff --git a/src/plugins/coreplugin/designmode.h b/src/plugins/coreplugin/designmode.h index fc0be09ed0..0bda118c74 100644 --- a/src/plugins/coreplugin/designmode.h +++ b/src/plugins/coreplugin/designmode.h @@ -30,8 +30,6 @@ namespace Core { class IEditor; -namespace Internal { class DesignModeCoreListener; } - /** * A global mode for Design pane - used by Bauhaus (QML Designer) and * Qt Designer. Other plugins can register themselves by registerDesignWidget() @@ -39,8 +37,6 @@ namespace Internal { class DesignModeCoreListener; } * to the main editor widget itself. */ -class DesignModePrivate; - class CORE_EXPORT DesignMode : public IMode { Q_OBJECT @@ -51,15 +47,13 @@ public: static DesignMode *instance(); - void setDesignModeIsRequired(); - bool designModeIsRequired() const; + static void setDesignModeIsRequired(); + static bool designModeIsRequired(); - void registerDesignWidget(QWidget *widget, - const QStringList &mimeTypes, - const Context &context); - void unregisterDesignWidget(QWidget *widget); - - QStringList registeredMimeTypes() const; + static void registerDesignWidget(QWidget *widget, + const QStringList &mimeTypes, + const Context &context); + static void unregisterDesignWidget(QWidget *widget); signals: void actionsUpdated(Core::IEditor *editor); @@ -70,9 +64,6 @@ private: void currentEditorChanged(IEditor *editor); void updateContext(Id newMode, Id oldMode); void setActiveContext(const Context &context); - - DesignModePrivate *d; - friend class Internal::DesignModeCoreListener; }; } // namespace Core diff --git a/src/plugins/designer/formeditorplugin.cpp b/src/plugins/designer/formeditorplugin.cpp index 7edde10be9..2b9843d64b 100644 --- a/src/plugins/designer/formeditorplugin.cpp +++ b/src/plugins/designer/formeditorplugin.cpp @@ -117,7 +117,7 @@ bool FormEditorPlugin::initialize(const QStringList &arguments, QString *error) void FormEditorPlugin::extensionsInitialized() { - DesignMode::instance()->setDesignModeIsRequired(); + DesignMode::setDesignModeIsRequired(); // 4) test and make sure everything works (undo, saving, editors, opening/closing multiple files, dirtiness etc) ActionContainer *mtools = ActionManager::actionContainer(Core::Constants::M_TOOLS); diff --git a/src/plugins/designer/formeditorw.cpp b/src/plugins/designer/formeditorw.cpp index e526c2f937..43e3149550 100644 --- a/src/plugins/designer/formeditorw.cpp +++ b/src/plugins/designer/formeditorw.cpp @@ -215,7 +215,6 @@ public: QList<Id> m_toolActionIds; QWidget *m_modeWidget = nullptr; EditorWidget *m_editorWidget = nullptr; - DesignMode *m_designMode = nullptr; QWidget *m_editorToolBar = nullptr; EditorToolBar *m_toolBar = nullptr; @@ -283,7 +282,7 @@ FormEditorData::~FormEditorData() m_editorWidget->saveSettings(s); s->endGroup(); - m_designMode->unregisterDesignWidget(m_modeWidget); + DesignMode::unregisterDesignWidget(m_modeWidget); delete m_modeWidget; m_modeWidget = nullptr; } @@ -406,7 +405,6 @@ void FormEditorData::fullInit() m_toolBar->setNavigationVisible(false); m_toolBar->addCenterToolBar(m_editorToolBar); - m_designMode = DesignMode::instance(); m_modeWidget = new QWidget; m_modeWidget->setObjectName("DesignerModeWidget"); QVBoxLayout *layout = new QVBoxLayout; @@ -417,7 +415,7 @@ void FormEditorData::fullInit() // 'Run' in 'Design' mode emits output. MiniSplitter *splitter = new MiniSplitter(Qt::Vertical); splitter->addWidget(m_editorWidget); - QWidget *outputPane = new OutputPanePlaceHolder(m_designMode->id(), splitter); + QWidget *outputPane = new OutputPanePlaceHolder(Core::Constants::MODE_DESIGN, splitter); outputPane->setObjectName("DesignerOutputPanePlaceHolder"); splitter->addWidget(outputPane); layout->addWidget(splitter); @@ -428,7 +426,7 @@ void FormEditorData::fullInit() m_context = new DesignerContext(designerContexts, m_modeWidget, m_instance); ICore::addContextObject(m_context); - m_designMode->registerDesignWidget(m_modeWidget, QStringList(FORM_MIMETYPE), m_contexts); + DesignMode::registerDesignWidget(m_modeWidget, QStringList(FORM_MIMETYPE), m_contexts); setupViewActions(); diff --git a/src/plugins/qmldesigner/qmldesignerplugin.cpp b/src/plugins/qmldesigner/qmldesignerplugin.cpp index a300537bec..21fd06824a 100644 --- a/src/plugins/qmldesigner/qmldesignerplugin.cpp +++ b/src/plugins/qmldesigner/qmldesignerplugin.cpp @@ -117,7 +117,7 @@ static bool checkIfEditorIsQtQuick(Core::IEditor *editor) static bool isDesignerMode(Core::Id mode) { - return mode == Core::DesignMode::instance()->id(); + return mode == Core::Constants::MODE_DESIGN; } static bool documentIsAlreadyOpen(DesignDocument *designDocument, Core::IEditor *editor, Core::Id newMode) @@ -158,7 +158,7 @@ QmlDesignerPlugin::QmlDesignerPlugin() QmlDesignerPlugin::~QmlDesignerPlugin() { if (d) { - Core::DesignMode::instance()->unregisterDesignWidget(d->mainWidget); + Core::DesignMode::unregisterDesignWidget(d->mainWidget); Core::ICore::removeContextObject(d->context); d->context = nullptr; } @@ -251,7 +251,7 @@ void QmlDesignerPlugin::integrateIntoQtCreator(QWidget *modeWidget) const QStringList mimeTypes = { QmlJSTools::Constants::QML_MIMETYPE, QmlJSTools::Constants::QMLUI_MIMETYPE }; - Core::DesignMode::instance()->registerDesignWidget(modeWidget, mimeTypes, d->context->context()); + Core::DesignMode::registerDesignWidget(modeWidget, mimeTypes, d->context->context()); connect(Core::DesignMode::instance(), &Core::DesignMode::actionsUpdated, &d->shortCutManager, &ShortCutManager::updateActions); diff --git a/src/plugins/scxmleditor/scxmleditordata.cpp b/src/plugins/scxmleditor/scxmleditordata.cpp index 49171fe146..c40639af48 100644 --- a/src/plugins/scxmleditor/scxmleditordata.cpp +++ b/src/plugins/scxmleditor/scxmleditordata.cpp @@ -118,7 +118,7 @@ ScxmlEditorData::~ScxmlEditorData() ICore::removeContextObject(m_context); if (m_modeWidget) { - m_designMode->unregisterDesignWidget(m_modeWidget); + DesignMode::unregisterDesignWidget(m_modeWidget); delete m_modeWidget; m_modeWidget = nullptr; } @@ -132,7 +132,6 @@ void ScxmlEditorData::fullInit() m_widgetStack = new ScxmlEditorStack; m_widgetToolBar = new QToolBar; m_mainToolBar = createMainToolBar(); - m_designMode = DesignMode::instance(); m_modeWidget = createModeWidget(); // Create undo/redo group/actions @@ -153,7 +152,7 @@ void ScxmlEditorData::fullInit() m_context = new ScxmlContext(scxmlContexts, m_modeWidget, this); ICore::addContextObject(m_context); - m_designMode->registerDesignWidget(m_modeWidget, QStringList(QLatin1String(ProjectExplorer::Constants::SCXML_MIMETYPE)), m_contexts); + DesignMode::registerDesignWidget(m_modeWidget, QStringList(QLatin1String(ProjectExplorer::Constants::SCXML_MIMETYPE)), m_contexts); } IEditor *ScxmlEditorData::createEditor() @@ -232,7 +231,7 @@ QWidget *ScxmlEditorData::createModeWidget() // 'Run' in 'Design' mode emits output. auto splitter = new MiniSplitter(Qt::Vertical); splitter->addWidget(m_widgetStack); - auto outputPane = new OutputPanePlaceHolder(m_designMode->id(), splitter); + auto outputPane = new OutputPanePlaceHolder(Core::Constants::MODE_DESIGN, splitter); outputPane->setObjectName("DesignerOutputPanePlaceHolder"); splitter->addWidget(outputPane); layout->addWidget(splitter); diff --git a/src/plugins/scxmleditor/scxmleditordata.h b/src/plugins/scxmleditor/scxmleditordata.h index 785e927531..cbe35cfd41 100644 --- a/src/plugins/scxmleditor/scxmleditordata.h +++ b/src/plugins/scxmleditor/scxmleditordata.h @@ -29,8 +29,8 @@ #include <QUndoGroup> #include <QCoreApplication> -#include <coreplugin/designmode.h> #include <coreplugin/editortoolbar.h> +#include <coreplugin/icontext.h> using namespace Core; @@ -61,7 +61,6 @@ private: Context m_contexts; QWidget *m_modeWidget = nullptr; ScxmlEditorStack *m_widgetStack = nullptr; - DesignMode *m_designMode = nullptr; QToolBar *m_widgetToolBar = nullptr; EditorToolBar *m_mainToolBar = nullptr; QUndoGroup *m_undoGroup = nullptr; diff --git a/src/plugins/scxmleditor/scxmleditorplugin.cpp b/src/plugins/scxmleditor/scxmleditorplugin.cpp index df5f355ff8..30bddf6b2f 100644 --- a/src/plugins/scxmleditor/scxmleditorplugin.cpp +++ b/src/plugins/scxmleditor/scxmleditorplugin.cpp @@ -58,7 +58,7 @@ bool ScxmlEditorPlugin::initialize(const QStringList &arguments, QString *errorS void ScxmlEditorPlugin::extensionsInitialized() { - DesignMode::instance()->setDesignModeIsRequired(); + DesignMode::setDesignModeIsRequired(); } ExtensionSystem::IPlugin::ShutdownFlag ScxmlEditorPlugin::aboutToShutdown() |