Analyzer: Reduce explicit use of StartMode enum

Change-Id: I27b1d06395dea940c8dd39cd2bd41fc09cee3a9c
Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
This commit is contained in:
hjk
2015-02-18 18:51:29 +01:00
parent 1eb36bb1d3
commit 813e995ebf
11 changed files with 78 additions and 62 deletions

View File

@@ -421,7 +421,7 @@ bool AnalyzerManagerPrivate::showPromptDialog(const QString &title, const QStrin
void AnalyzerManagerPrivate::startTool() void AnalyzerManagerPrivate::startTool()
{ {
QTC_ASSERT(m_currentAction, return); QTC_ASSERT(m_currentAction, return);
m_currentAction->toolStarter()(m_currentAction->startMode()); m_currentAction->toolStarter()();
} }
void AnalyzerManagerPrivate::modeChanged(IMode *mode) void AnalyzerManagerPrivate::modeChanged(IMode *mode)
@@ -687,8 +687,8 @@ AnalyzerRunControl *AnalyzerManager::createRunControl(
const AnalyzerStartParameters &sp, RunConfiguration *runConfiguration) const AnalyzerStartParameters &sp, RunConfiguration *runConfiguration)
{ {
foreach (AnalyzerAction *action, d->m_actions) { foreach (AnalyzerAction *action, d->m_actions) {
if (action->runMode() == sp.runMode && action->startMode() == sp.startMode) if (AnalyzerRunControl *rc = action->tryCreateRunControl(sp, runConfiguration))
return action->createRunControl(sp, runConfiguration); return rc;
} }
QTC_CHECK(false); QTC_CHECK(false);
return 0; return 0;

View File

@@ -64,12 +64,19 @@ AnalyzerAction::AnalyzerAction(QObject *parent)
bool AnalyzerAction::isRunnable() const bool AnalyzerAction::isRunnable() const
{ {
if (startMode() == StartRemote) if (m_startMode == StartRemote)
return true; return true;
return ProjectExplorerPlugin::canRun(SessionManager::startupProject(), runMode(), 0); return ProjectExplorerPlugin::canRun(SessionManager::startupProject(), runMode(), 0);
} }
AnalyzerRunControl *AnalyzerAction::tryCreateRunControl(const AnalyzerStartParameters &sp, RunConfiguration *runConfiguration) const
{
if (m_runMode == sp.runMode && m_startMode == sp.startMode)
return m_runControlCreator(sp, runConfiguration);
return 0;
}
static bool buildTypeAccepted(ToolMode toolMode, BuildConfiguration::BuildType buildType) static bool buildTypeAccepted(ToolMode toolMode, BuildConfiguration::BuildType buildType)
{ {
if (toolMode == AnyMode) if (toolMode == AnyMode)

View File

@@ -79,7 +79,6 @@ public:
explicit AnalyzerAction(QObject *parent = 0); explicit AnalyzerAction(QObject *parent = 0);
public: public:
StartMode startMode() const { return m_startMode; }
void setStartMode(StartMode startMode) { m_startMode = startMode; } void setStartMode(StartMode startMode) { m_startMode = startMode; }
Core::Id menuGroup() const { return m_menuGroup; } Core::Id menuGroup() const { return m_menuGroup; }
@@ -107,12 +106,11 @@ public:
/// Called each time the tool is launched. /// Called each time the tool is launched.
typedef std::function<AnalyzerRunControl *(const AnalyzerStartParameters &sp, typedef std::function<AnalyzerRunControl *(const AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration)> RunControlCreator; ProjectExplorer::RunConfiguration *runConfiguration)> RunControlCreator;
AnalyzerRunControl *createRunControl(const AnalyzerStartParameters &sp, AnalyzerRunControl *tryCreateRunControl(const AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration) const ProjectExplorer::RunConfiguration *runConfiguration) const;
{ return m_runControlCreator(sp, runConfiguration); }
void setRunControlCreator(const RunControlCreator &creator) { m_runControlCreator = creator; } void setRunControlCreator(const RunControlCreator &creator) { m_runControlCreator = creator; }
typedef std::function<void(StartMode)> ToolStarter; typedef std::function<void()> ToolStarter;
ToolStarter toolStarter() const { return m_toolStarter; } ToolStarter toolStarter() const { return m_toolStarter; }
void setToolStarter(const ToolStarter &toolStarter) { m_toolStarter = toolStarter; } void setToolStarter(const ToolStarter &toolStarter) { m_toolStarter = toolStarter; }

View File

@@ -53,7 +53,6 @@ bool QmlProfilerPlugin::initialize(const QStringList &arguments, QString *errorS
Q_UNUSED(errorString) Q_UNUSED(errorString)
auto tool = new QmlProfilerTool(this); auto tool = new QmlProfilerTool(this);
auto toolStarter = [tool](StartMode mode) { return tool->startTool(mode); };
auto widgetCreator = [tool] { return tool->createWidgets(); }; auto widgetCreator = [tool] { return tool->createWidgets(); };
auto runControlCreator = [tool](const AnalyzerStartParameters &sp, auto runControlCreator = [tool](const AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration) { ProjectExplorer::RunConfiguration *runConfiguration) {
@@ -71,7 +70,7 @@ bool QmlProfilerPlugin::initialize(const QStringList &arguments, QString *errorS
action->setToolId(QmlProfilerToolId); action->setToolId(QmlProfilerToolId);
action->setWidgetCreator(widgetCreator); action->setWidgetCreator(widgetCreator);
action->setRunControlCreator(runControlCreator); action->setRunControlCreator(runControlCreator);
action->setToolStarter(toolStarter); action->setToolStarter([tool] { tool->startLocalTool(); });
action->setRunMode(ProjectExplorer::QmlProfilerRunMode); action->setRunMode(ProjectExplorer::QmlProfilerRunMode);
action->setText(tr("QML Profiler")); action->setText(tr("QML Profiler"));
action->setToolTip(description); action->setToolTip(description);
@@ -84,7 +83,7 @@ bool QmlProfilerPlugin::initialize(const QStringList &arguments, QString *errorS
action->setToolId(QmlProfilerToolId); action->setToolId(QmlProfilerToolId);
action->setWidgetCreator(widgetCreator); action->setWidgetCreator(widgetCreator);
action->setRunControlCreator(runControlCreator); action->setRunControlCreator(runControlCreator);
action->setToolStarter(toolStarter); action->setToolStarter([tool] { tool->startRemoteTool(); });
action->setRunMode(ProjectExplorer::QmlProfilerRunMode); action->setRunMode(ProjectExplorer::QmlProfilerRunMode);
action->setText(tr("QML Profiler (External)")); action->setText(tr("QML Profiler (External)"));
action->setToolTip(description); action->setToolTip(description);

View File

@@ -486,8 +486,32 @@ void QmlProfilerTool::clearDisplay()
updateTimeDisplay(); updateTimeDisplay();
} }
static void startRemoteTool(QmlProfilerTool *tool, StartMode mode) void QmlProfilerTool::startLocalTool()
{ {
if (d->m_recordButton->isChecked()) {
if (!checkForUnsavedNotes())
return;
clearData(); // clear right away to suppress second warning on server recording change
}
// Make sure mode is shown.
AnalyzerManager::showMode();
// ### not sure if we're supposed to check if the RunConFiguration isEnabled
Project *pro = SessionManager::startupProject();
ProjectExplorerPlugin::runProject(pro, QmlProfilerRunMode);
}
void QmlProfilerTool::startRemoteTool()
{
if (d->m_recordButton->isChecked()) {
if (!checkForUnsavedNotes())
return;
clearData(); // clear right away to suppress second warning on server recording change
}
AnalyzerManager::showMode();
Id kitId; Id kitId;
quint16 port; quint16 port;
Kit *kit = 0; Kit *kit = 0;
@@ -514,7 +538,7 @@ static void startRemoteTool(QmlProfilerTool *tool, StartMode mode)
} }
AnalyzerStartParameters sp; AnalyzerStartParameters sp;
sp.startMode = mode; sp.startMode = StartRemote;
IDevice::ConstPtr device = DeviceKitInformation::device(kit); IDevice::ConstPtr device = DeviceKitInformation::device(kit);
if (device) { if (device) {
@@ -524,32 +548,10 @@ static void startRemoteTool(QmlProfilerTool *tool, StartMode mode)
sp.sysroot = SysRootKitInformation::sysRoot(kit).toString(); sp.sysroot = SysRootKitInformation::sysRoot(kit).toString();
sp.analyzerPort = port; sp.analyzerPort = port;
AnalyzerRunControl *rc = tool->createRunControl(sp, 0); AnalyzerRunControl *rc = createRunControl(sp, 0);
ProjectExplorerPlugin::startRunControl(rc, QmlProfilerRunMode); ProjectExplorerPlugin::startRunControl(rc, QmlProfilerRunMode);
} }
void QmlProfilerTool::startTool(StartMode mode)
{
if (d->m_recordButton->isChecked()) {
if (!checkForUnsavedNotes())
return;
else
clearData(); // clear right away to suppress second warning on server recording change
}
// Make sure mode is shown.
AnalyzerManager::showMode();
if (mode == StartLocal) {
// ### not sure if we're supposed to check if the RunConFiguration isEnabled
Project *pro = SessionManager::startupProject();
ProjectExplorerPlugin::instance()->runProject(pro, QmlProfilerRunMode);
} else if (mode == StartRemote) {
Internal::startRemoteTool(this, mode);
}
}
void QmlProfilerTool::logState(const QString &msg) void QmlProfilerTool::logState(const QString &msg)
{ {
MessageManager::write(msg, MessageManager::Flash); MessageManager::write(msg, MessageManager::Flash);

View File

@@ -58,7 +58,8 @@ public:
ProjectExplorer::RunConfiguration *runConfiguration = 0); ProjectExplorer::RunConfiguration *runConfiguration = 0);
QWidget *createWidgets(); QWidget *createWidgets();
void startTool(Analyzer::StartMode mode); void startLocalTool();
void startRemoteTool();
QList <QAction *> profilerContextMenuActions() const; QList <QAction *> profilerContextMenuActions() const;

View File

@@ -557,16 +557,19 @@ AnalyzerRunControl *CallgrindToolPrivate::createRunControl(const AnalyzerStartPa
return rc; return rc;
} }
void CallgrindTool::startTool(StartMode mode) void CallgrindTool::startLocalTool()
{ {
if (mode == StartLocal && checkForLocalStart(ReleaseMode)) { if (checkForLocalStart(ReleaseMode)) {
Project *pro = SessionManager::startupProject(); Project *pro = SessionManager::startupProject();
ProjectExplorerPlugin::instance()->runProject(pro, CallgrindRunMode); ProjectExplorerPlugin::runProject(pro, CallgrindRunMode);
d->setBusyCursor(true); d->setBusyCursor(true);
} }
}
void CallgrindTool::startRemoteTool()
{
AnalyzerStartParameters sp; AnalyzerStartParameters sp;
if (mode == StartRemote && checkForRemoteStart(&sp)) { if (checkForRemoteStart(&sp)) {
AnalyzerRunControl *rc = createRunControl(sp, 0); AnalyzerRunControl *rc = createRunControl(sp, 0);
ProjectExplorerPlugin::startRunControl(rc, CallgrindRunMode); ProjectExplorerPlugin::startRunControl(rc, CallgrindRunMode);
d->setBusyCursor(true); d->setBusyCursor(true);

View File

@@ -54,7 +54,8 @@ public:
ProjectExplorer::RunConfiguration *runConfiguration = 0); ProjectExplorer::RunConfiguration *runConfiguration = 0);
QWidget *createWidgets(); QWidget *createWidgets();
void startTool(Analyzer::StartMode mode); void startLocalTool();
void startRemoteTool();
public slots: public slots:
void handleShowCostsOfFunction(); void handleShowCostsOfFunction();

View File

@@ -597,15 +597,18 @@ void MemcheckTool::setBusyCursor(bool busy)
m_errorView->setCursor(cursor); m_errorView->setCursor(cursor);
} }
void MemcheckTool::startTool(StartMode mode) void MemcheckTool::startLocalTool()
{ {
if (mode == StartLocal && checkForLocalStart(DebugMode)) { if (checkForLocalStart(DebugMode)) {
Project *pro = SessionManager::startupProject(); Project *pro = SessionManager::startupProject();
ProjectExplorerPlugin::instance()->runProject(pro, MemcheckRunMode); ProjectExplorerPlugin::runProject(pro, MemcheckRunMode);
} }
}
void MemcheckTool::startRemoteTool()
{
AnalyzerStartParameters sp; AnalyzerStartParameters sp;
if (mode == StartRemote && checkForRemoteStart(&sp)) { if (checkForRemoteStart(&sp)) {
AnalyzerRunControl *rc = createRunControl(sp, 0); AnalyzerRunControl *rc = createRunControl(sp, 0);
ProjectExplorerPlugin::startRunControl(rc, MemcheckRunMode); ProjectExplorerPlugin::startRunControl(rc, MemcheckRunMode);
} }
@@ -617,15 +620,18 @@ MemcheckWithGdbTool::MemcheckWithGdbTool(QObject *parent) :
setObjectName(QLatin1String("MemcheckWithGdbTool")); setObjectName(QLatin1String("MemcheckWithGdbTool"));
} }
void MemcheckWithGdbTool::startTool(Analyzer::StartMode mode) void MemcheckWithGdbTool::startLocalTool()
{ {
if (mode == StartLocal && checkForLocalStart(DebugMode)) { if (checkForLocalStart(DebugMode)) {
Project *pro = SessionManager::startupProject(); Project *pro = SessionManager::startupProject();
ProjectExplorerPlugin::instance()->runProject(pro, MemcheckWithGdbRunMode); ProjectExplorerPlugin::runProject(pro, MemcheckWithGdbRunMode);
} }
}
void MemcheckWithGdbTool::startRemoteTool()
{
AnalyzerStartParameters sp; AnalyzerStartParameters sp;
if (mode == StartRemote && checkForRemoteStart(&sp)) { if (checkForRemoteStart(&sp)) {
AnalyzerRunControl *rc = createRunControl(sp, 0); AnalyzerRunControl *rc = createRunControl(sp, 0);
ProjectExplorerPlugin::startRunControl(rc, MemcheckWithGdbRunMode); ProjectExplorerPlugin::startRunControl(rc, MemcheckWithGdbRunMode);
} }

View File

@@ -83,11 +83,12 @@ class MemcheckTool : public QObject
public: public:
MemcheckTool(QObject *parent); MemcheckTool(QObject *parent);
void startTool(Analyzer::StartMode mode); void startLocalTool();
void startRemoteTool();
QWidget *createWidgets(); QWidget *createWidgets();
Analyzer::AnalyzerRunControl *createRunControl(const Analyzer::AnalyzerStartParameters &sp, Analyzer::AnalyzerRunControl *createRunControl(const Analyzer::AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration = 0); ProjectExplorer::RunConfiguration *runConfiguration);
private slots: private slots:
void settingsDestroyed(QObject *settings); void settingsDestroyed(QObject *settings);
@@ -139,7 +140,8 @@ class MemcheckWithGdbTool : public MemcheckTool
public: public:
MemcheckWithGdbTool(QObject *parent); MemcheckWithGdbTool(QObject *parent);
void startTool(Analyzer::StartMode mode); void startLocalTool();
void startRemoteTool();
MemcheckRunControl *createMemcheckRunControl( MemcheckRunControl *createMemcheckRunControl(
const Analyzer::AnalyzerStartParameters &sp, const Analyzer::AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration) Q_DECL_OVERRIDE; ProjectExplorer::RunConfiguration *runConfiguration) Q_DECL_OVERRIDE;

View File

@@ -125,7 +125,6 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *)
"When a problem is detected, the application is interrupted and can be debugged"); "When a problem is detected, the application is interrupted and can be debugged");
MemcheckTool *mcTool = m_memcheckTool; MemcheckTool *mcTool = m_memcheckTool;
auto mcToolStarter = [mcTool](StartMode mode) { return mcTool->startTool(mode); };
auto mcWidgetCreator = [mcTool] { return mcTool->createWidgets(); }; auto mcWidgetCreator = [mcTool] { return mcTool->createWidgets(); };
auto mcRunControlCreator = [mcTool](const AnalyzerStartParameters &sp, auto mcRunControlCreator = [mcTool](const AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration) { ProjectExplorer::RunConfiguration *runConfiguration) {
@@ -133,7 +132,6 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *)
}; };
MemcheckWithGdbTool *mcgTool = m_memcheckWithGdbTool; MemcheckWithGdbTool *mcgTool = m_memcheckWithGdbTool;
auto mcgToolStarter = [mcgTool](StartMode mode) { return mcgTool->startTool(mode); };
auto mcgWidgetCreator = [mcgTool] { return mcgTool->createWidgets(); }; auto mcgWidgetCreator = [mcgTool] { return mcgTool->createWidgets(); };
auto mcgRunControlCreator = [mcgTool](const AnalyzerStartParameters &sp, auto mcgRunControlCreator = [mcgTool](const AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration) { ProjectExplorer::RunConfiguration *runConfiguration) {
@@ -141,7 +139,6 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *)
}; };
CallgrindTool *cgTool = m_callgrindTool; CallgrindTool *cgTool = m_callgrindTool;
auto cgToolStarter = [cgTool](StartMode mode) { return cgTool->startTool(mode); };
auto cgWidgetCreator = [cgTool] { return cgTool->createWidgets(); }; auto cgWidgetCreator = [cgTool] { return cgTool->createWidgets(); };
auto cgRunControlCreator = [cgTool](const AnalyzerStartParameters &sp, auto cgRunControlCreator = [cgTool](const AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration) { ProjectExplorer::RunConfiguration *runConfiguration) {
@@ -154,7 +151,7 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *)
action->setToolId("Memcheck"); action->setToolId("Memcheck");
action->setWidgetCreator(mcWidgetCreator); action->setWidgetCreator(mcWidgetCreator);
action->setRunControlCreator(mcRunControlCreator); action->setRunControlCreator(mcRunControlCreator);
action->setToolStarter(mcToolStarter); action->setToolStarter([mcTool] { mcTool->startLocalTool(); });
action->setRunMode(ProjectExplorer::MemcheckRunMode); action->setRunMode(ProjectExplorer::MemcheckRunMode);
action->setText(tr("Valgrind Memory Analyzer")); action->setText(tr("Valgrind Memory Analyzer"));
action->setToolTip(memcheckToolTip); action->setToolTip(memcheckToolTip);
@@ -168,7 +165,7 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *)
action->setToolId("MemcheckWithGdb"); action->setToolId("MemcheckWithGdb");
action->setWidgetCreator(mcgWidgetCreator); action->setWidgetCreator(mcgWidgetCreator);
action->setRunControlCreator(mcgRunControlCreator); action->setRunControlCreator(mcgRunControlCreator);
action->setToolStarter(mcgToolStarter); action->setToolStarter([mcgTool] { mcgTool->startLocalTool(); });
action->setRunMode(ProjectExplorer::MemcheckWithGdbRunMode); action->setRunMode(ProjectExplorer::MemcheckWithGdbRunMode);
action->setText(tr("Valgrind Memory Analyzer with GDB")); action->setText(tr("Valgrind Memory Analyzer with GDB"));
action->setToolTip(memcheckWithGdbToolTip); action->setToolTip(memcheckWithGdbToolTip);
@@ -182,7 +179,7 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *)
action->setToolId(CallgrindToolId); action->setToolId(CallgrindToolId);
action->setWidgetCreator(cgWidgetCreator); action->setWidgetCreator(cgWidgetCreator);
action->setRunControlCreator(cgRunControlCreator); action->setRunControlCreator(cgRunControlCreator);
action->setToolStarter(cgToolStarter); action->setToolStarter([cgTool] { cgTool->startLocalTool(); });
action->setRunMode(ProjectExplorer::CallgrindRunMode); action->setRunMode(ProjectExplorer::CallgrindRunMode);
action->setText(tr("Valgrind Function Profiler")); action->setText(tr("Valgrind Function Profiler"));
action->setToolTip(callgrindToolTip); action->setToolTip(callgrindToolTip);
@@ -197,7 +194,7 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *)
action->setToolId("Memcheck"); action->setToolId("Memcheck");
action->setWidgetCreator(mcWidgetCreator); action->setWidgetCreator(mcWidgetCreator);
action->setRunControlCreator(mcRunControlCreator); action->setRunControlCreator(mcRunControlCreator);
action->setToolStarter(mcToolStarter); action->setToolStarter([mcTool] { mcTool->startRemoteTool(); });
action->setRunMode(ProjectExplorer::MemcheckRunMode); action->setRunMode(ProjectExplorer::MemcheckRunMode);
action->setText(tr("Valgrind Memory Analyzer (External Remote Application)")); action->setText(tr("Valgrind Memory Analyzer (External Remote Application)"));
action->setToolTip(memcheckToolTip); action->setToolTip(memcheckToolTip);
@@ -210,7 +207,7 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *)
action->setToolId(CallgrindToolId); action->setToolId(CallgrindToolId);
action->setWidgetCreator(cgWidgetCreator); action->setWidgetCreator(cgWidgetCreator);
action->setRunControlCreator(cgRunControlCreator); action->setRunControlCreator(cgRunControlCreator);
action->setToolStarter(cgToolStarter); action->setToolStarter([cgTool] { cgTool->startRemoteTool(); });
action->setRunMode(ProjectExplorer::CallgrindRunMode); action->setRunMode(ProjectExplorer::CallgrindRunMode);
action->setText(tr("Valgrind Function Profiler (External Remote Application)")); action->setText(tr("Valgrind Function Profiler (External Remote Application)"));
action->setToolTip(callgrindToolTip); action->setToolTip(callgrindToolTip);