From 763a1cfc06b23d9ce621c6319fb6b241bf8ad338 Mon Sep 17 00:00:00 2001 From: hjk Date: Wed, 22 Aug 2018 11:53:37 +0200 Subject: [PATCH] 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 --- src/plugins/debugger/debuggermainwindow.cpp | 32 ++++++++++++--------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/plugins/debugger/debuggermainwindow.cpp b/src/plugins/debugger/debuggermainwindow.cpp index 9a94aa22e11..4b0e1439d33 100644 --- a/src/plugins/debugger/debuggermainwindow.cpp +++ b/src/plugins/debugger/debuggermainwindow.cpp @@ -64,6 +64,7 @@ using namespace Core; namespace Utils { const char LAST_PERSPECTIVE_KEY[] = "LastPerspective"; +const char OWNED_BY_PERSPECTIVE[] = "OwnedByPerspective"; static DebuggerMainWindow *theMainWindow = nullptr; @@ -129,7 +130,7 @@ class DockOperation { public: QPointer widget; - QByteArray anchorDockId; + QString anchorDockId; Perspective::OperationType operationType = Perspective::Raise; bool visibleByDefault = true; Qt::DockWidgetArea area = Qt::BottomDockWidgetArea; @@ -179,7 +180,6 @@ public: Utils::StatusLabel *m_statusLabel = nullptr; QDockWidget *m_toolBarDock = nullptr; - QHash m_dockForDockId; QList m_perspectives; }; @@ -465,14 +465,16 @@ void DebuggerMainWindowPrivate::loadPerspectiveHelper(Perspective *perspective, // Clean up old perspective. if (m_currentPerspective) { savePerspectiveHelper(m_currentPerspective); - for (QDockWidget *dock : m_dockForDockId) { - dock->setParent(nullptr); - dock->widget()->setParent(nullptr); - ActionManager::unregisterAction(dock->toggleViewAction(), - Id("Dock.").withSuffix(dock->objectName())); - delete dock; + const QList allDocks = q->dockWidgets(); + for (QDockWidget *dock : allDocks) { + if (dock->property(OWNED_BY_PERSPECTIVE).toBool()) { + dock->setParent(nullptr); + dock->widget()->setParent(nullptr); + ActionManager::unregisterAction(dock->toggleViewAction(), + Id("Dock.").withSuffix(dock->objectName())); + delete dock; + } } - m_dockForDockId.clear(); ICore::removeAdditionalContext(m_currentPerspective->context()); QWidget *central = m_currentPerspective->centralWidget(); @@ -499,14 +501,16 @@ void DebuggerMainWindowPrivate::loadPerspectiveHelper(Perspective *perspective, m_currentPerspective->aboutToActivate(); + QHash dockForDockId; for (const DockOperation &op : m_currentPerspective->d->m_dockOperations) { QTC_ASSERT(op.widget, continue); - const QByteArray dockId = op.widget->objectName().toUtf8(); - QDockWidget *dock = m_dockForDockId.value(dockId); + const QString dockId = op.widget->objectName(); + QDockWidget *dock = dockForDockId.value(dockId); if (!dock) { QTC_CHECK(!dockId.isEmpty()); dock = q->addDockForWidget(op.widget); - m_dockForDockId[dockId] = dock; + dock->setProperty(OWNED_BY_PERSPECTIVE, true); + dockForDockId[dockId] = dock; QAction *toggleViewAction = dock->toggleViewAction(); toggleViewAction->setText(dock->windowTitle()); @@ -525,7 +529,7 @@ void DebuggerMainWindowPrivate::loadPerspectiveHelper(Perspective *perspective, continue; } q->addDockWidget(op.area, dock); - QDockWidget *anchor = m_dockForDockId.value(op.anchorDockId); + QDockWidget *anchor = dockForDockId.value(op.anchorDockId); if (!anchor && op.area == Qt::BottomDockWidgetArea) { ensureToolBarDockExists(); anchor = m_toolBarDock; @@ -736,7 +740,7 @@ void Perspective::addWindow(QWidget *widget, DockOperation op; op.widget = widget; if (anchorWidget) - op.anchorDockId = anchorWidget->objectName().toUtf8(); + op.anchorDockId = anchorWidget->objectName(); op.operationType = type; op.visibleByDefault = visibleByDefault; op.area = area;