forked from qt-creator/qt-creator
Debugger: Start introducing dynamic perspectives
Make perspectives and tool bars destroyable. This is a step forward to multiply debugger engines whose perspective's life time is connected to the engine, not the debug mode. In the present setup there are two kind of perspective: 1 - static: with a lifetime associated to the application (or, rather, plugin that defines them). These are listed in the perspective chooser, later e.g. Debugger for pre-set breakpoints 2 - dynamic: with a shorted lifetime, e.g. running GDB engine. Presently, and possibly also in future so, a dynamic perspective is related to exactly one of the static perspectives, i.e. are kind of "child". Change-Id: Ic11572e7121e14f8da2927a0c0ac3441c99073a3 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -63,8 +63,10 @@ DEBUGGER_EXPORT void showCannotStartDialog(const QString &toolName);
|
||||
|
||||
// Register a tool for a given start mode.
|
||||
DEBUGGER_EXPORT void registerPerspective(const QByteArray &perspectiveId, const Utils::Perspective *perspective);
|
||||
DEBUGGER_EXPORT void destroyDynamicPerspective(const QByteArray &perspectiveId);
|
||||
DEBUGGER_EXPORT void setPerspectiveEnabled(const QByteArray &perspectiveId, bool enable);
|
||||
DEBUGGER_EXPORT void registerToolbar(const QByteArray &perspectiveId, const Utils::ToolbarDescription &desc);
|
||||
DEBUGGER_EXPORT void destroyDynamicToolbar(const QByteArray &perspectiveId);
|
||||
|
||||
DEBUGGER_EXPORT void enableMainWindow(bool on);
|
||||
DEBUGGER_EXPORT QWidget *mainWindow();
|
||||
|
@@ -103,10 +103,18 @@ DebuggerMainWindow::~DebuggerMainWindow()
|
||||
void DebuggerMainWindow::registerPerspective(const QByteArray &perspectiveId, const Perspective *perspective)
|
||||
{
|
||||
m_perspectiveForPerspectiveId.insert(perspectiveId, perspective);
|
||||
QByteArray parentPerspective = perspective->parentPerspective();
|
||||
// Add "main" perspectives to the chooser.
|
||||
if (parentPerspective.isEmpty()) {
|
||||
m_perspectiveChooser->addItem(perspective->name(), perspectiveId);
|
||||
// adjust width if necessary
|
||||
increaseChooserWidthIfNecessary(perspective->name());
|
||||
}
|
||||
}
|
||||
|
||||
void DebuggerMainWindow::increaseChooserWidthIfNecessary(const QString &visibleName)
|
||||
{
|
||||
const int oldWidth = m_perspectiveChooser->width();
|
||||
const int contentWidth = m_perspectiveChooser->fontMetrics().width(perspective->name());
|
||||
const int contentWidth = m_perspectiveChooser->fontMetrics().width(visibleName);
|
||||
QStyleOptionComboBox option;
|
||||
option.initFrom(m_perspectiveChooser);
|
||||
const QSize sz(contentWidth, 1);
|
||||
@@ -116,12 +124,35 @@ void DebuggerMainWindow::registerPerspective(const QByteArray &perspectiveId, co
|
||||
m_perspectiveChooser->setFixedWidth(width);
|
||||
}
|
||||
|
||||
void DebuggerMainWindow::destroyDynamicPerspective(const QByteArray &perspectiveId)
|
||||
{
|
||||
savePerspectiveHelper(perspectiveId);
|
||||
|
||||
const Perspective *perspective = m_perspectiveForPerspectiveId.take(perspectiveId);
|
||||
QTC_ASSERT(perspective, return);
|
||||
// Dynamic perspectives are currently not visible in the chooser.
|
||||
// This might change in the future, make sure we notice.
|
||||
const int idx = m_perspectiveChooser->findData(perspectiveId);
|
||||
QTC_ASSERT(idx == -1, m_perspectiveChooser->removeItem(idx));
|
||||
QByteArray parentPerspective = perspective->parentPerspective();
|
||||
delete perspective;
|
||||
// All dynamic perspectives currently have a static parent perspective.
|
||||
// This might change in the future, make sure we notice.
|
||||
QTC_CHECK(!parentPerspective.isEmpty());
|
||||
restorePerspective(parentPerspective);
|
||||
}
|
||||
|
||||
void DebuggerMainWindow::registerToolbar(const QByteArray &perspectiveId, QWidget *widget)
|
||||
{
|
||||
m_toolbarForPerspectiveId.insert(perspectiveId, widget);
|
||||
m_controlsStackWidget->addWidget(widget);
|
||||
}
|
||||
|
||||
void DebuggerMainWindow::destroyDynamicToolbar(const QByteArray &perspectiveId)
|
||||
{
|
||||
delete m_toolbarForPerspectiveId.take(perspectiveId);
|
||||
}
|
||||
|
||||
void DebuggerMainWindow::showStatusMessage(const QString &message, int timeoutMS)
|
||||
{
|
||||
m_statusLabel->showStatusMessage(message, timeoutMS);
|
||||
@@ -456,6 +487,16 @@ void Perspective::aboutToActivate() const
|
||||
m_aboutToActivateCallback();
|
||||
}
|
||||
|
||||
QByteArray Perspective::parentPerspective() const
|
||||
{
|
||||
return m_parentPerspective;
|
||||
}
|
||||
|
||||
void Perspective::setParentPerspective(const QByteArray &parentPerspective)
|
||||
{
|
||||
m_parentPerspective = parentPerspective;
|
||||
}
|
||||
|
||||
QList<QWidget *> ToolbarDescription::widgets() const
|
||||
{
|
||||
return m_widgets;
|
||||
|
@@ -92,11 +92,15 @@ public:
|
||||
void setAboutToActivateCallback(const Callback &cb);
|
||||
void aboutToActivate() const;
|
||||
|
||||
QByteArray parentPerspective() const;
|
||||
void setParentPerspective(const QByteArray &parentPerspective);
|
||||
|
||||
private:
|
||||
Perspective(const Perspective &) = delete;
|
||||
void operator=(const Perspective &) = delete;
|
||||
|
||||
QString m_name;
|
||||
QByteArray m_parentPerspective;
|
||||
QVector<QByteArray> m_docks;
|
||||
QVector<Operation> m_operations;
|
||||
QPointer<QWidget> m_centralWidget;
|
||||
@@ -127,7 +131,9 @@ public:
|
||||
~DebuggerMainWindow() override;
|
||||
|
||||
void registerPerspective(const QByteArray &perspectiveId, const Perspective *perspective);
|
||||
void destroyDynamicPerspective(const QByteArray &perspectiveId);
|
||||
void registerToolbar(const QByteArray &perspectiveId, QWidget *widget);
|
||||
void destroyDynamicToolbar(const QByteArray &perspectiveId);
|
||||
|
||||
void resetCurrentPerspective();
|
||||
void restorePerspective(const QByteArray &perspectiveId);
|
||||
@@ -150,6 +156,7 @@ private:
|
||||
QDockWidget *registerDockWidget(const QByteArray &dockId, QWidget *widget);
|
||||
void loadPerspectiveHelper(const QByteArray &perspectiveId, bool fromStoredSettings = true);
|
||||
void savePerspectiveHelper(const QByteArray &perspectiveId);
|
||||
void increaseChooserWidthIfNecessary(const QString &visibleName);
|
||||
|
||||
QByteArray m_currentPerspectiveId;
|
||||
QComboBox *m_perspectiveChooser;
|
||||
|
@@ -3494,6 +3494,11 @@ void registerToolbar(const QByteArray &perspectiveId, const ToolbarDescription &
|
||||
dd->m_mainWindow->registerToolbar(perspectiveId, toolbar);
|
||||
}
|
||||
|
||||
void destroyDynamicToolbar(const QByteArray &perspectiveId)
|
||||
{
|
||||
dd->m_mainWindow->destroyDynamicToolbar(perspectiveId);
|
||||
}
|
||||
|
||||
QAction *createStartAction()
|
||||
{
|
||||
auto action = new QAction(DebuggerMainWindow::tr("Start"), DebuggerPlugin::instance());
|
||||
@@ -3515,6 +3520,11 @@ void registerPerspective(const QByteArray &perspectiveId, const Perspective *per
|
||||
dd->m_mainWindow->registerPerspective(perspectiveId, perspective);
|
||||
}
|
||||
|
||||
void destroyDynamicPerspective(const QByteArray &perspectiveId)
|
||||
{
|
||||
dd->m_mainWindow->destroyDynamicPerspective(perspectiveId);
|
||||
}
|
||||
|
||||
void setPerspectiveEnabled(const QByteArray &perspectiveId, bool enabled)
|
||||
{
|
||||
dd->m_mainWindow->setPerspectiveEnabled(perspectiveId, enabled);
|
||||
|
Reference in New Issue
Block a user