forked from qt-creator/qt-creator
Analyzer: Reduce explicit use of StartMode enum
Change-Id: I27b1d06395dea940c8dd39cd2bd41fc09cee3a9c Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
This commit is contained in:
@@ -421,7 +421,7 @@ bool AnalyzerManagerPrivate::showPromptDialog(const QString &title, const QStrin
|
||||
void AnalyzerManagerPrivate::startTool()
|
||||
{
|
||||
QTC_ASSERT(m_currentAction, return);
|
||||
m_currentAction->toolStarter()(m_currentAction->startMode());
|
||||
m_currentAction->toolStarter()();
|
||||
}
|
||||
|
||||
void AnalyzerManagerPrivate::modeChanged(IMode *mode)
|
||||
@@ -687,8 +687,8 @@ AnalyzerRunControl *AnalyzerManager::createRunControl(
|
||||
const AnalyzerStartParameters &sp, RunConfiguration *runConfiguration)
|
||||
{
|
||||
foreach (AnalyzerAction *action, d->m_actions) {
|
||||
if (action->runMode() == sp.runMode && action->startMode() == sp.startMode)
|
||||
return action->createRunControl(sp, runConfiguration);
|
||||
if (AnalyzerRunControl *rc = action->tryCreateRunControl(sp, runConfiguration))
|
||||
return rc;
|
||||
}
|
||||
QTC_CHECK(false);
|
||||
return 0;
|
||||
|
@@ -64,12 +64,19 @@ AnalyzerAction::AnalyzerAction(QObject *parent)
|
||||
|
||||
bool AnalyzerAction::isRunnable() const
|
||||
{
|
||||
if (startMode() == StartRemote)
|
||||
if (m_startMode == StartRemote)
|
||||
return true;
|
||||
|
||||
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)
|
||||
{
|
||||
if (toolMode == AnyMode)
|
||||
|
@@ -79,7 +79,6 @@ public:
|
||||
explicit AnalyzerAction(QObject *parent = 0);
|
||||
|
||||
public:
|
||||
StartMode startMode() const { return m_startMode; }
|
||||
void setStartMode(StartMode startMode) { m_startMode = startMode; }
|
||||
|
||||
Core::Id menuGroup() const { return m_menuGroup; }
|
||||
@@ -107,12 +106,11 @@ public:
|
||||
/// Called each time the tool is launched.
|
||||
typedef std::function<AnalyzerRunControl *(const AnalyzerStartParameters &sp,
|
||||
ProjectExplorer::RunConfiguration *runConfiguration)> RunControlCreator;
|
||||
AnalyzerRunControl *createRunControl(const AnalyzerStartParameters &sp,
|
||||
ProjectExplorer::RunConfiguration *runConfiguration) const
|
||||
{ return m_runControlCreator(sp, runConfiguration); }
|
||||
AnalyzerRunControl *tryCreateRunControl(const AnalyzerStartParameters &sp,
|
||||
ProjectExplorer::RunConfiguration *runConfiguration) const;
|
||||
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; }
|
||||
void setToolStarter(const ToolStarter &toolStarter) { m_toolStarter = toolStarter; }
|
||||
|
||||
|
@@ -53,7 +53,6 @@ bool QmlProfilerPlugin::initialize(const QStringList &arguments, QString *errorS
|
||||
Q_UNUSED(errorString)
|
||||
|
||||
auto tool = new QmlProfilerTool(this);
|
||||
auto toolStarter = [tool](StartMode mode) { return tool->startTool(mode); };
|
||||
auto widgetCreator = [tool] { return tool->createWidgets(); };
|
||||
auto runControlCreator = [tool](const AnalyzerStartParameters &sp,
|
||||
ProjectExplorer::RunConfiguration *runConfiguration) {
|
||||
@@ -71,7 +70,7 @@ bool QmlProfilerPlugin::initialize(const QStringList &arguments, QString *errorS
|
||||
action->setToolId(QmlProfilerToolId);
|
||||
action->setWidgetCreator(widgetCreator);
|
||||
action->setRunControlCreator(runControlCreator);
|
||||
action->setToolStarter(toolStarter);
|
||||
action->setToolStarter([tool] { tool->startLocalTool(); });
|
||||
action->setRunMode(ProjectExplorer::QmlProfilerRunMode);
|
||||
action->setText(tr("QML Profiler"));
|
||||
action->setToolTip(description);
|
||||
@@ -84,7 +83,7 @@ bool QmlProfilerPlugin::initialize(const QStringList &arguments, QString *errorS
|
||||
action->setToolId(QmlProfilerToolId);
|
||||
action->setWidgetCreator(widgetCreator);
|
||||
action->setRunControlCreator(runControlCreator);
|
||||
action->setToolStarter(toolStarter);
|
||||
action->setToolStarter([tool] { tool->startRemoteTool(); });
|
||||
action->setRunMode(ProjectExplorer::QmlProfilerRunMode);
|
||||
action->setText(tr("QML Profiler (External)"));
|
||||
action->setToolTip(description);
|
||||
|
@@ -486,8 +486,32 @@ void QmlProfilerTool::clearDisplay()
|
||||
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;
|
||||
quint16 port;
|
||||
Kit *kit = 0;
|
||||
@@ -514,7 +538,7 @@ static void startRemoteTool(QmlProfilerTool *tool, StartMode mode)
|
||||
}
|
||||
|
||||
AnalyzerStartParameters sp;
|
||||
sp.startMode = mode;
|
||||
sp.startMode = StartRemote;
|
||||
|
||||
IDevice::ConstPtr device = DeviceKitInformation::device(kit);
|
||||
if (device) {
|
||||
@@ -524,32 +548,10 @@ static void startRemoteTool(QmlProfilerTool *tool, StartMode mode)
|
||||
sp.sysroot = SysRootKitInformation::sysRoot(kit).toString();
|
||||
sp.analyzerPort = port;
|
||||
|
||||
AnalyzerRunControl *rc = tool->createRunControl(sp, 0);
|
||||
|
||||
AnalyzerRunControl *rc = createRunControl(sp, 0);
|
||||
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)
|
||||
{
|
||||
MessageManager::write(msg, MessageManager::Flash);
|
||||
|
@@ -58,7 +58,8 @@ public:
|
||||
ProjectExplorer::RunConfiguration *runConfiguration = 0);
|
||||
|
||||
QWidget *createWidgets();
|
||||
void startTool(Analyzer::StartMode mode);
|
||||
void startLocalTool();
|
||||
void startRemoteTool();
|
||||
|
||||
QList <QAction *> profilerContextMenuActions() const;
|
||||
|
||||
|
@@ -557,16 +557,19 @@ AnalyzerRunControl *CallgrindToolPrivate::createRunControl(const AnalyzerStartPa
|
||||
return rc;
|
||||
}
|
||||
|
||||
void CallgrindTool::startTool(StartMode mode)
|
||||
void CallgrindTool::startLocalTool()
|
||||
{
|
||||
if (mode == StartLocal && checkForLocalStart(ReleaseMode)) {
|
||||
if (checkForLocalStart(ReleaseMode)) {
|
||||
Project *pro = SessionManager::startupProject();
|
||||
ProjectExplorerPlugin::instance()->runProject(pro, CallgrindRunMode);
|
||||
ProjectExplorerPlugin::runProject(pro, CallgrindRunMode);
|
||||
d->setBusyCursor(true);
|
||||
}
|
||||
}
|
||||
|
||||
void CallgrindTool::startRemoteTool()
|
||||
{
|
||||
AnalyzerStartParameters sp;
|
||||
if (mode == StartRemote && checkForRemoteStart(&sp)) {
|
||||
if (checkForRemoteStart(&sp)) {
|
||||
AnalyzerRunControl *rc = createRunControl(sp, 0);
|
||||
ProjectExplorerPlugin::startRunControl(rc, CallgrindRunMode);
|
||||
d->setBusyCursor(true);
|
||||
|
@@ -54,7 +54,8 @@ public:
|
||||
ProjectExplorer::RunConfiguration *runConfiguration = 0);
|
||||
QWidget *createWidgets();
|
||||
|
||||
void startTool(Analyzer::StartMode mode);
|
||||
void startLocalTool();
|
||||
void startRemoteTool();
|
||||
|
||||
public slots:
|
||||
void handleShowCostsOfFunction();
|
||||
|
@@ -597,15 +597,18 @@ void MemcheckTool::setBusyCursor(bool busy)
|
||||
m_errorView->setCursor(cursor);
|
||||
}
|
||||
|
||||
void MemcheckTool::startTool(StartMode mode)
|
||||
void MemcheckTool::startLocalTool()
|
||||
{
|
||||
if (mode == StartLocal && checkForLocalStart(DebugMode)) {
|
||||
if (checkForLocalStart(DebugMode)) {
|
||||
Project *pro = SessionManager::startupProject();
|
||||
ProjectExplorerPlugin::instance()->runProject(pro, MemcheckRunMode);
|
||||
ProjectExplorerPlugin::runProject(pro, MemcheckRunMode);
|
||||
}
|
||||
}
|
||||
|
||||
void MemcheckTool::startRemoteTool()
|
||||
{
|
||||
AnalyzerStartParameters sp;
|
||||
if (mode == StartRemote && checkForRemoteStart(&sp)) {
|
||||
if (checkForRemoteStart(&sp)) {
|
||||
AnalyzerRunControl *rc = createRunControl(sp, 0);
|
||||
ProjectExplorerPlugin::startRunControl(rc, MemcheckRunMode);
|
||||
}
|
||||
@@ -617,15 +620,18 @@ MemcheckWithGdbTool::MemcheckWithGdbTool(QObject *parent) :
|
||||
setObjectName(QLatin1String("MemcheckWithGdbTool"));
|
||||
}
|
||||
|
||||
void MemcheckWithGdbTool::startTool(Analyzer::StartMode mode)
|
||||
void MemcheckWithGdbTool::startLocalTool()
|
||||
{
|
||||
if (mode == StartLocal && checkForLocalStart(DebugMode)) {
|
||||
if (checkForLocalStart(DebugMode)) {
|
||||
Project *pro = SessionManager::startupProject();
|
||||
ProjectExplorerPlugin::instance()->runProject(pro, MemcheckWithGdbRunMode);
|
||||
ProjectExplorerPlugin::runProject(pro, MemcheckWithGdbRunMode);
|
||||
}
|
||||
}
|
||||
|
||||
void MemcheckWithGdbTool::startRemoteTool()
|
||||
{
|
||||
AnalyzerStartParameters sp;
|
||||
if (mode == StartRemote && checkForRemoteStart(&sp)) {
|
||||
if (checkForRemoteStart(&sp)) {
|
||||
AnalyzerRunControl *rc = createRunControl(sp, 0);
|
||||
ProjectExplorerPlugin::startRunControl(rc, MemcheckWithGdbRunMode);
|
||||
}
|
||||
|
@@ -83,11 +83,12 @@ class MemcheckTool : public QObject
|
||||
public:
|
||||
MemcheckTool(QObject *parent);
|
||||
|
||||
void startTool(Analyzer::StartMode mode);
|
||||
void startLocalTool();
|
||||
void startRemoteTool();
|
||||
QWidget *createWidgets();
|
||||
|
||||
Analyzer::AnalyzerRunControl *createRunControl(const Analyzer::AnalyzerStartParameters &sp,
|
||||
ProjectExplorer::RunConfiguration *runConfiguration = 0);
|
||||
ProjectExplorer::RunConfiguration *runConfiguration);
|
||||
|
||||
private slots:
|
||||
void settingsDestroyed(QObject *settings);
|
||||
@@ -139,7 +140,8 @@ class MemcheckWithGdbTool : public MemcheckTool
|
||||
public:
|
||||
MemcheckWithGdbTool(QObject *parent);
|
||||
|
||||
void startTool(Analyzer::StartMode mode);
|
||||
void startLocalTool();
|
||||
void startRemoteTool();
|
||||
MemcheckRunControl *createMemcheckRunControl(
|
||||
const Analyzer::AnalyzerStartParameters &sp,
|
||||
ProjectExplorer::RunConfiguration *runConfiguration) Q_DECL_OVERRIDE;
|
||||
|
@@ -125,7 +125,6 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *)
|
||||
"When a problem is detected, the application is interrupted and can be debugged");
|
||||
|
||||
MemcheckTool *mcTool = m_memcheckTool;
|
||||
auto mcToolStarter = [mcTool](StartMode mode) { return mcTool->startTool(mode); };
|
||||
auto mcWidgetCreator = [mcTool] { return mcTool->createWidgets(); };
|
||||
auto mcRunControlCreator = [mcTool](const AnalyzerStartParameters &sp,
|
||||
ProjectExplorer::RunConfiguration *runConfiguration) {
|
||||
@@ -133,7 +132,6 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *)
|
||||
};
|
||||
|
||||
MemcheckWithGdbTool *mcgTool = m_memcheckWithGdbTool;
|
||||
auto mcgToolStarter = [mcgTool](StartMode mode) { return mcgTool->startTool(mode); };
|
||||
auto mcgWidgetCreator = [mcgTool] { return mcgTool->createWidgets(); };
|
||||
auto mcgRunControlCreator = [mcgTool](const AnalyzerStartParameters &sp,
|
||||
ProjectExplorer::RunConfiguration *runConfiguration) {
|
||||
@@ -141,7 +139,6 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *)
|
||||
};
|
||||
|
||||
CallgrindTool *cgTool = m_callgrindTool;
|
||||
auto cgToolStarter = [cgTool](StartMode mode) { return cgTool->startTool(mode); };
|
||||
auto cgWidgetCreator = [cgTool] { return cgTool->createWidgets(); };
|
||||
auto cgRunControlCreator = [cgTool](const AnalyzerStartParameters &sp,
|
||||
ProjectExplorer::RunConfiguration *runConfiguration) {
|
||||
@@ -154,7 +151,7 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *)
|
||||
action->setToolId("Memcheck");
|
||||
action->setWidgetCreator(mcWidgetCreator);
|
||||
action->setRunControlCreator(mcRunControlCreator);
|
||||
action->setToolStarter(mcToolStarter);
|
||||
action->setToolStarter([mcTool] { mcTool->startLocalTool(); });
|
||||
action->setRunMode(ProjectExplorer::MemcheckRunMode);
|
||||
action->setText(tr("Valgrind Memory Analyzer"));
|
||||
action->setToolTip(memcheckToolTip);
|
||||
@@ -168,7 +165,7 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *)
|
||||
action->setToolId("MemcheckWithGdb");
|
||||
action->setWidgetCreator(mcgWidgetCreator);
|
||||
action->setRunControlCreator(mcgRunControlCreator);
|
||||
action->setToolStarter(mcgToolStarter);
|
||||
action->setToolStarter([mcgTool] { mcgTool->startLocalTool(); });
|
||||
action->setRunMode(ProjectExplorer::MemcheckWithGdbRunMode);
|
||||
action->setText(tr("Valgrind Memory Analyzer with GDB"));
|
||||
action->setToolTip(memcheckWithGdbToolTip);
|
||||
@@ -182,7 +179,7 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *)
|
||||
action->setToolId(CallgrindToolId);
|
||||
action->setWidgetCreator(cgWidgetCreator);
|
||||
action->setRunControlCreator(cgRunControlCreator);
|
||||
action->setToolStarter(cgToolStarter);
|
||||
action->setToolStarter([cgTool] { cgTool->startLocalTool(); });
|
||||
action->setRunMode(ProjectExplorer::CallgrindRunMode);
|
||||
action->setText(tr("Valgrind Function Profiler"));
|
||||
action->setToolTip(callgrindToolTip);
|
||||
@@ -197,7 +194,7 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *)
|
||||
action->setToolId("Memcheck");
|
||||
action->setWidgetCreator(mcWidgetCreator);
|
||||
action->setRunControlCreator(mcRunControlCreator);
|
||||
action->setToolStarter(mcToolStarter);
|
||||
action->setToolStarter([mcTool] { mcTool->startRemoteTool(); });
|
||||
action->setRunMode(ProjectExplorer::MemcheckRunMode);
|
||||
action->setText(tr("Valgrind Memory Analyzer (External Remote Application)"));
|
||||
action->setToolTip(memcheckToolTip);
|
||||
@@ -210,7 +207,7 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *)
|
||||
action->setToolId(CallgrindToolId);
|
||||
action->setWidgetCreator(cgWidgetCreator);
|
||||
action->setRunControlCreator(cgRunControlCreator);
|
||||
action->setToolStarter(cgToolStarter);
|
||||
action->setToolStarter([cgTool] { cgTool->startRemoteTool(); });
|
||||
action->setRunMode(ProjectExplorer::CallgrindRunMode);
|
||||
action->setText(tr("Valgrind Function Profiler (External Remote Application)"));
|
||||
action->setToolTip(callgrindToolTip);
|
||||
|
Reference in New Issue
Block a user