From e6e38df436aab431d7682b22183790898e599350 Mon Sep 17 00:00:00 2001 From: hjk Date: Wed, 22 Aug 2018 10:53:34 +0200 Subject: [PATCH] Debugger: Shift some perspective related API to the perspective class Also, use QString uniformly for the (now rarely used) perspective ids. Change-Id: I682062e7d179d0fcfd309e7714713bd1218bd8bb Reviewed-by: Ulf Hermann --- .../debugger/analyzer/analyzermanager.h | 2 -- src/plugins/debugger/debuggermainwindow.cpp | 27 ++++++++----------- src/plugins/debugger/debuggermainwindow.h | 5 ++-- src/plugins/debugger/debuggerplugin.cpp | 6 ----- src/plugins/debugger/snapshothandler.cpp | 11 ++++---- src/plugins/qmlprofiler/qmlprofilertool.cpp | 8 +++--- src/plugins/valgrind/callgrindtool.cpp | 11 ++++---- src/plugins/valgrind/memchecktool.cpp | 19 ++++++------- 8 files changed, 37 insertions(+), 52 deletions(-) diff --git a/src/plugins/debugger/analyzer/analyzermanager.h b/src/plugins/debugger/analyzer/analyzermanager.h index d71cc4f9306..e7c7f4d9d58 100644 --- a/src/plugins/debugger/analyzer/analyzermanager.h +++ b/src/plugins/debugger/analyzer/analyzermanager.h @@ -62,8 +62,6 @@ DEBUGGER_EXPORT void showCannotStartDialog(const QString &toolName); DEBUGGER_EXPORT void enableMainWindow(bool on); -DEBUGGER_EXPORT void selectPerspective(const QByteArray &perspectiveId); - // Convenience functions. DEBUGGER_EXPORT void showStatusMessage(const QString &message, int timeoutMS = 10000); DEBUGGER_EXPORT void showPermanentStatusMessage(const QString &message); diff --git a/src/plugins/debugger/debuggermainwindow.cpp b/src/plugins/debugger/debuggermainwindow.cpp index 92b28cd4481..9a94aa22e11 100644 --- a/src/plugins/debugger/debuggermainwindow.cpp +++ b/src/plugins/debugger/debuggermainwindow.cpp @@ -146,7 +146,7 @@ public: QString m_id; QString m_name; - QByteArray m_parentPerspective; + QString m_parentPerspective; QVector m_dockOperations; QVector m_toolBarOperations; QPointer m_centralWidget; @@ -168,7 +168,6 @@ public: void registerPerspective(Perspective *perspective); void increaseChooserWidthIfNecessary(const QString &visibleName); void resetCurrentPerspective(); - Perspective *findPerspective(const QByteArray &perspectiveId) const; int indexInChooser(Perspective *perspective) const; DebuggerMainWindow *q = nullptr; @@ -197,7 +196,7 @@ DebuggerMainWindowPrivate::DebuggerMainWindowPrivate(DebuggerMainWindow *parent) m_perspectiveChooser->setProperty("panelwidget", true); connect(m_perspectiveChooser, static_cast(&QComboBox::activated), this, [this](int item) { - restorePerspective(q->findPerspective(m_perspectiveChooser->itemData(item).toByteArray())); + restorePerspective(Perspective::findPerspective(m_perspectiveChooser->itemData(item).toString())); }); } @@ -258,7 +257,7 @@ void DebuggerMainWindow::doShutdown() void DebuggerMainWindowPrivate::registerPerspective(Perspective *perspective) { m_perspectives.append(perspective); - QByteArray parentPerspective = perspective->d->m_parentPerspective; + QString parentPerspective = perspective->d->m_parentPerspective; // Add "main" perspectives to the chooser. if (parentPerspective.isEmpty()) { m_perspectiveChooser->addItem(perspective->name(), perspective->id()); @@ -293,7 +292,7 @@ void DebuggerMainWindowPrivate::destroyPerspective(Perspective *perspective) if (perspective == m_currentPerspective) { m_currentPerspective = nullptr; if (!perspective->d->m_parentPerspective.isEmpty()) { - if (Perspective *parent = findPerspective(perspective->d->m_parentPerspective)) + if (Perspective *parent = Perspective::findPerspective(perspective->d->m_parentPerspective)) parent->select(); } } @@ -321,11 +320,6 @@ void DebuggerMainWindow::onModeChanged(Core::Id mode) } } -Perspective *DebuggerMainWindow::findPerspective(const QByteArray &perspectiveId) -{ - return theMainWindow ? theMainWindow->d->findPerspective(perspectiveId) : nullptr; -} - QWidget *DebuggerMainWindow::centralWidgetStack() { return theMainWindow ? theMainWindow->d->m_centralWidgetStack : nullptr; @@ -336,10 +330,10 @@ DebuggerMainWindow *DebuggerMainWindow::instance() return theMainWindow; } -Perspective *DebuggerMainWindowPrivate::findPerspective(const QByteArray &perspectiveId) const +Perspective *Perspective::findPerspective(const QString &perspectiveId) { - return Utils::findOr(m_perspectives, nullptr, [&](Perspective *perspective) { - return perspective->d->m_id.toUtf8() == perspectiveId; + return Utils::findOr(theMainWindow->d->m_perspectives, nullptr, [&](Perspective *perspective) { + return perspective->d->m_id == perspectiveId; }); } @@ -491,7 +485,8 @@ void DebuggerMainWindowPrivate::loadPerspectiveHelper(Perspective *perspective, m_currentPerspective = perspective; } else { const QSettings *settings = ICore::settings(); - m_currentPerspective = findPerspective(settings->value(QLatin1String(LAST_PERSPECTIVE_KEY)).toByteArray()); + const QString lastPerspectiveId = settings->value(QLatin1String(LAST_PERSPECTIVE_KEY)).toString(); + m_currentPerspective = Perspective::findPerspective(lastPerspectiveId); // If we don't find a perspective with the stored name, pick any. // This can happen e.g. when a plugin was disabled that provided // the stored perspective, or when the save file was modified externally. @@ -632,9 +627,9 @@ void Perspective::aboutToActivate() const d->m_aboutToActivateCallback(); } -void Perspective::setParentPerspective(const QByteArray &parentPerspective) +void Perspective::setParentPerspective(const QString &parentPerspectiveId) { - d->m_parentPerspective = parentPerspective; + d->m_parentPerspective = parentPerspectiveId; } void Perspective::setEnabled(bool enabled) diff --git a/src/plugins/debugger/debuggermainwindow.h b/src/plugins/debugger/debuggermainwindow.h index b01caf10087..06b73ca3448 100644 --- a/src/plugins/debugger/debuggermainwindow.h +++ b/src/plugins/debugger/debuggermainwindow.h @@ -89,11 +89,13 @@ public: void setAboutToActivateCallback(const Callback &cb); void aboutToActivate() const; - void setParentPerspective(const QByteArray &parentPerspective); + void setParentPerspective(const QString &parentPerspectiveId); void setEnabled(bool enabled); void select(); + static Perspective *currentPerspective(); + static Perspective *findPerspective(const QString &perspectiveId); Core::Context context() const; @@ -122,7 +124,6 @@ public: static void showStatusMessage(const QString &message, int timeoutMS); static void onModeChanged(Core::Id mode); - static Perspective *findPerspective(const QByteArray &perspectiveId); static QWidget *centralWidgetStack(); private: diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp index 37ff2df9312..3c67eb8ada2 100644 --- a/src/plugins/debugger/debuggerplugin.cpp +++ b/src/plugins/debugger/debuggerplugin.cpp @@ -2548,12 +2548,6 @@ QAction *createStopAction() return action; } -void selectPerspective(const QByteArray &perspectiveId) -{ - if (auto perspective = DebuggerMainWindow::findPerspective(perspectiveId)) - perspective->select(); -} - void enableMainWindow(bool on) { DebuggerMainWindow::instance()->setEnabled(on); diff --git a/src/plugins/debugger/snapshothandler.cpp b/src/plugins/debugger/snapshothandler.cpp index 619a3f5fdde..4581305c703 100644 --- a/src/plugins/debugger/snapshothandler.cpp +++ b/src/plugins/debugger/snapshothandler.cpp @@ -332,12 +332,13 @@ void EngineManagerPrivate::selectUiForCurrentEngine() m_engineChooser->setCurrentIndex(row); - if (perspective) - perspective->select(); - else - selectPerspective(Debugger::Constants::PRESET_PERSPRECTIVE_ID); + if (!perspective) + perspective = Perspective::findPerspective(Debugger::Constants::PRESET_PERSPRECTIVE_ID); - m_engineModel.rootItem()->forFirstLevelChildren([this](EngineItem *engineItem) { + QTC_ASSERT(perspective, return); + perspective->select(); + + m_engineModel.rootItem()->forFirstLevelChildren([](EngineItem *engineItem) { if (engineItem && engineItem->m_engine) engineItem->m_engine->updateMarkers(); }); diff --git a/src/plugins/qmlprofiler/qmlprofilertool.cpp b/src/plugins/qmlprofiler/qmlprofilertool.cpp index a496012d103..d42416a4a98 100644 --- a/src/plugins/qmlprofiler/qmlprofilertool.cpp +++ b/src/plugins/qmlprofiler/qmlprofilertool.cpp @@ -547,7 +547,7 @@ ProjectExplorer::RunControl *QmlProfilerTool::attachToWaitingApplication() serverUrl.setHost(toolControl.host()); serverUrl.setPort(port); - Debugger::selectPerspective(Constants::QmlProfilerPerspectiveId); + d->m_viewContainer->perspective()->select(); auto runConfig = RunConfiguration::startupRunConfiguration(); auto runControl = new RunControl(runConfig, ProjectExplorer::Constants::QML_PROFILER_RUN_MODE); @@ -616,7 +616,7 @@ void QmlProfilerTool::showLoadDialog() if (!checkForUnsavedNotes()) return; - Debugger::selectPerspective(QmlProfilerPerspectiveId); + d->m_viewContainer->perspective()->select(); QLatin1String tFile(QtdFileExtension); QLatin1String zFile(QztFileExtension); @@ -640,8 +640,8 @@ void QmlProfilerTool::profileStartupProject() { if (!prepareTool()) return; - Debugger::selectPerspective(Constants::QmlProfilerPerspectiveId); - ProjectExplorerPlugin::runStartupProject(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE); + d->m_viewContainer->perspective()->select(); + ProjectExplorerPlugin::runStartupProject(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE); } QAction *QmlProfilerTool::startAction() const diff --git a/src/plugins/valgrind/callgrindtool.cpp b/src/plugins/valgrind/callgrindtool.cpp index 0d87510ec2b..a64e5d4f27b 100644 --- a/src/plugins/valgrind/callgrindtool.cpp +++ b/src/plugins/valgrind/callgrindtool.cpp @@ -102,7 +102,6 @@ using namespace Utils; namespace Valgrind { namespace Internal { -const char CallgrindPerspectiveId[] = "Callgrind.Perspective"; const char CallgrindLocalActionId[] = "Callgrind.Local.Action"; const char CallgrindRemoteActionId[] = "Callgrind.Remote.Action"; const char CALLGRIND_RUN_MODE[] = "CallgrindTool.CallgrindRunMode"; @@ -216,7 +215,7 @@ public: QString m_toggleCollectFunction; bool m_toolBusy = false; - Perspective m_perspective{CallgrindPerspectiveId, tr("Callgrind")}; + Perspective m_perspective{"Callgrind.Perspective", tr("Callgrind")}; }; CallgrindTool::CallgrindTool() @@ -252,10 +251,10 @@ CallgrindTool::CallgrindTool() action->setToolTip(toolTip); menu->addAction(ActionManager::registerAction(action, CallgrindLocalActionId), Debugger::Constants::G_ANALYZER_TOOLS); - QObject::connect(action, &QAction::triggered, this, [action] { + QObject::connect(action, &QAction::triggered, this, [this, action] { if (!Debugger::wantRunTool(OptimizedMode, action->text())) return; - Debugger::selectPerspective(CallgrindPerspectiveId); + m_perspective.select(); ProjectExplorerPlugin::runStartupProject(CALLGRIND_RUN_MODE); }); QObject::connect(m_startAction, &QAction::triggered, action, &QAction::triggered); @@ -268,7 +267,7 @@ CallgrindTool::CallgrindTool() action->setToolTip(toolTip); menu->addAction(ActionManager::registerAction(action, CallgrindRemoteActionId), Debugger::Constants::G_ANALYZER_REMOTE_TOOLS); - QObject::connect(action, &QAction::triggered, this, [action] { + QObject::connect(action, &QAction::triggered, this, [this, action] { auto runConfig = RunConfiguration::startupRunConfiguration(); if (!runConfig) { showCannotStartDialog(action->text()); @@ -277,7 +276,7 @@ CallgrindTool::CallgrindTool() StartRemoteDialog dlg; if (dlg.exec() != QDialog::Accepted) return; - Debugger::selectPerspective(CallgrindPerspectiveId); + m_perspective.select(); auto runControl = new RunControl(runConfig, CALLGRIND_RUN_MODE); if (auto creator = RunControl::producer(runConfig, CALLGRIND_RUN_MODE)) creator(runControl); diff --git a/src/plugins/valgrind/memchecktool.cpp b/src/plugins/valgrind/memchecktool.cpp index 19cb8ff72aa..e6586720222 100644 --- a/src/plugins/valgrind/memchecktool.cpp +++ b/src/plugins/valgrind/memchecktool.cpp @@ -117,9 +117,6 @@ namespace Internal { const char MEMCHECK_RUN_MODE[] = "MemcheckTool.MemcheckRunMode"; const char MEMCHECK_WITH_GDB_RUN_MODE[] = "MemcheckTool.MemcheckWithGdbRunMode"; -const char MemcheckPerspectiveId[] = "Memcheck.Perspective"; - - class MemcheckToolRunner : public ValgrindToolRunner { Q_OBJECT @@ -440,7 +437,7 @@ private: bool m_toolBusy = false; QString m_exitMsg; - Perspective m_perspective{MemcheckPerspectiveId, tr("Memcheck")}; + Perspective m_perspective{"Memcheck.Perspective", tr("Memcheck")}; }; #ifdef Q_OS_WIN @@ -617,11 +614,11 @@ MemcheckTool::MemcheckTool() action->setToolTip(toolTip); menu->addAction(ActionManager::registerAction(action, "Memcheck.Local"), Debugger::Constants::G_ANALYZER_TOOLS); - QObject::connect(action, &QAction::triggered, this, [action] { + QObject::connect(action, &QAction::triggered, this, [this, action] { if (!Debugger::wantRunTool(DebugMode, action->text())) return; TaskHub::clearTasks(Debugger::Constants::ANALYZERTASK_ID); - Debugger::selectPerspective(MemcheckPerspectiveId); + m_perspective.select(); ProjectExplorerPlugin::runStartupProject(MEMCHECK_RUN_MODE); }); QObject::connect(m_startAction, &QAction::triggered, action, &QAction::triggered); @@ -636,11 +633,11 @@ MemcheckTool::MemcheckTool() "the application is interrupted and can be debugged.")); menu->addAction(ActionManager::registerAction(action, "MemcheckWithGdb.Local"), Debugger::Constants::G_ANALYZER_TOOLS); - QObject::connect(action, &QAction::triggered, this, [action] { + QObject::connect(action, &QAction::triggered, this, [this, action] { if (!Debugger::wantRunTool(DebugMode, action->text())) return; TaskHub::clearTasks(Debugger::Constants::ANALYZERTASK_ID); - Debugger::selectPerspective(MemcheckPerspectiveId); + m_perspective.select(); ProjectExplorerPlugin::runStartupProject(MEMCHECK_WITH_GDB_RUN_MODE); }); QObject::connect(m_startWithGdbAction, &QAction::triggered, action, &QAction::triggered); @@ -663,7 +660,7 @@ MemcheckTool::MemcheckTool() action->setToolTip(toolTip); menu->addAction(ActionManager::registerAction(action, "Memcheck.Remote"), Debugger::Constants::G_ANALYZER_REMOTE_TOOLS); - QObject::connect(action, &QAction::triggered, this, [action] { + QObject::connect(action, &QAction::triggered, this, [this, action] { auto runConfig = RunConfiguration::startupRunConfiguration(); if (!runConfig) { showCannotStartDialog(action->text()); @@ -673,7 +670,7 @@ MemcheckTool::MemcheckTool() if (dlg.exec() != QDialog::Accepted) return; TaskHub::clearTasks(Debugger::Constants::ANALYZERTASK_ID); - Debugger::selectPerspective(MemcheckPerspectiveId); + m_perspective.select(); RunControl *rc = new RunControl(runConfig, MEMCHECK_RUN_MODE); if (auto creator = RunControl::producer(runConfig, MEMCHECK_RUN_MODE)) creator(rc); @@ -980,7 +977,7 @@ void MemcheckTool::loadShowXmlLogFile(const QString &filePath, const QString &ex clearErrorView(); m_settings->setFilterExternalIssues(false); m_filterProjectAction->setChecked(true); - Debugger::selectPerspective(MemcheckPerspectiveId); + m_perspective.select(); Core::ModeManager::activateMode(Debugger::Constants::MODE_DEBUG); m_exitMsg = exitMsg;