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 <ulf.hermann@qt.io>
This commit is contained in:
hjk
2018-08-22 10:53:34 +02:00
parent aca14a36e9
commit e6e38df436
8 changed files with 37 additions and 52 deletions

View File

@@ -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);

View File

@@ -146,7 +146,7 @@ public:
QString m_id;
QString m_name;
QByteArray m_parentPerspective;
QString m_parentPerspective;
QVector<DockOperation> m_dockOperations;
QVector<ToolbarOperation> m_toolBarOperations;
QPointer<QWidget> 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<void (QComboBox::*)(int)>(&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)

View File

@@ -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:

View File

@@ -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);

View File

@@ -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();
});

View File

@@ -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

View File

@@ -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);

View File

@@ -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;