From 375791ec58a8b801e57aa719ba16b5983efd0893 Mon Sep 17 00:00:00 2001 From: hjk Date: Tue, 11 Sep 2018 11:24:19 +0200 Subject: [PATCH] Debugger: Re-organize registration of sub-perspective switcher Change-Id: Ia3559e5c4793bb297c9bdfbdf32a56d285ee0700 Reviewed-by: Eike Ziller --- src/plugins/debugger/debuggerengine.cpp | 2 +- src/plugins/debugger/debuggermainwindow.cpp | 29 ++++++++++++--------- src/plugins/debugger/debuggermainwindow.h | 6 +++-- src/plugins/debugger/debuggerplugin.cpp | 4 +-- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/plugins/debugger/debuggerengine.cpp b/src/plugins/debugger/debuggerengine.cpp index 49138ef1e1d..63811b25952 100644 --- a/src/plugins/debugger/debuggerengine.cpp +++ b/src/plugins/debugger/debuggerengine.cpp @@ -667,7 +667,7 @@ void DebuggerEnginePrivate::setupViews() m_breakWindow->setObjectName(DOCKWIDGET_BREAK); m_breakWindow->setWindowTitle(tr("&Breakpoints")); - m_perspective->addToolBarSwitcher(EngineManager::engineChooser(), false); + m_perspective->useSubPerspectiveSwitcher(EngineManager::engineChooser()); m_perspective->addToolBarAction(&m_continueAction); m_perspective->addToolBarAction(&m_interruptAction); diff --git a/src/plugins/debugger/debuggermainwindow.cpp b/src/plugins/debugger/debuggermainwindow.cpp index bc7933df2ca..d8a45e55b30 100644 --- a/src/plugins/debugger/debuggermainwindow.cpp +++ b/src/plugins/debugger/debuggermainwindow.cpp @@ -122,7 +122,7 @@ public: Perspective *m_currentPerspective = nullptr; QComboBox *m_perspectiveChooser = nullptr; QStackedWidget *m_centralWidgetStack = nullptr; - QHBoxLayout *m_subToolsSwitcherLayout = nullptr; + QHBoxLayout *m_subPerspectiveSwitcherLayout = nullptr; QHBoxLayout *m_innerToolsLayout = nullptr; QWidget *m_editorPlaceHolder = nullptr; Utils::StatusLabel *m_statusLabel = nullptr; @@ -165,10 +165,10 @@ DebuggerMainWindowPrivate::DebuggerMainWindowPrivate(DebuggerMainWindow *parent) toolbar->setProperty("topBorder", true); // "Engine switcher" style comboboxes - auto subToolsSwitcher = new QWidget; - m_subToolsSwitcherLayout = new QHBoxLayout(subToolsSwitcher); - m_subToolsSwitcherLayout->setMargin(0); - m_subToolsSwitcherLayout->setSpacing(0); + auto subPerspectiveSwitcher = new QWidget; + m_subPerspectiveSwitcherLayout = new QHBoxLayout(subPerspectiveSwitcher); + m_subPerspectiveSwitcherLayout->setMargin(0); + m_subPerspectiveSwitcherLayout->setSpacing(0); // All perspective toolbars will get inserted here, but only // the current perspective's toolbar is set visible. @@ -181,7 +181,7 @@ DebuggerMainWindowPrivate::DebuggerMainWindowPrivate(DebuggerMainWindow *parent) hbox->setMargin(0); hbox->setSpacing(0); hbox->addWidget(m_perspectiveChooser); - hbox->addWidget(subToolsSwitcher); + hbox->addWidget(subPerspectiveSwitcher); hbox->addWidget(innerTools); hbox->addWidget(m_statusLabel); hbox->addStretch(1); @@ -332,6 +332,13 @@ QWidget *DebuggerMainWindow::centralWidgetStack() return theMainWindow ? theMainWindow->d->m_centralWidgetStack : nullptr; } +void DebuggerMainWindow::setSubPerspectiveSwitcher(QWidget *widget) +{ + widget->setVisible(false); + widget->setProperty("panelwidget", true); + d->m_subPerspectiveSwitcherLayout->addWidget(widget); +} + DebuggerMainWindow *DebuggerMainWindow::instance() { return theMainWindow; @@ -393,8 +400,10 @@ void DebuggerMainWindowPrivate::selectPerspective(Perspective *perspective) } } -QWidget *createModeWindow(const Core::Id &mode) +QWidget *createModeWindow(const Core::Id &mode, QWidget *switcher) { + theMainWindow->setSubPerspectiveSwitcher(switcher); + auto editorHolderLayout = new QVBoxLayout; editorHolderLayout->setMargin(0); editorHolderLayout->setSpacing(0); @@ -633,13 +642,9 @@ void Perspective::addToolBarWidget(QWidget *widget) d->m_innerToolBarLayout->addWidget(widget); } -void Perspective::addToolBarSwitcher(QWidget *widget, bool owner) +void Perspective::useSubPerspectiveSwitcher(QWidget *widget) { d->m_switcher = widget; - d->m_switcher->setProperty("panelwidget", true); - d->m_switcher->setVisible(false); - if (owner) - theMainWindow->d->m_subToolsSwitcherLayout->addWidget(d->m_switcher); } void Perspective::addToolbarSeparator() diff --git a/src/plugins/debugger/debuggermainwindow.h b/src/plugins/debugger/debuggermainwindow.h index da9072dfd0d..bb057b7b482 100644 --- a/src/plugins/debugger/debuggermainwindow.h +++ b/src/plugins/debugger/debuggermainwindow.h @@ -79,9 +79,10 @@ public: void addToolBarAction(QAction *action); void addToolBarAction(OptionalAction *action); void addToolBarWidget(QWidget *widget); - void addToolBarSwitcher(QWidget *widget, bool owner); void addToolbarSeparator(); + void useSubPerspectiveSwitcher(QWidget *widget); + using ShouldPersistChecker = std::function; void setShouldPersistChecker(const ShouldPersistChecker &checker); @@ -127,6 +128,7 @@ public: static void onModeChanged(Core::Id mode); static QWidget *centralWidgetStack(); + void setSubPerspectiveSwitcher(QWidget *widget); private: DebuggerMainWindow(); @@ -137,6 +139,6 @@ private: class DebuggerMainWindowPrivate *d = nullptr; }; -DEBUGGER_EXPORT QWidget *createModeWindow(const Core::Id &mode); +DEBUGGER_EXPORT QWidget *createModeWindow(const Core::Id &mode, QWidget *); } // Utils diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp index d2d269afbf2..862c23f658e 100644 --- a/src/plugins/debugger/debuggerplugin.cpp +++ b/src/plugins/debugger/debuggerplugin.cpp @@ -1296,7 +1296,7 @@ bool DebuggerPluginPrivate::initialize(const QStringList &arguments, // Debug mode setup m_mode = new DebugMode; - m_modeWindow = createModeWindow(Constants::MODE_DEBUG); + m_modeWindow = createModeWindow(Constants::MODE_DEBUG, EngineManager::engineChooser()); m_mode->setWidget(m_modeWindow); m_debugModeContext.setContext(Context(CC::C_EDITORMANAGER)); @@ -1339,7 +1339,7 @@ bool DebuggerPluginPrivate::initialize(const QStringList &arguments, connect(action(SettingsDialog), &QAction::triggered, [] { ICore::showOptionsDialog(DEBUGGER_COMMON_SETTINGS_ID); }); - m_perspective.addToolBarSwitcher(EngineManager::engineChooser(), true); + m_perspective.useSubPerspectiveSwitcher(EngineManager::engineChooser()); m_perspective.addToolBarAction(&m_startAction); // QAction *operateByInstructionAction = action(OperateByInstruction);