forked from qt-creator/qt-creator
Core: Add a way to delay-construct mode widgets
... and use it for edit mode. There's currently no real effect as the mode bar population in ModeManagerPrivate::extensionsInitializedHelper() accesses all IMode::widget() and triggers the creation, but in principle we could pass the functor instead of the widget down to and store in FancyTabWidget and only use it when a mode gets activated. Change-Id: I4c4a276bc025abce1ff47c68b060c67b5c8e5170 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -74,14 +74,11 @@ EditMode::EditMode()
|
||||
connect(ModeManager::instance(), &ModeManager::currentModeChanged,
|
||||
this, &EditMode::grabEditorManager);
|
||||
|
||||
setWidget(new EditModeWidget);
|
||||
setWidgetCreator([] { return new EditModeWidget; });
|
||||
setContext(Context(Constants::C_EDIT_MODE, Constants::C_NAVIGATION_PANE));
|
||||
}
|
||||
|
||||
EditMode::~EditMode()
|
||||
{
|
||||
delete widget();
|
||||
}
|
||||
EditMode::~EditMode() = default;
|
||||
|
||||
void EditMode::grabEditorManager(Utils::Id mode)
|
||||
{
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <utils/aspects.h>
|
||||
#include <utils/fancymainwindow.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <aggregation/aggregate.h>
|
||||
|
||||
@@ -27,6 +28,7 @@ public:
|
||||
Utils::Id m_id;
|
||||
Context m_context;
|
||||
QPointer<QWidget> m_widget;
|
||||
std::function<QWidget *()> m_widgetCreator;
|
||||
bool m_isEnabled = true;
|
||||
BoolAspect m_isVisible;
|
||||
};
|
||||
@@ -127,7 +129,11 @@ IMode::IMode(QObject *parent)
|
||||
ModeManager::addMode(this);
|
||||
}
|
||||
|
||||
IMode::~IMode() = default;
|
||||
IMode::~IMode()
|
||||
{
|
||||
if (m_d->m_widgetCreator)
|
||||
delete m_d->m_widget;
|
||||
}
|
||||
|
||||
QString IMode::displayName() const
|
||||
{
|
||||
@@ -203,9 +209,18 @@ void IMode::setContext(const Context &context)
|
||||
|
||||
void IMode::setWidget(QWidget *widget)
|
||||
{
|
||||
QTC_ASSERT(!m_d->m_widgetCreator,
|
||||
qWarning("A mode widget should not be set if there is already a widget creator"));
|
||||
m_d->m_widget = widget;
|
||||
}
|
||||
|
||||
void IMode::setWidgetCreator(const std::function<QWidget *()> &widgetCreator)
|
||||
{
|
||||
QTC_ASSERT(!m_d->m_widget,
|
||||
qWarning("A mode widget widgetCreator should not be set if there is already a widget"));
|
||||
m_d->m_widgetCreator = widgetCreator;
|
||||
}
|
||||
|
||||
Utils::FancyMainWindow *IMode::mainWindow()
|
||||
{
|
||||
if (m_d->m_mainWindow)
|
||||
@@ -257,6 +272,8 @@ Context IMode::context() const
|
||||
|
||||
QWidget *IMode::widget() const
|
||||
{
|
||||
if (!m_d->m_widget && m_d->m_widgetCreator)
|
||||
m_d->m_widget = m_d->m_widgetCreator();
|
||||
return m_d->m_widget;
|
||||
}
|
||||
|
||||
|
||||
@@ -56,6 +56,7 @@ public:
|
||||
void setMenu(std::function<void(QMenu *)> menuFunction);
|
||||
void setContext(const Context &context);
|
||||
void setWidget(QWidget *widget);
|
||||
void setWidgetCreator(const std::function<QWidget *()> &widgetCreator);
|
||||
|
||||
Utils::FancyMainWindow *mainWindow();
|
||||
void setMainWindow(Utils::FancyMainWindow *mw);
|
||||
|
||||
@@ -500,13 +500,11 @@ public:
|
||||
setPriority(85);
|
||||
setId(MODE_DEBUG);
|
||||
|
||||
setWidget(new DebugModeWidget);
|
||||
setWidgetCreator([] { return new DebugModeWidget; });
|
||||
setMainWindow(DebuggerMainWindow::instance());
|
||||
|
||||
setMenu(&DebuggerMainWindow::addPerspectiveMenu);
|
||||
}
|
||||
|
||||
~DebugMode() { delete widget(); }
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user