Debugger: Dissolve Debugger::ActionDescription

ActionDescription was a horizontal layer of convenience functionality
covering (only) ex-AnalyzerBase based RunControl start scenarios
and gets in the way of target/tool orthogonalization.

So continue the path chosen with the removal of AnalyzerRunControl:
Remove ActionDescription by inlining into user code, then orthogonalize
tool-by-tool, then generalize again.

Change-Id: Ib597df3f4ad7b06bef06644458fa13ddca53afdb
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
hjk
2017-04-12 10:06:41 +02:00
parent e821b98c11
commit e063ca68d0
10 changed files with 192 additions and 214 deletions

View File

@@ -31,10 +31,15 @@
#include "clangstaticanalyzerdiagnosticview.h" #include "clangstaticanalyzerdiagnosticview.h"
#include "clangstaticanalyzerruncontrol.h" #include "clangstaticanalyzerruncontrol.h"
#include <debugger/analyzer/analyzermanager.h> #include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/coreconstants.h> #include <coreplugin/coreconstants.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <cpptools/cppmodelmanager.h> #include <cpptools/cppmodelmanager.h>
#include <debugger/analyzer/analyzermanager.h>
#include <projectexplorer/buildconfiguration.h> #include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/projectexplorer.h> #include <projectexplorer/projectexplorer.h>
#include <projectexplorer/session.h> #include <projectexplorer/session.h>
@@ -52,6 +57,7 @@
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#include <QToolButton> #include <QToolButton>
using namespace Core;
using namespace Debugger; using namespace Debugger;
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace Utils; using namespace Utils;
@@ -134,6 +140,7 @@ ClangStaticAnalyzerTool::ClangStaticAnalyzerTool(QObject *parent)
connect(action, &QAction::triggered, m_diagnosticView, &DetailedErrorView::goNext); connect(action, &QAction::triggered, m_diagnosticView, &DetailedErrorView::goNext);
m_goNext = action; m_goNext = action;
ActionContainer *menu = ActionManager::actionContainer(Debugger::Constants::M_DEBUG_ANALYZER);
const QString toolTip = tr("Clang Static Analyzer uses the analyzer from the Clang project " const QString toolTip = tr("Clang Static Analyzer uses the analyzer from the Clang project "
"to find bugs."); "to find bugs.");
@@ -142,17 +149,16 @@ ClangStaticAnalyzerTool::ClangStaticAnalyzerTool(QObject *parent)
{{ClangStaticAnalyzerDockId, m_diagnosticView, {}, Perspective::SplitVertical}} {{ClangStaticAnalyzerDockId, m_diagnosticView, {}, Perspective::SplitVertical}}
)); ));
ActionDescription desc; Debugger::registerAction(Constants::CLANGSTATICANALYZER_RUN_MODE, {});
desc.setText(tr("Clang Static Analyzer")); action = new QAction(tr("Clang Static Analyzer"), this);
desc.setToolTip(toolTip); action->setToolTip(toolTip);
desc.setRunMode(Constants::CLANGSTATICANALYZER_RUN_MODE); menu->addAction(ActionManager::registerAction(action, "ClangStaticAnalyzer.Action"),
desc.setPerspectiveId(ClangStaticAnalyzerPerspectiveId); Debugger::Constants::G_ANALYZER_TOOLS);
desc.setCustomToolStarter([this](RunConfiguration *runConfiguration) { QObject::connect(action, &QAction::triggered, this, &ClangStaticAnalyzerTool::startTool);
Q_UNUSED(runConfiguration); QObject::connect(m_startAction, &QAction::triggered, action, &QAction::triggered);
startTool(); QObject::connect(m_startAction, &QAction::changed, action, [action, this] {
action->setEnabled(m_startAction->isEnabled());
}); });
desc.setMenuGroup(Debugger::Constants::G_ANALYZER_TOOLS);
Debugger::registerAction(ClangStaticAnalyzerActionId, desc, m_startAction);
ToolbarDescription toolbar; ToolbarDescription toolbar;
toolbar.addAction(m_startAction); toolbar.addAction(m_startAction);
@@ -240,6 +246,7 @@ void ClangStaticAnalyzerTool::startTool()
if (dontStartAfterHintForDebugMode(project)) if (dontStartAfterHintForDebugMode(project))
return; return;
Debugger::selectPerspective(ClangStaticAnalyzerPerspectiveId);
m_diagnosticModel->clear(); m_diagnosticModel->clear();
setBusyCursor(true); setBusyCursor(true);
m_diagnosticFilterModel->setProject(project); m_diagnosticFilterModel->setProject(project);

View File

@@ -40,7 +40,6 @@ class Diagnostic;
class DummyRunConfiguration; class DummyRunConfiguration;
const char ClangStaticAnalyzerPerspectiveId[] = "ClangStaticAnalyzer.Perspective"; const char ClangStaticAnalyzerPerspectiveId[] = "ClangStaticAnalyzer.Perspective";
const char ClangStaticAnalyzerActionId[] = "ClangStaticAnalyzer.Action";
const char ClangStaticAnalyzerDockId[] = "ClangStaticAnalyzer.Dock"; const char ClangStaticAnalyzerDockId[] = "ClangStaticAnalyzer.Dock";
class ClangStaticAnalyzerTool : public QObject class ClangStaticAnalyzerTool : public QObject

View File

@@ -33,7 +33,6 @@ namespace Constants {
// Menu. // Menu.
const char M_DEBUG_ANALYZER[] = "Analyzer.Menu.StartAnalyzer"; const char M_DEBUG_ANALYZER[] = "Analyzer.Menu.StartAnalyzer";
const char M_DEBUG_ANALYZER_QML_OPTIONS[] = "Analyzer.Menu.QMLOptions";
const char G_ANALYZER_CONTROL[] = "Menu.Group.Analyzer.Control"; const char G_ANALYZER_CONTROL[] = "Menu.Group.Analyzer.Control";
const char G_ANALYZER_TOOLS[] = "Menu.Group.Analyzer.Tools"; const char G_ANALYZER_TOOLS[] = "Menu.Group.Analyzer.Tools";

View File

@@ -32,6 +32,7 @@
#include <coreplugin/id.h> #include <coreplugin/id.h>
#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/runconfiguration.h> #include <projectexplorer/runconfiguration.h>
@@ -39,11 +40,6 @@
#include <functional> #include <functional>
QT_BEGIN_NAMESPACE
class QDockWidget;
class QAction;
QT_END_NAMESPACE
namespace Debugger { namespace Debugger {
/** /**
@@ -60,71 +56,19 @@ enum ToolMode {
ReleaseMode = 0x4, ReleaseMode = 0x4,
SymbolsMode = DebugMode | ProfileMode, SymbolsMode = DebugMode | ProfileMode,
OptimizedMode = ProfileMode | ReleaseMode, OptimizedMode = ProfileMode | ReleaseMode,
AnyMode = DebugMode | ProfileMode | ReleaseMode //AnyMode = DebugMode | ProfileMode | ReleaseMode
}; };
Q_DECLARE_FLAGS(ToolModes, ToolMode)
/** using RunControlCreator = std::function<ProjectExplorer::RunControl *
* This class represents an analyzation action, i.e. a tool that runs in a specific mode. (ProjectExplorer::RunConfiguration *runConfiguration, Core::Id runMode)>;
*
*/
class DEBUGGER_EXPORT ActionDescription
{
Q_DECLARE_TR_FUNCTIONS(Debugger::AnalyzerAction)
public:
ActionDescription() {}
Core::Id menuGroup() const { return m_menuGroup; }
void setMenuGroup(Core::Id menuGroup) { m_menuGroup = menuGroup; }
QByteArray perspectiveId() const { return m_perspectiveId; }
void setPerspectiveId(const QByteArray &id) { m_perspectiveId = id; }
void setToolMode(QFlags<ToolMode> mode) { m_toolMode = mode; }
Core::Id runMode() const { return m_runMode; }
void setRunMode(Core::Id mode) { m_runMode = mode; }
/// Returns a new engine for the given start parameters.
/// Called each time the tool is launched.
typedef std::function<ProjectExplorer::RunControl *(ProjectExplorer::RunConfiguration *runConfiguration,
Core::Id runMode)> RunControlCreator;
RunControlCreator runControlCreator() const { return m_runControlCreator; }
void setRunControlCreator(const RunControlCreator &creator) { m_runControlCreator = creator; }
typedef std::function<bool()> ToolPreparer;
ToolPreparer toolPreparer() const { return m_toolPreparer; }
void setToolPreparer(const ToolPreparer &toolPreparer) { m_toolPreparer = toolPreparer; }
void startTool() const;
/// This is only used for setups not using the startup project.
typedef std::function<void(ProjectExplorer::RunConfiguration *runConfiguration)> ToolStarter;
void setCustomToolStarter(const ToolStarter &toolStarter) { m_customToolStarter = toolStarter; }
QString toolTip() const { return m_toolTip; }
void setToolTip(const QString &toolTip) { m_toolTip = toolTip; }
QString text() const { return m_text; }
void setText(const QString &text) { m_text = text; }
private:
QString m_text;
QString m_toolTip;
Core::Id m_menuGroup;
QByteArray m_perspectiveId;
QFlags<ToolMode> m_toolMode = AnyMode;
Core::Id m_runMode;
RunControlCreator m_runControlCreator;
ToolStarter m_customToolStarter;
ToolPreparer m_toolPreparer;
};
// FIXME: Merge with something sensible. // FIXME: Merge with something sensible.
DEBUGGER_EXPORT bool wantRunTool(ToolMode toolMode, const QString &toolName);
DEBUGGER_EXPORT void showCannotStartDialog(const QString &toolName);
DEBUGGER_EXPORT ProjectExplorer::RunConfiguration *startupRunConfiguration();
// Register a tool for a given start mode. // Register a tool for a given start mode.
DEBUGGER_EXPORT void registerAction(Core::Id actionId, const ActionDescription &desc, QAction *startAction = 0); DEBUGGER_EXPORT void registerAction(Core::Id runMode, const RunControlCreator &runControlCreator);
DEBUGGER_EXPORT void registerPerspective(const QByteArray &perspectiveId, const Utils::Perspective *perspective); DEBUGGER_EXPORT void registerPerspective(const QByteArray &perspectiveId, const Utils::Perspective *perspective);
DEBUGGER_EXPORT void registerToolbar(const QByteArray &perspectiveId, const Utils::ToolbarDescription &desc); DEBUGGER_EXPORT void registerToolbar(const QByteArray &perspectiveId, const Utils::ToolbarDescription &desc);

View File

@@ -973,7 +973,7 @@ public:
QPointer<QWidget> m_modeWindow; QPointer<QWidget> m_modeWindow;
QPointer<DebugMode> m_mode; QPointer<DebugMode> m_mode;
QHash<Id, ActionDescription> m_descriptions; QHash<Id, RunControlCreator> m_runControlCreators;
ActionContainer *m_menu = 0; ActionContainer *m_menu = 0;
// DockWidgetEventFilter m_resizeEventFilter; // DockWidgetEventFilter m_resizeEventFilter;
@@ -3430,85 +3430,80 @@ static bool buildTypeAccepted(QFlags<ToolMode> toolMode, BuildConfiguration::Bui
return false; return false;
} }
void ActionDescription::startTool() const RunConfiguration *startupRunConfiguration()
{ {
TaskHub::clearTasks(Constants::ANALYZERTASK_ID); if (Project *pro = SessionManager::startupProject()) {
Debugger::selectPerspective(m_perspectiveId); if (const Target *target = pro->activeTarget())
return target->activeRunConfiguration();
}
return nullptr;
}
if (m_toolPreparer && !m_toolPreparer()) static BuildConfiguration::BuildType startupBuildType()
return; {
// ### not sure if we're supposed to check if the RunConFiguration isEnabled
Project *pro = SessionManager::startupProject();
RunConfiguration *rc = 0;
BuildConfiguration::BuildType buildType = BuildConfiguration::Unknown; BuildConfiguration::BuildType buildType = BuildConfiguration::Unknown;
if (pro) { if (RunConfiguration *runConfig = startupRunConfiguration()) {
if (const Target *target = pro->activeTarget()) { if (const BuildConfiguration *buildConfig = runConfig->target()->activeBuildConfiguration())
// Build configuration is 0 for QML projects. buildType = buildConfig->buildType();
if (const BuildConfiguration *buildConfig = target->activeBuildConfiguration())
buildType = buildConfig->buildType();
rc = target->activeRunConfiguration();
}
} }
return buildType;
}
// Custom start. void showCannotStartDialog(const QString &text)
if (m_customToolStarter) { {
if (rc) { QMessageBox *errorDialog = new QMessageBox(ICore::mainWindow());
m_customToolStarter(rc); errorDialog->setIcon(QMessageBox::Warning);
} else { errorDialog->setWindowTitle(text);
QMessageBox *errorDialog = new QMessageBox(ICore::mainWindow()); errorDialog->setText(DebuggerPlugin::tr("Cannot start %1 without a project. Please open the project "
errorDialog->setIcon(QMessageBox::Warning); "and try again.").arg(text));
errorDialog->setWindowTitle(m_text); errorDialog->setStandardButtons(QMessageBox::Ok);
errorDialog->setText(tr("Cannot start %1 without a project. Please open the project " errorDialog->setDefaultButton(QMessageBox::Ok);
"and try again.").arg(m_text)); errorDialog->show();
errorDialog->setStandardButtons(QMessageBox::Ok); }
errorDialog->setDefaultButton(QMessageBox::Ok);
errorDialog->show();
}
return;
}
bool wantRunTool(ToolMode toolMode, const QString &toolName)
{
// Check the project for whether the build config is in the correct mode // Check the project for whether the build config is in the correct mode
// if not, notify the user and urge him to use the correct mode. // if not, notify the user and urge him to use the correct mode.
if (!buildTypeAccepted(m_toolMode, buildType)) { BuildConfiguration::BuildType buildType = startupBuildType();
if (!buildTypeAccepted(toolMode, buildType)) {
QString currentMode; QString currentMode;
switch (buildType) { switch (buildType) {
case BuildConfiguration::Debug: case BuildConfiguration::Debug:
currentMode = tr("Debug"); currentMode = DebuggerPlugin::tr("Debug");
break; break;
case BuildConfiguration::Profile: case BuildConfiguration::Profile:
currentMode = tr("Profile"); currentMode = DebuggerPlugin::tr("Profile");
break; break;
case BuildConfiguration::Release: case BuildConfiguration::Release:
currentMode = tr("Release"); currentMode = DebuggerPlugin::tr("Release");
break; break;
default: default:
QTC_CHECK(false); QTC_CHECK(false);
} }
QString toolModeString; QString toolModeString;
switch (m_toolMode) { switch (toolMode) {
case DebugMode: case DebugMode:
toolModeString = tr("in Debug mode"); toolModeString = DebuggerPlugin::tr("in Debug mode");
break; break;
case ProfileMode: case ProfileMode:
toolModeString = tr("in Profile mode"); toolModeString = DebuggerPlugin::tr("in Profile mode");
break; break;
case ReleaseMode: case ReleaseMode:
toolModeString = tr("in Release mode"); toolModeString = DebuggerPlugin::tr("in Release mode");
break; break;
case SymbolsMode: case SymbolsMode:
toolModeString = tr("with debug symbols (Debug or Profile mode)"); toolModeString = DebuggerPlugin::tr("with debug symbols (Debug or Profile mode)");
break; break;
case OptimizedMode: case OptimizedMode:
toolModeString = tr("on optimized code (Profile or Release mode)"); toolModeString = DebuggerPlugin::tr("on optimized code (Profile or Release mode)");
break; break;
default: default:
QTC_CHECK(false); QTC_CHECK(false);
} }
const QString toolName = m_text; // The action text is always the name of the tool const QString title = DebuggerPlugin::tr("Run %1 in %2 Mode?").arg(toolName).arg(currentMode);
const QString title = tr("Run %1 in %2 Mode?").arg(toolName).arg(currentMode); const QString message = DebuggerPlugin::tr("<html><head/><body><p>You are trying "
const QString message = tr("<html><head/><body><p>You are trying "
"to run the tool \"%1\" on an application in %2 mode. " "to run the tool \"%1\" on an application in %2 mode. "
"The tool is designed to be used %3.</p><p>" "The tool is designed to be used %3.</p><p>"
"Run-time characteristics differ significantly between " "Run-time characteristics differ significantly between "
@@ -3523,34 +3518,15 @@ void ActionDescription::startTool() const
if (Utils::CheckableMessageBox::doNotAskAgainQuestion(ICore::mainWindow(), if (Utils::CheckableMessageBox::doNotAskAgainQuestion(ICore::mainWindow(),
title, message, ICore::settings(), QLatin1String("AnalyzerCorrectModeWarning")) title, message, ICore::settings(), QLatin1String("AnalyzerCorrectModeWarning"))
!= QDialogButtonBox::Yes) != QDialogButtonBox::Yes)
return; return false;
} }
ProjectExplorerPlugin::runStartupProject(m_runMode); return true;
} }
void registerAction(Id actionId, const ActionDescription &desc, QAction *startAction) void registerAction(Id runMode, const RunControlCreator &runControlCreator)
{ {
auto action = new QAction(dd); dd->m_runControlCreators.insert(runMode, runControlCreator);
action->setText(desc.text());
action->setToolTip(desc.toolTip());
dd->m_descriptions.insert(actionId, desc);
Id menuGroup = desc.menuGroup();
if (menuGroup.isValid()) {
Command *command = ActionManager::registerAction(action, actionId);
dd->m_menu->addAction(command, menuGroup);
}
QObject::connect(action, &QAction::triggered, dd, [desc] { desc.startTool(); });
if (startAction) {
QObject::connect(startAction, &QAction::triggered, action, &QAction::triggered);
QObject::connect(startAction, &QAction::changed, action, [action, startAction] {
action->setEnabled(startAction->isEnabled());
});
}
} }
void registerToolbar(const QByteArray &perspectiveId, const ToolbarDescription &desc) void registerToolbar(const QByteArray &perspectiveId, const ToolbarDescription &desc)
@@ -3628,11 +3604,10 @@ void showPermanentStatusMessage(const QString &message)
RunControl *createAnalyzerRunControl(RunConfiguration *runConfiguration, Id runMode) RunControl *createAnalyzerRunControl(RunConfiguration *runConfiguration, Id runMode)
{ {
foreach (const ActionDescription &action, dd->m_descriptions) { RunControlCreator rcc = dd->m_runControlCreators.value(runMode);
if (action.runMode() == runMode) if (rcc)
return action.runControlCreator()(runConfiguration, runMode); return rcc(runConfiguration, runMode);
} return nullptr;
return 0;
} }
namespace Internal { namespace Internal {

View File

@@ -44,8 +44,6 @@ const char QtdFileExtension[] = ".qtd";
const char QztFileExtension[] = ".qzt"; const char QztFileExtension[] = ".qzt";
const char QmlProfilerPerspectiveId[] = "QmlProfiler.Perspective"; const char QmlProfilerPerspectiveId[] = "QmlProfiler.Perspective";
const char QmlProfilerLocalActionId[] = "QmlProfiler.Local";
const char QmlProfilerRemoteActionId[] = "QmlProfiler.Remote";
const char QmlProfilerLoadActionId[] = const char QmlProfilerLoadActionId[] =
"Analyzer.Menu.StartAnalyzer.QMLProfilerOptions.LoadQMLTrace"; "Analyzer.Menu.StartAnalyzer.QMLProfilerOptions.LoadQMLTrace";

View File

@@ -53,6 +53,7 @@
#include <projectexplorer/session.h> #include <projectexplorer/session.h>
#include <projectexplorer/kitinformation.h> #include <projectexplorer/kitinformation.h>
#include <projectexplorer/runnables.h> #include <projectexplorer/runnables.h>
#include <projectexplorer/taskhub.h>
#include <texteditor/texteditor.h> #include <texteditor/texteditor.h>
#include <coreplugin/coreconstants.h> #include <coreplugin/coreconstants.h>
@@ -162,7 +163,7 @@ QmlProfilerTool::QmlProfilerTool(QObject *parent)
Command *command = 0; Command *command = 0;
ActionContainer *menu = ActionManager::actionContainer(M_DEBUG_ANALYZER); ActionContainer *menu = ActionManager::actionContainer(M_DEBUG_ANALYZER);
ActionContainer *options = ActionManager::createMenu(M_DEBUG_ANALYZER_QML_OPTIONS); ActionContainer *options = ActionManager::createMenu("Analyzer.Menu.QMLOptions");
options->menu()->setTitle(tr("QML Profiler Options")); options->menu()->setTitle(tr("QML Profiler Options"));
menu->addMenu(options, G_ANALYZER_OPTIONS); menu->addMenu(options, G_ANALYZER_OPTIONS);
options->menu()->setEnabled(true); options->menu()->setEnabled(true);
@@ -253,25 +254,28 @@ QmlProfilerTool::QmlProfilerTool(QObject *parent)
d->m_startAction = Debugger::createStartAction(); d->m_startAction = Debugger::createStartAction();
d->m_stopAction = Debugger::createStopAction(); d->m_stopAction = Debugger::createStopAction();
ActionDescription desc; Debugger::registerAction(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE, runControlCreator);
desc.setText(tr("QML Profiler")); act = new QAction(tr("QML Profiler"), this);
desc.setToolTip(description); act->setToolTip(description);
desc.setPerspectiveId(Constants::QmlProfilerPerspectiveId); menu->addAction(ActionManager::registerAction(act, "QmlProfiler.Local"),
desc.setRunControlCreator(runControlCreator); Debugger::Constants::G_ANALYZER_TOOLS);
desc.setToolPreparer([this] { return prepareTool(); }); QObject::connect(act, &QAction::triggered, this, [this] {
desc.setRunMode(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE); if (!prepareTool())
desc.setMenuGroup(Debugger::Constants::G_ANALYZER_TOOLS); return;
Debugger::registerAction(Constants::QmlProfilerLocalActionId, desc, d->m_startAction); Debugger::selectPerspective(Constants::QmlProfilerPerspectiveId);
ProjectExplorerPlugin::runStartupProject(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
});
QObject::connect(d->m_startAction, &QAction::triggered, act, &QAction::triggered);
QObject::connect(d->m_startAction, &QAction::changed, act, [act, this] {
act->setEnabled(d->m_startAction->isEnabled());
});
desc.setText(tr("QML Profiler (External)")); Debugger::registerAction(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE, runControlCreator);
desc.setToolTip(description); act = new QAction(tr("QML Profiler (External)"), this);
desc.setPerspectiveId(Constants::QmlProfilerPerspectiveId); act->setToolTip(description);
desc.setRunControlCreator(runControlCreator); menu->addAction(ActionManager::registerAction(act, "QmlProfiler.Remote"),
desc.setCustomToolStarter([this](RunConfiguration *rc) { startRemoteTool(rc); }); Debugger::Constants::G_ANALYZER_REMOTE_TOOLS);
desc.setToolPreparer([this] { return prepareTool(); }); QObject::connect(act, &QAction::triggered, this, &QmlProfilerTool::startRemoteTool);
desc.setRunMode(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
desc.setMenuGroup(Debugger::Constants::G_ANALYZER_REMOTE_TOOLS);
Debugger::registerAction(Constants::QmlProfilerRemoteActionId, desc);
Utils::ToolbarDescription toolbar; Utils::ToolbarDescription toolbar;
toolbar.addAction(d->m_startAction); toolbar.addAction(d->m_startAction);
@@ -556,8 +560,11 @@ bool QmlProfilerTool::prepareTool()
return true; return true;
} }
void QmlProfilerTool::startRemoteTool(ProjectExplorer::RunConfiguration *rc) void QmlProfilerTool::startRemoteTool()
{ {
if (!prepareTool())
return;
Id kitId; Id kitId;
quint16 port; quint16 port;
Kit *kit = 0; Kit *kit = 0;
@@ -594,6 +601,9 @@ void QmlProfilerTool::startRemoteTool(ProjectExplorer::RunConfiguration *rc)
} }
connection.analyzerPort = Utils::Port(port); connection.analyzerPort = Utils::Port(port);
Debugger::selectPerspective(Constants::QmlProfilerPerspectiveId);
RunConfiguration *rc = Debugger::startupRunConfiguration();
auto runControl = qobject_cast<QmlProfilerRunControl *>(createRunControl(rc)); auto runControl = qobject_cast<QmlProfilerRunControl *>(createRunControl(rc));
runControl->setConnection(connection); runControl->setConnection(connection);

View File

@@ -53,7 +53,7 @@ public:
void finalizeRunControl(QmlProfilerRunControl *runControl); void finalizeRunControl(QmlProfilerRunControl *runControl);
bool prepareTool(); bool prepareTool();
void startRemoteTool(ProjectExplorer::RunConfiguration *rc); void startRemoteTool();
QString summary(const QVector<int> &typeIds) const; QString summary(const QVector<int> &typeIds) const;
QStringList details(int typeId) const; QStringList details(int typeId) const;

View File

@@ -251,28 +251,47 @@ CallgrindTool::CallgrindTool(QObject *parent)
m_startAction = Debugger::createStartAction(); m_startAction = Debugger::createStartAction();
m_stopAction = Debugger::createStopAction(); m_stopAction = Debugger::createStopAction();
ActionDescription desc; ActionContainer *menu = ActionManager::actionContainer(Debugger::Constants::M_DEBUG_ANALYZER);
desc.setToolTip(tr("Valgrind Function Profiler uses the " QString toolTip = tr("Valgrind Function Profiler uses the "
"Callgrind tool to record function calls when a program runs.")); "Callgrind tool to record function calls when a program runs.");
auto rcc = [this](RunConfiguration *runConfiguration, Id mode) {
return createRunControl(runConfiguration, mode);
};
if (!Utils::HostOsInfo::isWindowsHost()) { if (!Utils::HostOsInfo::isWindowsHost()) {
desc.setText(tr("Valgrind Function Profiler")); Debugger::registerAction(CALLGRIND_RUN_MODE, rcc);
desc.setPerspectiveId(CallgrindPerspectiveId); auto action = new QAction(tr("Valgrind Function Profiler"), this);
desc.setRunControlCreator([this](RunConfiguration *runConfiguration, Id) { action->setToolTip(toolTip);
return createRunControl(runConfiguration, CALLGRIND_RUN_MODE); menu->addAction(ActionManager::registerAction(action, CallgrindLocalActionId),
Debugger::Constants::G_ANALYZER_TOOLS);
QObject::connect(action, &QAction::triggered, this, [action] {
if (!Debugger::wantRunTool(OptimizedMode, action->text()))
return;
Debugger::selectPerspective(CallgrindPerspectiveId);
ProjectExplorerPlugin::runStartupProject(CALLGRIND_RUN_MODE);
});
QObject::connect(m_startAction, &QAction::triggered, action, &QAction::triggered);
QObject::connect(m_startAction, &QAction::changed, action, [action, this] {
action->setEnabled(m_startAction->isEnabled());
}); });
desc.setToolMode(OptimizedMode);
desc.setRunMode(CALLGRIND_RUN_MODE);
desc.setMenuGroup(Debugger::Constants::G_ANALYZER_TOOLS);
Debugger::registerAction(CallgrindLocalActionId, desc, m_startAction);
} }
desc.setText(tr("Valgrind Function Profiler (External Application)")); Debugger::registerAction(CALLGRIND_RUN_MODE, rcc);
desc.setPerspectiveId(CallgrindPerspectiveId); auto action = new QAction(tr("Valgrind Function Profiler (External Application)"), this);
desc.setCustomToolStarter([this](RunConfiguration *runConfig) { action->setToolTip(toolTip);
menu->addAction(ActionManager::registerAction(action, CallgrindRemoteActionId),
Debugger::Constants::G_ANALYZER_REMOTE_TOOLS);
QObject::connect(action, &QAction::triggered, this, [this, action] {
RunConfiguration *runConfig = startupRunConfiguration();
if (!runConfig) {
showCannotStartDialog(action->text());
return;
}
StartRemoteDialog dlg; StartRemoteDialog dlg;
if (dlg.exec() != QDialog::Accepted) if (dlg.exec() != QDialog::Accepted)
return; return;
Debugger::selectPerspective(CallgrindPerspectiveId);
ValgrindRunControl *rc = createRunControl(runConfig, CALLGRIND_RUN_MODE); ValgrindRunControl *rc = createRunControl(runConfig, CALLGRIND_RUN_MODE);
QTC_ASSERT(rc, return); QTC_ASSERT(rc, return);
const auto runnable = dlg.runnable(); const auto runnable = dlg.runnable();
@@ -283,8 +302,6 @@ CallgrindTool::CallgrindTool(QObject *parent)
rc->setDisplayName(runnable.executable); rc->setDisplayName(runnable.executable);
ProjectExplorerPlugin::startRunControl(rc); ProjectExplorerPlugin::startRunControl(rc);
}); });
desc.setMenuGroup(Debugger::Constants::G_ANALYZER_REMOTE_TOOLS);
Debugger::registerAction(CallgrindRemoteActionId, desc);
// If there is a CppEditor context menu add our own context menu actions. // If there is a CppEditor context menu add our own context menu actions.
if (ActionContainer *editorContextMenu = if (ActionContainer *editorContextMenu =
@@ -360,7 +377,7 @@ CallgrindTool::CallgrindTool(QObject *parent)
// //
// load external log file // load external log file
auto action = m_loadExternalLogFile = new QAction(this); action = m_loadExternalLogFile = new QAction(this);
action->setIcon(Utils::Icons::OPENFILE.icon()); action->setIcon(Utils::Icons::OPENFILE.icon());
action->setToolTip(tr("Load External Log File")); action->setToolTip(tr("Load External Log File"));
connect(action, &QAction::triggered, this, &CallgrindTool::loadExternalLogFile); connect(action, &QAction::triggered, this, &CallgrindTool::loadExternalLogFile);

View File

@@ -57,6 +57,7 @@
#include <projectexplorer/session.h> #include <projectexplorer/session.h>
#include <projectexplorer/buildconfiguration.h> #include <projectexplorer/buildconfiguration.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actioncontainer.h> #include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h> #include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/command.h> #include <coreplugin/actionmanager/command.h>
@@ -87,6 +88,7 @@
#include <QString> #include <QString>
#include <QToolButton> #include <QToolButton>
using namespace Core;
using namespace Debugger; using namespace Debugger;
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace Utils; using namespace Utils;
@@ -390,37 +392,66 @@ MemcheckTool::MemcheckTool(QObject *parent)
connect(m_filterMenu, &QMenu::triggered, this, &MemcheckTool::updateErrorFilter); connect(m_filterMenu, &QMenu::triggered, this, &MemcheckTool::updateErrorFilter);
filterButton->setMenu(m_filterMenu); filterButton->setMenu(m_filterMenu);
ActionDescription desc; ActionContainer *menu = ActionManager::actionContainer(Debugger::Constants::M_DEBUG_ANALYZER);
desc.setToolTip(tr("Valgrind Analyze Memory uses the " QString toolTip = tr("Valgrind Analyze Memory uses the Memcheck tool to find memory leaks.");
"Memcheck tool to find memory leaks."));
if (!Utils::HostOsInfo::isWindowsHost()) { if (!Utils::HostOsInfo::isWindowsHost()) {
desc.setText(tr("Valgrind Memory Analyzer")); Debugger::registerAction(MEMCHECK_RUN_MODE, std::bind(&MemcheckTool::createRunControl, this, _1, _2));
desc.setPerspectiveId(MemcheckPerspectiveId); action = new QAction(this);
desc.setRunControlCreator(std::bind(&MemcheckTool::createRunControl, this, _1, _2)); action->setText(tr("Valgrind Memory Analyzer"));
desc.setToolMode(DebugMode); action->setToolTip(toolTip);
desc.setRunMode(MEMCHECK_RUN_MODE); menu->addAction(ActionManager::registerAction(action, "Memcheck.Local"),
desc.setMenuGroup(Debugger::Constants::G_ANALYZER_TOOLS); Debugger::Constants::G_ANALYZER_TOOLS);
Debugger::registerAction("Memcheck.Local", desc, m_startAction); QObject::connect(action, &QAction::triggered, this, [action] {
if (!Debugger::wantRunTool(DebugMode, action->text()))
return;
TaskHub::clearTasks(Debugger::Constants::ANALYZERTASK_ID);
Debugger::selectPerspective(MemcheckPerspectiveId);
ProjectExplorerPlugin::runStartupProject(MEMCHECK_RUN_MODE);
});
QObject::connect(m_startAction, &QAction::triggered, action, &QAction::triggered);
QObject::connect(m_startAction, &QAction::changed, action, [action, this] {
action->setEnabled(m_startAction->isEnabled());
});
desc.setText(tr("Valgrind Memory Analyzer with GDB")); Debugger::registerAction(MEMCHECK_WITH_GDB_RUN_MODE, std::bind(&MemcheckTool::createRunControl, this, _1, _2));
desc.setToolTip(tr("Valgrind Analyze Memory with GDB uses the " action = new QAction(this);
action->setText(tr("Valgrind Memory Analyzer with GDB"));
action->setToolTip(tr("Valgrind Analyze Memory with GDB uses the "
"Memcheck tool to find memory leaks.\nWhen a problem is detected, " "Memcheck tool to find memory leaks.\nWhen a problem is detected, "
"the application is interrupted and can be debugged.")); "the application is interrupted and can be debugged."));
desc.setPerspectiveId(MemcheckPerspectiveId); menu->addAction(ActionManager::registerAction(action, "MemcheckWithGdb.Local"),
desc.setRunControlCreator(std::bind(&MemcheckTool::createRunControl, this, _1, _2)); Debugger::Constants::G_ANALYZER_TOOLS);
desc.setToolMode(DebugMode); QObject::connect(action, &QAction::triggered, this, [action] {
desc.setRunMode(MEMCHECK_WITH_GDB_RUN_MODE); if (!Debugger::wantRunTool(DebugMode, action->text()))
desc.setMenuGroup(Debugger::Constants::G_ANALYZER_TOOLS); return;
Debugger::registerAction("MemcheckWithGdb.Local", desc, m_startWithGdbAction); TaskHub::clearTasks(Debugger::Constants::ANALYZERTASK_ID);
Debugger::selectPerspective(MemcheckPerspectiveId);
ProjectExplorerPlugin::runStartupProject(MEMCHECK_WITH_GDB_RUN_MODE);
});
QObject::connect(m_startWithGdbAction, &QAction::triggered, action, &QAction::triggered);
QObject::connect(m_startWithGdbAction, &QAction::changed, action, [action, this] {
action->setEnabled(m_startWithGdbAction->isEnabled());
});
} }
desc.setText(tr("Valgrind Memory Analyzer (External Application)")); Debugger::registerAction(MEMCHECK_RUN_MODE, std::bind(&MemcheckTool::createRunControl, this, _1, _2));
desc.setPerspectiveId(MemcheckPerspectiveId); action = new QAction(this);
desc.setCustomToolStarter([this](ProjectExplorer::RunConfiguration *runConfig) { action->setText(tr("Valgrind Memory Analyzer (External Application)"));
action->setToolTip(toolTip);
menu->addAction(ActionManager::registerAction(action, "Memcheck.Remote"),
Debugger::Constants::G_ANALYZER_REMOTE_TOOLS);
QObject::connect(action, &QAction::triggered, this, [this, action] {
RunConfiguration *runConfig = startupRunConfiguration();
if (!runConfig) {
showCannotStartDialog(action->text());
return;
}
StartRemoteDialog dlg; StartRemoteDialog dlg;
if (dlg.exec() != QDialog::Accepted) if (dlg.exec() != QDialog::Accepted)
return; return;
TaskHub::clearTasks(Debugger::Constants::ANALYZERTASK_ID);
Debugger::selectPerspective(MemcheckPerspectiveId);
RunControl *rc = createRunControl(runConfig, MEMCHECK_RUN_MODE); RunControl *rc = createRunControl(runConfig, MEMCHECK_RUN_MODE);
QTC_ASSERT(rc, return); QTC_ASSERT(rc, return);
const auto runnable = dlg.runnable(); const auto runnable = dlg.runnable();
@@ -431,8 +462,6 @@ MemcheckTool::MemcheckTool(QObject *parent)
rc->setDisplayName(runnable.executable); rc->setDisplayName(runnable.executable);
ProjectExplorerPlugin::startRunControl(rc); ProjectExplorerPlugin::startRunControl(rc);
}); });
desc.setMenuGroup(Debugger::Constants::G_ANALYZER_REMOTE_TOOLS);
Debugger::registerAction("Memcheck.Remote", desc);
ToolbarDescription toolbar; ToolbarDescription toolbar;
toolbar.addAction(m_startAction); toolbar.addAction(m_startAction);