From 72cca4855dfe07b79234e0b82956e1a177ee68f8 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Fri, 26 Aug 2016 13:33:30 +0200 Subject: [PATCH] Debugger: Have main window handle mode change separately On shutdown the DebuggerMainWindow might not be alive anymore. By connecting the signal handler to the window, rather than the plugin we avoid dereferencing null pointers in that case. Change-Id: I6421eebc6b1b76f176b31eafeb039d91edd3f0b3 Reviewed-by: hjk --- src/plugins/debugger/debuggermainwindow.cpp | 16 ++++++++++++++++ src/plugins/debugger/debuggermainwindow.h | 2 ++ src/plugins/debugger/debuggerplugin.cpp | 11 ++--------- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/plugins/debugger/debuggermainwindow.cpp b/src/plugins/debugger/debuggermainwindow.cpp index 7821532832b..77b7f514704 100644 --- a/src/plugins/debugger/debuggermainwindow.cpp +++ b/src/plugins/debugger/debuggermainwindow.cpp @@ -126,6 +126,22 @@ QDockWidget *DebuggerMainWindow::dockWidget(const QByteArray &dockId) const return m_dockForDockId.value(dockId); } +void DebuggerMainWindow::onModeChanged(Core::Id mode) +{ + if (mode == Debugger::Constants::MODE_DEBUG) { + setDockActionsVisible(true); + restorePerspective({}); + } else { + setDockActionsVisible(false); + + // Hide dock widgets manually in case they are floating. + foreach (QDockWidget *dockWidget, dockWidgets()) { + if (dockWidget->isFloating()) + dockWidget->hide(); + } + } +} + void DebuggerMainWindow::resetCurrentPerspective() { loadPerspectiveHelper(m_currentPerspectiveId, false); diff --git a/src/plugins/debugger/debuggermainwindow.h b/src/plugins/debugger/debuggermainwindow.h index d7dd6460be9..0e8a9f5c81d 100644 --- a/src/plugins/debugger/debuggermainwindow.h +++ b/src/plugins/debugger/debuggermainwindow.h @@ -129,6 +129,8 @@ public: QByteArray currentPerspective() const { return m_currentPerspectiveId; } QStackedWidget *centralWidgetStack() const { return m_centralWidgetStack; } + void onModeChanged(Core::Id mode); + private: QDockWidget *registerDockWidget(const QByteArray &dockId, QWidget *widget); void loadPerspectiveHelper(const QByteArray &perspectiveId, bool fromStoredSettings = true); diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp index b08c29a5e7a..0d4afff535b 100644 --- a/src/plugins/debugger/debuggerplugin.cpp +++ b/src/plugins/debugger/debuggerplugin.cpp @@ -1770,6 +1770,8 @@ bool DebuggerPluginPrivate::initialize(const QStringList &arguments, connect(ModeManager::instance(), &ModeManager::currentModeChanged, this, &DebuggerPluginPrivate::onModeChanged); + connect(ModeManager::instance(), &ModeManager::currentModeChanged, + m_mainWindow.data(), &DebuggerMainWindow::onModeChanged); connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::settingsChanged, this, &DebuggerPluginPrivate::updateDebugWithoutDeployMenu); @@ -3386,8 +3388,6 @@ void DebuggerPluginPrivate::onModeChanged(Id mode) editor->widget()->setFocus(); m_toolTipManager.debugModeEntered(); - m_mainWindow->setDockActionsVisible(true); - m_mainWindow->restorePerspective({}); // static bool firstTime = true; // if (firstTime) { @@ -3405,13 +3405,6 @@ void DebuggerPluginPrivate::onModeChanged(Id mode) updateActiveLanguages(); } else { m_toolTipManager.leavingDebugMode(); - m_mainWindow->setDockActionsVisible(false); - - // Hide dock widgets manually in case they are floating. - foreach (QDockWidget *dockWidget, m_mainWindow->dockWidgets()) { - if (dockWidget->isFloating()) - dockWidget->hide(); - } } }