forked from qt-creator/qt-creator
DesignMode: Create only when needed
Postpone the Mode object creation until it is really necessary,
the private data object may be needed before.
In the QmlDesigner this patch moves the connection to the DesignMode
instance back to delayedInitialize, essentially reverting part of
e8b3b8140b.
Change-Id: I07146b0bc93eede09af8e824e916edb6de1817ef
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -29,10 +29,11 @@
|
||||
#include <coreplugin/idocument.h>
|
||||
#include <coreplugin/modemanager.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
#include <coreplugin/coreconstants.h>
|
||||
#include <coreplugin/coreicons.h>
|
||||
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
|
||||
#include <QPointer>
|
||||
#include <QStringList>
|
||||
@@ -59,7 +60,6 @@ public:
|
||||
public:
|
||||
QPointer<IEditor> m_currentEditor;
|
||||
bool m_isActive = false;
|
||||
bool m_isRequired = false;
|
||||
QList<DesignEditorInfo*> m_editors;
|
||||
QStackedWidget *m_stackWidget;
|
||||
Context m_activeContext;
|
||||
@@ -79,9 +79,6 @@ static DesignModePrivate *d = nullptr;
|
||||
|
||||
DesignMode::DesignMode()
|
||||
{
|
||||
m_instance = this;
|
||||
d = new DesignModePrivate;
|
||||
|
||||
ICore::addPreCloseListener([]() -> bool {
|
||||
m_instance->currentEditorChanged(0);
|
||||
return true;
|
||||
@@ -107,7 +104,6 @@ DesignMode::DesignMode()
|
||||
DesignMode::~DesignMode()
|
||||
{
|
||||
qDeleteAll(d->m_editors);
|
||||
delete d;
|
||||
}
|
||||
|
||||
DesignMode *DesignMode::instance()
|
||||
@@ -117,12 +113,9 @@ DesignMode *DesignMode::instance()
|
||||
|
||||
void DesignMode::setDesignModeIsRequired()
|
||||
{
|
||||
d->m_isRequired = true;
|
||||
}
|
||||
|
||||
bool DesignMode::designModeIsRequired()
|
||||
{
|
||||
return d->m_isRequired;
|
||||
// d != nullptr indicates "isRequired".
|
||||
if (!d)
|
||||
d = new DesignModePrivate;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -227,4 +220,21 @@ void DesignMode::setActiveContext(const Context &context)
|
||||
d->m_activeContext = context;
|
||||
}
|
||||
|
||||
void DesignMode::createModeIfRequired()
|
||||
{
|
||||
if (d) {
|
||||
m_instance = new DesignMode;
|
||||
ExtensionSystem::PluginManager::addObject(m_instance);
|
||||
}
|
||||
}
|
||||
|
||||
void DesignMode::destroyModeIfRequired()
|
||||
{
|
||||
if (m_instance) {
|
||||
ExtensionSystem::PluginManager::removeObject(m_instance);
|
||||
delete m_instance;
|
||||
}
|
||||
delete d;
|
||||
}
|
||||
|
||||
} // namespace Core
|
||||
|
||||
Reference in New Issue
Block a user