forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -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();
|
||||
|
@@ -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
|
||||
|
@@ -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,
|
||||
static void registerDesignWidget(QWidget *widget,
|
||||
const QStringList &mimeTypes,
|
||||
const Context &context);
|
||||
void unregisterDesignWidget(QWidget *widget);
|
||||
|
||||
QStringList registeredMimeTypes() const;
|
||||
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
|
||||
|
@@ -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);
|
||||
|
@@ -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();
|
||||
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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;
|
||||
|
@@ -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()
|
||||
|
Reference in New Issue
Block a user