diff --git a/src/plugins/clangtools/clangtidyclazytool.cpp b/src/plugins/clangtools/clangtidyclazytool.cpp index 059f9a2d53b..a96cf56dff2 100644 --- a/src/plugins/clangtools/clangtidyclazytool.cpp +++ b/src/plugins/clangtools/clangtidyclazytool.cpp @@ -271,7 +271,6 @@ ClangTidyClazyTool::ClangTidyClazyTool() auto perspective = new Perspective(tr("Clang-Tidy and Clazy")); perspective->addWindow(m_diagnosticView, Perspective::SplitVertical, nullptr); - Debugger::registerPerspective(ClangTidyClazyPerspectiveId, perspective); action = new QAction(tr("Clang-Tidy and Clazy..."), this); action->setToolTip(toolTip); @@ -283,14 +282,14 @@ ClangTidyClazyTool::ClangTidyClazyTool() action->setEnabled(m_startAction->isEnabled()); }); - ToolbarDescription tidyClazyToolbar; - tidyClazyToolbar.addAction(m_startAction); - tidyClazyToolbar.addAction(m_stopAction); - tidyClazyToolbar.addAction(m_goBack); - tidyClazyToolbar.addAction(m_goNext); - tidyClazyToolbar.addWidget(m_filterLineEdit); - tidyClazyToolbar.addWidget(m_applyFixitsButton); - Debugger::registerToolbar(ClangTidyClazyPerspectiveId, tidyClazyToolbar); + perspective->addToolbarAction(m_startAction); + perspective->addToolbarAction(m_stopAction); + perspective->addToolbarAction(m_goBack); + perspective->addToolbarAction(m_goNext); + perspective->addToolbarWidget(m_filterLineEdit); + perspective->addToolbarWidget(m_applyFixitsButton); + + Debugger::registerPerspective(ClangTidyClazyPerspectiveId, perspective); updateRunActions(); diff --git a/src/plugins/debugger/analyzer/analyzermanager.h b/src/plugins/debugger/analyzer/analyzermanager.h index 2f69bcab2ae..3a4bd7bb36b 100644 --- a/src/plugins/debugger/analyzer/analyzermanager.h +++ b/src/plugins/debugger/analyzer/analyzermanager.h @@ -62,11 +62,9 @@ DEBUGGER_EXPORT bool wantRunTool(ToolMode toolMode, const QString &toolName); 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 registerPerspective(const QByteArray &perspectiveId, 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(); diff --git a/src/plugins/debugger/debuggermainwindow.cpp b/src/plugins/debugger/debuggermainwindow.cpp index dadea407597..cd1acf417b9 100644 --- a/src/plugins/debugger/debuggermainwindow.cpp +++ b/src/plugins/debugger/debuggermainwindow.cpp @@ -41,6 +41,7 @@ #include +#include #include #include #include @@ -65,7 +66,6 @@ const char LAST_PERSPECTIVE_KEY[] = "LastPerspective"; DebuggerMainWindow::DebuggerMainWindow() { - m_controlsStackWidget = new QStackedWidget; m_centralWidgetStack = new QStackedWidget; m_statusLabel = new Utils::StatusLabel; m_editorPlaceHolder = new EditorManagerPlaceHolder; @@ -73,7 +73,9 @@ DebuggerMainWindow::DebuggerMainWindow() m_perspectiveChooser = new QComboBox; m_perspectiveChooser->setObjectName(QLatin1String("PerspectiveChooser")); connect(m_perspectiveChooser, static_cast(&QComboBox::activated), - this, [this](int item) { restorePerspective(m_perspectiveChooser->itemData(item).toByteArray()); }); + this, [this](int item) { + restorePerspective(findPerspective(m_perspectiveChooser->itemData(item).toByteArray())); + }); setDockNestingEnabled(true); setDockActionsVisible(false); @@ -85,7 +87,7 @@ DebuggerMainWindow::DebuggerMainWindow() DebuggerMainWindow::~DebuggerMainWindow() { - savePerspectiveHelper(m_currentPerspectiveId); + savePerspectiveHelper(m_currentPerspective); delete m_editorPlaceHolder; m_editorPlaceHolder = nullptr; @@ -96,17 +98,18 @@ DebuggerMainWindow::~DebuggerMainWindow() delete dock; } - foreach (const Perspective *perspective, m_perspectiveForPerspectiveId) + foreach (const Perspective *perspective, m_perspectives) delete perspective; } -void DebuggerMainWindow::registerPerspective(const QByteArray &perspectiveId, const Perspective *perspective) +void DebuggerMainWindow::registerPerspective(const QByteArray &perspectiveId, Perspective *perspective) { - m_perspectiveForPerspectiveId.insert(perspectiveId, perspective); + m_perspectives.append(perspective); + perspective->m_id = perspectiveId; QByteArray parentPerspective = perspective->parentPerspective(); // Add "main" perspectives to the chooser. if (parentPerspective.isEmpty()) { - m_perspectiveChooser->addItem(perspective->name(), perspectiveId); + m_perspectiveChooser->addItem(perspective->name(), perspective->m_id); increaseChooserWidthIfNecessary(perspective->name()); } } @@ -124,33 +127,22 @@ void DebuggerMainWindow::increaseChooserWidthIfNecessary(const QString &visibleN m_perspectiveChooser->setFixedWidth(width); } -void DebuggerMainWindow::destroyDynamicPerspective(const QByteArray &perspectiveId) +void DebuggerMainWindow::destroyDynamicPerspective(Perspective *perspective) { - savePerspectiveHelper(perspectiveId); - - const Perspective *perspective = m_perspectiveForPerspectiveId.take(perspectiveId); QTC_ASSERT(perspective, return); + savePerspectiveHelper(perspective); + + m_perspectives.removeAll(perspective); // 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); + const int idx = indexInChooser(perspective); 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); + restorePerspective(findPerspective(parentPerspective)); } void DebuggerMainWindow::showStatusMessage(const QString &message, int timeoutMS) @@ -168,11 +160,16 @@ void DebuggerMainWindow::raiseDock(const QByteArray &dockId) dock->raise(); } +QByteArray DebuggerMainWindow::currentPerspective() const +{ + return m_currentPerspective ? m_currentPerspective->m_id : QByteArray(); +} + void DebuggerMainWindow::onModeChanged(Core::Id mode) { if (mode == Debugger::Constants::MODE_DEBUG) { setDockActionsVisible(true); - restorePerspective({}); + restorePerspective(nullptr); } else { setDockActionsVisible(false); @@ -186,7 +183,8 @@ void DebuggerMainWindow::onModeChanged(Core::Id mode) void DebuggerMainWindow::setPerspectiveEnabled(const QByteArray &perspectiveId, bool enabled) { - const int index = m_perspectiveChooser->findData(perspectiveId); + Perspective *perspective = findPerspective(perspectiveId); + const int index = indexInChooser(perspective); QTC_ASSERT(index != -1, return); auto model = qobject_cast(m_perspectiveChooser->model()); QTC_ASSERT(model, return); @@ -194,18 +192,28 @@ void DebuggerMainWindow::setPerspectiveEnabled(const QByteArray &perspectiveId, item->setFlags(enabled ? item->flags() | Qt::ItemIsEnabled : item->flags() & ~Qt::ItemIsEnabled ); } -void DebuggerMainWindow::resetCurrentPerspective() +Perspective *DebuggerMainWindow::findPerspective(const QByteArray &perspectiveId) const { - loadPerspectiveHelper(m_currentPerspectiveId, false); + return Utils::findOr(m_perspectives, nullptr, [&](Perspective *perspective) { + return perspective->m_id == perspectiveId; + }); } -void DebuggerMainWindow::restorePerspective(const QByteArray &perspectiveId) +void DebuggerMainWindow::resetCurrentPerspective() { - loadPerspectiveHelper(perspectiveId, true); + loadPerspectiveHelper(m_currentPerspective, false); +} - int index = m_perspectiveChooser->findData(perspectiveId); - if (index == -1) - index = m_perspectiveChooser->findData(m_currentPerspectiveId); +int DebuggerMainWindow::indexInChooser(Perspective *perspective) const +{ + return perspective ? m_perspectiveChooser->findData(perspective->m_id) : -1; +} + +void DebuggerMainWindow::restorePerspective(Perspective *perspective) +{ + loadPerspectiveHelper(perspective, true); + + const int index = indexInChooser(m_currentPerspective); if (index != -1) m_perspectiveChooser->setCurrentIndex(index); } @@ -219,13 +227,19 @@ void DebuggerMainWindow::finalizeSetup() closeButton->setIcon(Utils::Icons::CLOSE_SPLIT_BOTTOM.icon()); closeButton->setToolTip(tr("Leave Debug Mode")); + auto toolbuttonBox = new QWidget; + m_toolbuttonBoxLayout = new QHBoxLayout(toolbuttonBox); + m_toolbuttonBoxLayout->setMargin(0); + m_toolbuttonBoxLayout->setSpacing(0); + auto toolbar = new Utils::StyledBar; toolbar->setProperty("topBorder", true); auto hbox = new QHBoxLayout(toolbar); hbox->setMargin(0); hbox->setSpacing(0); hbox->addWidget(m_perspectiveChooser); - hbox->addWidget(m_controlsStackWidget); + hbox->addWidget(toolbuttonBox); + hbox->addStretch(3); hbox->addWidget(m_statusLabel); hbox->addStretch(1); hbox->addWidget(new Utils::StyledSeparator); @@ -329,15 +343,13 @@ QWidget *createModeWindow(const Core::Id &mode, DebuggerMainWindow *mainWindow) return splitter; } -void DebuggerMainWindow::loadPerspectiveHelper(const QByteArray &perspectiveId, bool fromStoredSettings) +void DebuggerMainWindow::loadPerspectiveHelper(Perspective *perspective, bool fromStoredSettings) { // Clean up old perspective. - if (!m_currentPerspectiveId.isEmpty()) { - savePerspectiveHelper(m_currentPerspectiveId); + if (m_currentPerspective) { + savePerspectiveHelper(m_currentPerspective); for (QDockWidget *dock : m_dockForDockId) { QTC_ASSERT(dock, continue); - dock->setFloating(false); - removeDockWidget(dock); dock->setParent(nullptr); dock->widget()->setParent(nullptr); ActionManager::unregisterAction(dock->toggleViewAction(), @@ -346,31 +358,50 @@ void DebuggerMainWindow::loadPerspectiveHelper(const QByteArray &perspectiveId, } m_dockForDockId.clear(); - ICore::removeAdditionalContext(Context(Id::fromName(m_currentPerspectiveId))); - const Perspective *perspective = m_perspectiveForPerspectiveId.value(m_currentPerspectiveId); - QWidget *central = perspective ? perspective->centralWidget() : nullptr; + ICore::removeAdditionalContext(Context(Id::fromName(m_currentPerspective->m_id))); + QWidget *central = m_currentPerspective->centralWidget(); m_centralWidgetStack->removeWidget(central ? central : m_editorPlaceHolder); + + // Detach potentially re-used widgets to prevent deletion. + for (const Perspective::ToolbarOperation &op : m_currentPerspective->m_toolbarOperations) { + if (op.widget) + op.widget->setParent(nullptr); + if (op.toolbutton) + op.toolbutton->setParent(nullptr); + if (op.separator) + op.separator->setParent(nullptr); + } + + while (QLayoutItem *item = m_toolbuttonBoxLayout->takeAt(0)) + delete item; } - m_currentPerspectiveId = perspectiveId; - - if (m_currentPerspectiveId.isEmpty()) { + if (perspective) { + m_currentPerspective = perspective; + } else { const QSettings *settings = ICore::settings(); - m_currentPerspectiveId = settings->value(QLatin1String(LAST_PERSPECTIVE_KEY)).toByteArray(); - if (m_currentPerspectiveId.isEmpty()) - m_currentPerspectiveId = Debugger::Constants::CppPerspectiveId; + m_currentPerspective = findPerspective(settings->value(QLatin1String(LAST_PERSPECTIVE_KEY)).toByteArray()); + if (!m_currentPerspective) + m_currentPerspective = findPerspective(Debugger::Constants::CppPerspectiveId); + if (!m_currentPerspective && !m_perspectives.isEmpty()) + m_currentPerspective = m_perspectives.first(); + } + QTC_ASSERT(m_currentPerspective, return); + + ICore::addAdditionalContext(Context(Id::fromName(m_currentPerspective->m_id))); + + m_currentPerspective->aboutToActivate(); + + for (const Perspective::ToolbarOperation &op : m_currentPerspective->m_toolbarOperations) { + if (op.widget) + m_toolbuttonBoxLayout->addWidget(op.widget); + if (op.toolbutton) + m_toolbuttonBoxLayout->addWidget(op.toolbutton); + if (op.separator) + m_toolbuttonBoxLayout->addWidget(op.separator); } - ICore::addAdditionalContext(Context(Id::fromName(m_currentPerspectiveId))); - - const Perspective *perspective = m_perspectiveForPerspectiveId.value(m_currentPerspectiveId); - if (!perspective) { - QTC_ASSERT(!m_perspectiveForPerspectiveId.isEmpty(), return); - perspective = *m_perspectiveForPerspectiveId.begin(); - } - QTC_ASSERT(perspective, return); - perspective->aboutToActivate(); - for (const Perspective::Operation &op : perspective->m_operations) { + for (const Perspective::Operation &op : m_currentPerspective->m_operations) { QTC_ASSERT(op.widget, continue); const QByteArray dockId = op.widget->objectName().toUtf8(); QDockWidget *dock = m_dockForDockId.value(dockId); @@ -384,7 +415,7 @@ void DebuggerMainWindow::loadPerspectiveHelper(const QByteArray &perspectiveId, Command *cmd = ActionManager::registerAction(toggleViewAction, Id("Dock.").withSuffix(dock->objectName()), - Context(Id::fromName(m_currentPerspectiveId))); + Context(Id::fromName(m_currentPerspective->m_id))); cmd->setAttribute(Command::CA_Hide); ActionManager::actionContainer(Core::Constants::M_WINDOW_VIEWS)->addAction(cmd); @@ -422,7 +453,7 @@ void DebuggerMainWindow::loadPerspectiveHelper(const QByteArray &perspectiveId, if (fromStoredSettings) { QSettings *settings = ICore::settings(); - settings->beginGroup(QString::fromLatin1(m_currentPerspectiveId)); + settings->beginGroup(QString::fromLatin1(m_currentPerspective->m_id)); if (settings->value(QLatin1String("ToolSettingsSaved"), false).toBool()) restoreSettings(settings); settings->endGroup(); @@ -431,29 +462,32 @@ void DebuggerMainWindow::loadPerspectiveHelper(const QByteArray &perspectiveId, showCentralWidgetAction()->setChecked(true); } - QWidget *central = perspective->centralWidget(); + QWidget *central = m_currentPerspective->centralWidget(); m_centralWidgetStack->addWidget(central ? central : m_editorPlaceHolder); showCentralWidgetAction()->setText(central ? central->windowTitle() : tr("Editor")); - QTC_CHECK(m_toolbarForPerspectiveId.contains(m_currentPerspectiveId)); - m_controlsStackWidget->setCurrentWidget(m_toolbarForPerspectiveId.value(m_currentPerspectiveId)); m_statusLabel->clear(); } -void DebuggerMainWindow::savePerspectiveHelper(const QByteArray &perspectiveId) +void DebuggerMainWindow::savePerspectiveHelper(const Perspective *perspective) { - if (perspectiveId.isEmpty()) + if (!perspective) return; QSettings *settings = ICore::settings(); - settings->beginGroup(QString::fromLatin1(perspectiveId)); + settings->beginGroup(QString::fromLatin1(perspective->m_id)); saveSettings(settings); settings->setValue(QLatin1String("ToolSettingsSaved"), true); settings->endGroup(); - settings->setValue(QLatin1String(LAST_PERSPECTIVE_KEY), perspectiveId); + settings->setValue(QLatin1String(LAST_PERSPECTIVE_KEY), perspective->m_id); } Perspective::~Perspective() { + for (const ToolbarOperation &op : m_toolbarOperations) { + // op.widget and op.actions are owned by the plugins + delete op.toolbutton; + delete op.separator; + } } void Perspective::setCentralWidget(QWidget *centralWidget) @@ -493,23 +527,36 @@ void Perspective::setParentPerspective(const QByteArray &parentPerspective) m_parentPerspective = parentPerspective; } -QList ToolbarDescription::widgets() const +QToolButton *Perspective::addToolbarAction(QAction *action, const QIcon &toolbarIcon) { - return m_widgets; + ToolbarOperation op; + op.action = action; + op.icon = toolbarIcon; + op.toolbutton = new QToolButton; + op.toolbutton->setDefaultAction(toolbarIcon.isNull() + ? action : ProxyAction::proxyActionWithIcon(action, toolbarIcon)); + m_toolbarOperations.append(op); + + return op.toolbutton; } -QToolButton *ToolbarDescription::addAction(QAction *action, const QIcon &toolbarIcon) +void Perspective::addToolbarWidget(QWidget *widget) { - auto button = new QToolButton; - button->setDefaultAction(toolbarIcon.isNull() - ? action : ProxyAction::proxyActionWithIcon(action, toolbarIcon)); - m_widgets.append(button); - return button; + ToolbarOperation op; + op.widget = widget; + m_toolbarOperations.append(op); } -void ToolbarDescription::addWidget(QWidget *widget) +void Perspective::addToolbarSeparator() { - m_widgets.append(widget); + ToolbarOperation op; + op.separator = new StyledSeparator; + m_toolbarOperations.append(op); +} + +QWidget *Perspective::centralWidget() const +{ + return m_centralWidget; } Perspective::Perspective(const QString &name) diff --git a/src/plugins/debugger/debuggermainwindow.h b/src/plugins/debugger/debuggermainwindow.h index d4f45f9dc2d..2c2aa3d8c00 100644 --- a/src/plugins/debugger/debuggermainwindow.h +++ b/src/plugins/debugger/debuggermainwindow.h @@ -30,6 +30,7 @@ #include #include +#include #include #include @@ -61,7 +62,11 @@ public: bool visibleByDefault = true, Qt::DockWidgetArea area = Qt::BottomDockWidgetArea); - QWidget *centralWidget() const { return m_centralWidget; } + QToolButton *addToolbarAction(QAction *action, const QIcon &toolbarIcon = QIcon()); + void addToolbarWidget(QWidget *widget); + void addToolbarSeparator(); + + QWidget *centralWidget() const; QString name() const; void setName(const QString &name); @@ -78,7 +83,7 @@ private: void operator=(const Perspective &) = delete; friend class DebuggerMainWindow; - + class PerspectivePrivate *d = nullptr; class Operation { public: @@ -89,26 +94,23 @@ private: Qt::DockWidgetArea area = Qt::BottomDockWidgetArea; }; + class ToolbarOperation + { + public: + QPointer widget; // Owned by plugin if present + QPointer action; // Owned by plugin if present + QPointer toolbutton; // Owned here in case action is used + QPointer separator; + QIcon icon; + }; + + QByteArray m_id; QString m_name; QByteArray m_parentPerspective; QVector m_operations; QPointer m_centralWidget; Callback m_aboutToActivateCallback; -}; - -class DEBUGGER_EXPORT ToolbarDescription -{ -public: - ToolbarDescription() = default; - ToolbarDescription(const QList &widgets) : m_widgets(widgets) {} - - QList widgets() const; - - QToolButton *addAction(QAction *action, const QIcon &toolbarIcon = QIcon()); - void addWidget(QWidget *widget); - -private: - QList m_widgets; + QVector m_toolbarOperations; }; class DEBUGGER_EXPORT DebuggerMainWindow : public FancyMainWindow @@ -119,43 +121,43 @@ public: DebuggerMainWindow(); ~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 registerPerspective(const QByteArray &perspectiveId, Perspective *perspective); + void destroyDynamicPerspective(Perspective *perspective); void resetCurrentPerspective(); - void restorePerspective(const QByteArray &perspectiveId); + void restorePerspective(Perspective *perspective); void finalizeSetup(); void showStatusMessage(const QString &message, int timeoutMS); void raiseDock(const QByteArray &dockId); - QByteArray currentPerspective() const { return m_currentPerspectiveId; } + QByteArray currentPerspective() const; QStackedWidget *centralWidgetStack() const { return m_centralWidgetStack; } void onModeChanged(Core::Id mode); void setPerspectiveEnabled(const QByteArray &perspectiveId, bool enabled); + Perspective *findPerspective(const QByteArray &perspectiveId) const; + private: - void closeEvent(QCloseEvent *) final { savePerspectiveHelper(m_currentPerspectiveId); } + void closeEvent(QCloseEvent *) final { savePerspectiveHelper(m_currentPerspective); } - void loadPerspectiveHelper(const QByteArray &perspectiveId, bool fromStoredSettings = true); - void savePerspectiveHelper(const QByteArray &perspectiveId); + void loadPerspectiveHelper(Perspective *perspective, bool fromStoredSettings = true); + void savePerspectiveHelper(const Perspective *perspective); void increaseChooserWidthIfNecessary(const QString &visibleName); + int indexInChooser(Perspective *perspective) const; - QByteArray m_currentPerspectiveId; - QComboBox *m_perspectiveChooser; - QStackedWidget *m_controlsStackWidget; - QStackedWidget *m_centralWidgetStack; - QWidget *m_editorPlaceHolder; - Utils::StatusLabel *m_statusLabel; + Perspective *m_currentPerspective = nullptr; + QComboBox *m_perspectiveChooser = nullptr; + QHBoxLayout *m_toolbuttonBoxLayout = nullptr; + QStackedWidget *m_centralWidgetStack = nullptr; + QWidget *m_editorPlaceHolder = nullptr; + Utils::StatusLabel *m_statusLabel = nullptr; QDockWidget *m_toolbarDock = nullptr; QHash m_dockForDockId; - QHash m_toolbarForPerspectiveId; - QHash m_perspectiveForPerspectiveId; + QList m_perspectives; }; DEBUGGER_EXPORT QWidget *createModeWindow(const Core::Id &mode, DebuggerMainWindow *mainWindow); diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp index 8a2eb6032de..41bc2909707 100644 --- a/src/plugins/debugger/debuggerplugin.cpp +++ b/src/plugins/debugger/debuggerplugin.cpp @@ -1809,35 +1809,18 @@ bool DebuggerPluginPrivate::initialize(const QStringList &arguments, connect(action(SettingsDialog), &QAction::triggered, [] { ICore::showOptionsDialog(DEBUGGER_COMMON_SETTINGS_ID); }); - // Toolbar - ToolbarDescription toolbar; - toolbar.addAction(m_visibleStartAction); - toolbar.addAction(ActionManager::command(Constants::STOP)->action(), Icons::DEBUG_EXIT_SMALL_TOOLBAR.icon()); - toolbar.addAction(ActionManager::command(Constants::NEXT)->action(), Icons::STEP_OVER_TOOLBAR.icon()); - toolbar.addAction(ActionManager::command(Constants::STEP)->action(), Icons::STEP_INTO_TOOLBAR.icon()); - toolbar.addAction(ActionManager::command(Constants::STEPOUT)->action(), Icons::STEP_OUT_TOOLBAR.icon()); - toolbar.addAction(ActionManager::command(Constants::RESET)->action(), Icons::RESTART_TOOLBAR.icon()); - toolbar.addAction(ActionManager::command(Constants::OPERATE_BY_INSTRUCTION)->action()); - if (isReverseDebuggingEnabled()) { m_reverseToolButton = new QToolButton; m_reverseToolButton->setDefaultAction(m_reverseDirectionAction); - toolbar.addWidget(m_reverseToolButton); } - toolbar.addWidget(new StyledSeparator); - m_threadLabel = new QLabel(tr("Threads:")); - toolbar.addWidget(m_threadLabel); m_threadBox = new QComboBox; m_threadBox->setSizeAdjustPolicy(QComboBox::AdjustToContents); connect(m_threadBox, static_cast(&QComboBox::activated), this, &DebuggerPluginPrivate::selectThread); - toolbar.addWidget(m_threadBox); -// toolbar.addSpacerItem(new QSpacerItem(4, 0)); - // ToolbarDescription qmlToolbar // qmlToolbar.addAction(qmlUpdateOnSaveDummyAction); // qmlToolbar.addAction(qmlShowAppOnTopDummyAction, Icons::APP_ON_TOP_TOOLBAR.icon()); @@ -1846,7 +1829,7 @@ bool DebuggerPluginPrivate::initialize(const QStringList &arguments, // qmlToolbar.addWidget(new StyledSeparator); auto createBasePerspective = [this] { - auto perspective = new Perspective; + auto perspective = new Perspective("Debugger"); perspective->addWindow(m_stackWindow, Perspective::SplitVertical, nullptr); perspective->addWindow(m_breakWindow, Perspective::SplitHorizontal, m_stackWindow); perspective->addWindow(m_threadsWindow, Perspective::AddToTab, m_breakWindow, false); @@ -1859,6 +1842,23 @@ bool DebuggerPluginPrivate::initialize(const QStringList &arguments, Qt::RightDockWidgetArea); perspective->addWindow(m_logWindow, Perspective::AddToTab, nullptr, false, Qt::TopDockWidgetArea); perspective->addWindow(m_breakWindow, Perspective::Raise, nullptr); + + + perspective->addToolbarAction(m_visibleStartAction); + perspective->addToolbarAction(ActionManager::command(Constants::STOP)->action(), Icons::DEBUG_EXIT_SMALL_TOOLBAR.icon()); + perspective->addToolbarAction(ActionManager::command(Constants::NEXT)->action(), Icons::STEP_OVER_TOOLBAR.icon()); + perspective->addToolbarAction(ActionManager::command(Constants::STEP)->action(), Icons::STEP_INTO_TOOLBAR.icon()); + perspective->addToolbarAction(ActionManager::command(Constants::STEPOUT)->action(), Icons::STEP_OUT_TOOLBAR.icon()); + perspective->addToolbarAction(ActionManager::command(Constants::RESET)->action(), Icons::RESTART_TOOLBAR.icon()); + perspective->addToolbarAction(ActionManager::command(Constants::OPERATE_BY_INSTRUCTION)->action()); + + if (isReverseDebuggingEnabled()) + perspective->addToolbarWidget(m_reverseToolButton); + + perspective->addToolbarSeparator(); + perspective->addToolbarWidget(m_threadLabel); + perspective->addToolbarWidget(m_threadBox); + return perspective; }; @@ -1866,7 +1866,6 @@ bool DebuggerPluginPrivate::initialize(const QStringList &arguments, cppPerspective->setName(tr("Debugger")); cppPerspective->addWindow(m_registerWindow, Perspective::AddToTab, m_snapshotWindow, false); - Debugger::registerToolbar(CppPerspectiveId, toolbar); Debugger::registerPerspective(CppPerspectiveId, cppPerspective); // Perspective *qmlPerspective = createBasePerspective(); @@ -3495,26 +3494,6 @@ bool wantRunTool(ToolMode toolMode, const QString &toolName) return true; } -void registerToolbar(const QByteArray &perspectiveId, const ToolbarDescription &desc) -{ - auto toolbar = new QWidget; - toolbar->setObjectName(QString::fromLatin1(perspectiveId + ".Toolbar")); - auto hbox = new QHBoxLayout(toolbar); - hbox->setMargin(0); - hbox->setSpacing(0); - for (QWidget *widget : desc.widgets()) - hbox->addWidget(widget); - hbox->addStretch(); - toolbar->setLayout(hbox); - - 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()); @@ -3531,16 +3510,11 @@ QAction *createStopAction() return action; } -void registerPerspective(const QByteArray &perspectiveId, const Perspective *perspective) +void registerPerspective(const QByteArray &perspectiveId, Perspective *perspective) { 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); @@ -3557,7 +3531,7 @@ void selectPerspective(const QByteArray &perspectiveId) if (perspectiveId.isEmpty()) return; ModeManager::activateMode(MODE_DEBUG); - dd->m_mainWindow->restorePerspective(perspectiveId); + dd->m_mainWindow->restorePerspective(dd->m_mainWindow->findPerspective(perspectiveId)); } QByteArray currentPerspective() diff --git a/src/plugins/qmlprofiler/qmlprofilertool.cpp b/src/plugins/qmlprofiler/qmlprofilertool.cpp index e78858f2bd2..8003788d905 100644 --- a/src/plugins/qmlprofiler/qmlprofilertool.cpp +++ b/src/plugins/qmlprofiler/qmlprofilertool.cpp @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -228,15 +229,14 @@ QmlProfilerTool::QmlProfilerTool() QObject::connect(d->m_startAction, &QAction::triggered, this, &QmlProfilerTool::profileStartupProject); - Utils::ToolbarDescription toolbar; - toolbar.addAction(d->m_startAction); - toolbar.addAction(d->m_stopAction); - toolbar.addWidget(d->m_recordButton); - toolbar.addWidget(d->m_clearButton); - toolbar.addWidget(d->m_searchButton); - toolbar.addWidget(d->m_displayFeaturesButton); - toolbar.addWidget(d->m_timeLabel); - Debugger::registerToolbar(Constants::QmlProfilerPerspectiveId, toolbar); + Utils::Perspective *perspective = d->m_viewContainer->perspective(); + perspective->addToolbarAction(d->m_startAction); + perspective->addToolbarAction(d->m_stopAction); + perspective->addToolbarWidget(d->m_recordButton); + perspective->addToolbarWidget(d->m_clearButton); + perspective->addToolbarWidget(d->m_searchButton); + perspective->addToolbarWidget(d->m_displayFeaturesButton); + perspective->addToolbarWidget(d->m_timeLabel); connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::updateRunActions, this, &QmlProfilerTool::updateRunActions); diff --git a/src/plugins/qmlprofiler/qmlprofilerviewmanager.cpp b/src/plugins/qmlprofiler/qmlprofilerviewmanager.cpp index 69b38790462..0e1a8d80bdb 100644 --- a/src/plugins/qmlprofiler/qmlprofilerviewmanager.cpp +++ b/src/plugins/qmlprofiler/qmlprofilerviewmanager.cpp @@ -61,8 +61,8 @@ QmlProfilerViewManager::QmlProfilerViewManager(QObject *parent, new QmlProfilerStateWidget(m_profilerState, m_profilerModelManager, m_traceView); - auto perspective = new Utils::Perspective; - perspective->setName(tr("QML Profiler")); + m_perspective = new Utils::Perspective; + m_perspective->setName(tr("QML Profiler")); auto prepareEventsView = [this](QmlProfilerEventsView *view) { connect(view, &QmlProfilerEventsView::typeSelected, @@ -86,16 +86,16 @@ QmlProfilerViewManager::QmlProfilerViewManager(QObject *parent, QWidget *anchor = nullptr; if (m_traceView->isUsable()) { anchor = m_traceView; - perspective->addWindow(m_traceView, Perspective::SplitVertical, nullptr); - perspective->addWindow(m_flameGraphView, Perspective::AddToTab, anchor); + m_perspective->addWindow(m_traceView, Perspective::SplitVertical, nullptr); + m_perspective->addWindow(m_flameGraphView, Perspective::AddToTab, anchor); } else { anchor = m_flameGraphView; - perspective->addWindow(m_flameGraphView, Perspective::SplitVertical, nullptr); + m_perspective->addWindow(m_flameGraphView, Perspective::SplitVertical, nullptr); } - perspective->addWindow(m_statisticsView, Perspective::AddToTab, anchor); - perspective->addWindow(anchor, Perspective::Raise, nullptr); + m_perspective->addWindow(m_statisticsView, Perspective::AddToTab, anchor); + m_perspective->addWindow(anchor, Perspective::Raise, nullptr); - Debugger::registerPerspective(Constants::QmlProfilerPerspectiveId, perspective); + Debugger::registerPerspective(Constants::QmlProfilerPerspectiveId, m_perspective); } QmlProfilerViewManager::~QmlProfilerViewManager() diff --git a/src/plugins/qmlprofiler/qmlprofilerviewmanager.h b/src/plugins/qmlprofiler/qmlprofilerviewmanager.h index 3fba19d7b1c..e106afb4cce 100644 --- a/src/plugins/qmlprofiler/qmlprofilerviewmanager.h +++ b/src/plugins/qmlprofiler/qmlprofilerviewmanager.h @@ -31,6 +31,8 @@ #include +namespace Utils { class Perspective; } + namespace QmlProfiler { namespace Internal { @@ -49,6 +51,7 @@ public: QmlProfilerTraceView *traceView() const { return m_traceView; } QmlProfilerStatisticsView *statisticsView() const { return m_statisticsView; } FlameGraphView *flameGraphView() const { return m_flameGraphView; } + Utils::Perspective *perspective() const { return m_perspective; } void clear(); @@ -62,6 +65,7 @@ private: FlameGraphView *m_flameGraphView = nullptr; QmlProfilerStateManager *m_profilerState = nullptr; QmlProfilerModelManager *m_profilerModelManager = nullptr; + Utils::Perspective *m_perspective = nullptr; }; diff --git a/src/plugins/valgrind/callgrindtool.cpp b/src/plugins/valgrind/callgrindtool.cpp index 71e251d7873..57132f83d4d 100644 --- a/src/plugins/valgrind/callgrindtool.cpp +++ b/src/plugins/valgrind/callgrindtool.cpp @@ -419,18 +419,18 @@ CallgrindTool::CallgrindTool() this, &CallgrindTool::setCostEvent); updateEventCombo(); - ToolbarDescription toolbar; - toolbar.addAction(m_startAction); - toolbar.addAction(m_stopAction); - toolbar.addAction(m_loadExternalLogFile); - toolbar.addAction(m_dumpAction); - toolbar.addAction(m_resetAction); - toolbar.addAction(m_pauseAction); - toolbar.addAction(m_discardAction); - toolbar.addAction(m_goBack); - toolbar.addAction(m_goNext); - toolbar.addWidget(new Utils::StyledSeparator); - toolbar.addWidget(m_eventCombo); + auto perspective = new Perspective(tr("Callgrind")); + perspective->addToolbarAction(m_startAction); + perspective->addToolbarAction(m_stopAction); + perspective->addToolbarAction(m_loadExternalLogFile); + perspective->addToolbarAction(m_dumpAction); + perspective->addToolbarAction(m_resetAction); + perspective->addToolbarAction(m_pauseAction); + perspective->addToolbarAction(m_discardAction); + perspective->addToolbarAction(m_goBack); + perspective->addToolbarAction(m_goNext); + perspective->addToolbarSeparator(); + perspective->addToolbarWidget(m_eventCombo); // Cost formatting { @@ -463,7 +463,7 @@ CallgrindTool::CallgrindTool() button->setPopupMode(QToolButton::InstantPopup); button->setText(QLatin1String("$")); button->setToolTip(tr("Cost Format")); - toolbar.addWidget(button); + perspective->addToolbarWidget(button); } ValgrindGlobalSettings *settings = ValgrindPlugin::globalSettings(); @@ -500,13 +500,11 @@ CallgrindTool::CallgrindTool() setCostFormat(settings->costFormat()); enableCycleDetection(settings->detectCycles()); - toolbar.addAction(m_cycleDetection); - toolbar.addAction(m_shortenTemplates); - toolbar.addAction(m_filterProjectCosts); - toolbar.addWidget(m_searchFilter); - Debugger::registerToolbar(CallgrindPerspectiveId, toolbar); + perspective->addToolbarAction(m_cycleDetection); + perspective->addToolbarAction(m_shortenTemplates); + perspective->addToolbarAction(m_filterProjectCosts); + perspective->addToolbarWidget(m_searchFilter); - auto perspective = new Perspective(tr("Callgrind")); perspective->addWindow(m_flatView, Perspective::SplitVertical, nullptr); perspective->addWindow(m_calleesView, Perspective::SplitVertical, nullptr); perspective->addWindow(m_callersView, Perspective::SplitHorizontal, m_calleesView); diff --git a/src/plugins/valgrind/memchecktool.cpp b/src/plugins/valgrind/memchecktool.cpp index bf91eeb2b44..a42dbd9d60e 100644 --- a/src/plugins/valgrind/memchecktool.cpp +++ b/src/plugins/valgrind/memchecktool.cpp @@ -558,7 +558,6 @@ MemcheckTool::MemcheckTool() auto perspective = new Perspective(tr("Memcheck")); perspective->addWindow(m_errorView, Perspective::SplitVertical, nullptr); - Debugger::registerPerspective(MemcheckPerspectiveId, perspective); connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::updateRunActions, this, &MemcheckTool::maybeActiveRunConfigurationChanged); @@ -684,15 +683,14 @@ MemcheckTool::MemcheckTool() ProjectExplorerPlugin::startRunControl(rc); }); - ToolbarDescription toolbar; - toolbar.addAction(m_startAction); + perspective->addToolbarAction(m_startAction); //toolbar.addAction(m_startWithGdbAction); - toolbar.addAction(m_stopAction); - toolbar.addAction(m_loadExternalLogFile); - toolbar.addAction(m_goBack); - toolbar.addAction(m_goNext); - toolbar.addWidget(filterButton); - Debugger::registerToolbar(MemcheckPerspectiveId, toolbar); + perspective->addToolbarAction(m_stopAction); + perspective->addToolbarAction(m_loadExternalLogFile); + perspective->addToolbarAction(m_goBack); + perspective->addToolbarAction(m_goNext); + perspective->addToolbarWidget(filterButton); + Debugger::registerPerspective(MemcheckPerspectiveId, perspective); updateFromSettings(); maybeActiveRunConfigurationChanged();