forked from qt-creator/qt-creator
Debugger: Simplify keeping track of perspective dock widgets
It's essentially a property of the dock widget, and we fully control it. So store the information there. Also, using QString as id saves a few conversions. Change-Id: I9e1add60c8451127363aba67eec295001cc3425b Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -64,6 +64,7 @@ using namespace Core;
|
|||||||
namespace Utils {
|
namespace Utils {
|
||||||
|
|
||||||
const char LAST_PERSPECTIVE_KEY[] = "LastPerspective";
|
const char LAST_PERSPECTIVE_KEY[] = "LastPerspective";
|
||||||
|
const char OWNED_BY_PERSPECTIVE[] = "OwnedByPerspective";
|
||||||
|
|
||||||
static DebuggerMainWindow *theMainWindow = nullptr;
|
static DebuggerMainWindow *theMainWindow = nullptr;
|
||||||
|
|
||||||
@@ -129,7 +130,7 @@ class DockOperation
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
QPointer<QWidget> widget;
|
QPointer<QWidget> widget;
|
||||||
QByteArray anchorDockId;
|
QString anchorDockId;
|
||||||
Perspective::OperationType operationType = Perspective::Raise;
|
Perspective::OperationType operationType = Perspective::Raise;
|
||||||
bool visibleByDefault = true;
|
bool visibleByDefault = true;
|
||||||
Qt::DockWidgetArea area = Qt::BottomDockWidgetArea;
|
Qt::DockWidgetArea area = Qt::BottomDockWidgetArea;
|
||||||
@@ -179,7 +180,6 @@ public:
|
|||||||
Utils::StatusLabel *m_statusLabel = nullptr;
|
Utils::StatusLabel *m_statusLabel = nullptr;
|
||||||
QDockWidget *m_toolBarDock = nullptr;
|
QDockWidget *m_toolBarDock = nullptr;
|
||||||
|
|
||||||
QHash<QByteArray, QDockWidget *> m_dockForDockId;
|
|
||||||
QList<Perspective *> m_perspectives;
|
QList<Perspective *> m_perspectives;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -465,14 +465,16 @@ void DebuggerMainWindowPrivate::loadPerspectiveHelper(Perspective *perspective,
|
|||||||
// Clean up old perspective.
|
// Clean up old perspective.
|
||||||
if (m_currentPerspective) {
|
if (m_currentPerspective) {
|
||||||
savePerspectiveHelper(m_currentPerspective);
|
savePerspectiveHelper(m_currentPerspective);
|
||||||
for (QDockWidget *dock : m_dockForDockId) {
|
const QList<QDockWidget *> allDocks = q->dockWidgets();
|
||||||
dock->setParent(nullptr);
|
for (QDockWidget *dock : allDocks) {
|
||||||
dock->widget()->setParent(nullptr);
|
if (dock->property(OWNED_BY_PERSPECTIVE).toBool()) {
|
||||||
ActionManager::unregisterAction(dock->toggleViewAction(),
|
dock->setParent(nullptr);
|
||||||
Id("Dock.").withSuffix(dock->objectName()));
|
dock->widget()->setParent(nullptr);
|
||||||
delete dock;
|
ActionManager::unregisterAction(dock->toggleViewAction(),
|
||||||
|
Id("Dock.").withSuffix(dock->objectName()));
|
||||||
|
delete dock;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
m_dockForDockId.clear();
|
|
||||||
|
|
||||||
ICore::removeAdditionalContext(m_currentPerspective->context());
|
ICore::removeAdditionalContext(m_currentPerspective->context());
|
||||||
QWidget *central = m_currentPerspective->centralWidget();
|
QWidget *central = m_currentPerspective->centralWidget();
|
||||||
@@ -499,14 +501,16 @@ void DebuggerMainWindowPrivate::loadPerspectiveHelper(Perspective *perspective,
|
|||||||
|
|
||||||
m_currentPerspective->aboutToActivate();
|
m_currentPerspective->aboutToActivate();
|
||||||
|
|
||||||
|
QHash<QString, QDockWidget *> dockForDockId;
|
||||||
for (const DockOperation &op : m_currentPerspective->d->m_dockOperations) {
|
for (const DockOperation &op : m_currentPerspective->d->m_dockOperations) {
|
||||||
QTC_ASSERT(op.widget, continue);
|
QTC_ASSERT(op.widget, continue);
|
||||||
const QByteArray dockId = op.widget->objectName().toUtf8();
|
const QString dockId = op.widget->objectName();
|
||||||
QDockWidget *dock = m_dockForDockId.value(dockId);
|
QDockWidget *dock = dockForDockId.value(dockId);
|
||||||
if (!dock) {
|
if (!dock) {
|
||||||
QTC_CHECK(!dockId.isEmpty());
|
QTC_CHECK(!dockId.isEmpty());
|
||||||
dock = q->addDockForWidget(op.widget);
|
dock = q->addDockForWidget(op.widget);
|
||||||
m_dockForDockId[dockId] = dock;
|
dock->setProperty(OWNED_BY_PERSPECTIVE, true);
|
||||||
|
dockForDockId[dockId] = dock;
|
||||||
|
|
||||||
QAction *toggleViewAction = dock->toggleViewAction();
|
QAction *toggleViewAction = dock->toggleViewAction();
|
||||||
toggleViewAction->setText(dock->windowTitle());
|
toggleViewAction->setText(dock->windowTitle());
|
||||||
@@ -525,7 +529,7 @@ void DebuggerMainWindowPrivate::loadPerspectiveHelper(Perspective *perspective,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
q->addDockWidget(op.area, dock);
|
q->addDockWidget(op.area, dock);
|
||||||
QDockWidget *anchor = m_dockForDockId.value(op.anchorDockId);
|
QDockWidget *anchor = dockForDockId.value(op.anchorDockId);
|
||||||
if (!anchor && op.area == Qt::BottomDockWidgetArea) {
|
if (!anchor && op.area == Qt::BottomDockWidgetArea) {
|
||||||
ensureToolBarDockExists();
|
ensureToolBarDockExists();
|
||||||
anchor = m_toolBarDock;
|
anchor = m_toolBarDock;
|
||||||
@@ -736,7 +740,7 @@ void Perspective::addWindow(QWidget *widget,
|
|||||||
DockOperation op;
|
DockOperation op;
|
||||||
op.widget = widget;
|
op.widget = widget;
|
||||||
if (anchorWidget)
|
if (anchorWidget)
|
||||||
op.anchorDockId = anchorWidget->objectName().toUtf8();
|
op.anchorDockId = anchorWidget->objectName();
|
||||||
op.operationType = type;
|
op.operationType = type;
|
||||||
op.visibleByDefault = visibleByDefault;
|
op.visibleByDefault = visibleByDefault;
|
||||||
op.area = area;
|
op.area = area;
|
||||||
|
Reference in New Issue
Block a user