forked from qt-creator/qt-creator
ProjectExplorer: Re-work setup runworker factories
This combines two of the previous three paths to create run workers, and refers to RunConfigurations by id, not by type where possible to decrease coupling between the classes. Only allow "type of run configuration" and "type of device" as the only possible kind of restriction and require a uniform RunWorker constructor signature. Adapt user code to fit that pattern. Change-Id: I5a6d49c9a144785fd0235d7586f244b56f67b366 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -80,34 +80,18 @@ namespace Internal {
|
||||
|
||||
Q_GLOBAL_STATIC(QmlProfilerSettings, qmlProfilerGlobalSettings)
|
||||
|
||||
bool constraint(RunConfiguration *runConfiguration)
|
||||
{
|
||||
Target *target = runConfiguration ? runConfiguration->target() : nullptr;
|
||||
Kit *kit = target ? target->kit() : nullptr;
|
||||
return DeviceTypeKitAspect::deviceTypeId(kit)
|
||||
== ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE;
|
||||
}
|
||||
|
||||
class QmlProfilerRunWorkerFactory : public RunWorkerFactory
|
||||
{
|
||||
public:
|
||||
QmlProfilerRunWorkerFactory(QmlProfilerTool *tool)
|
||||
{
|
||||
addSupportedRunMode(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
|
||||
setProducer([tool](RunControl *runControl) {
|
||||
return new LocalQmlProfilerSupport(tool, runControl);
|
||||
});
|
||||
addConstraint(constraint);
|
||||
}
|
||||
};
|
||||
|
||||
class QmlProfilerPluginPrivate
|
||||
{
|
||||
public:
|
||||
QmlProfilerTool m_profilerTool;
|
||||
QmlProfilerOptionsPage m_profilerOptionsPage;
|
||||
QmlProfilerActions m_actions;
|
||||
QmlProfilerRunWorkerFactory m_profilerWorkerFactory{&m_profilerTool};
|
||||
RunWorkerFactory m_profilerWorkerFactory{
|
||||
RunWorkerFactory::make<LocalQmlProfilerSupport>(),
|
||||
{ProjectExplorer::Constants::QML_PROFILER_RUN_MODE},
|
||||
{},
|
||||
{ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE}
|
||||
};
|
||||
};
|
||||
|
||||
bool QmlProfilerPlugin::initialize(const QStringList &arguments, QString *errorString)
|
||||
|
||||
@@ -218,14 +218,12 @@ static QUrl localServerUrl(RunControl *runControl)
|
||||
return serverUrl;
|
||||
}
|
||||
|
||||
LocalQmlProfilerSupport::LocalQmlProfilerSupport(QmlProfilerTool *profilerTool,
|
||||
RunControl *runControl)
|
||||
: LocalQmlProfilerSupport(profilerTool, runControl, localServerUrl(runControl))
|
||||
LocalQmlProfilerSupport::LocalQmlProfilerSupport(RunControl *runControl)
|
||||
: LocalQmlProfilerSupport(runControl, localServerUrl(runControl))
|
||||
{
|
||||
}
|
||||
|
||||
LocalQmlProfilerSupport::LocalQmlProfilerSupport(QmlProfilerTool *profilerTool,
|
||||
RunControl *runControl, const QUrl &serverUrl)
|
||||
LocalQmlProfilerSupport::LocalQmlProfilerSupport(RunControl *runControl, const QUrl &serverUrl)
|
||||
: SimpleTargetRunner(runControl)
|
||||
{
|
||||
setId("LocalQmlProfilerSupport");
|
||||
@@ -233,7 +231,7 @@ LocalQmlProfilerSupport::LocalQmlProfilerSupport(QmlProfilerTool *profilerTool,
|
||||
auto profiler = new QmlProfilerRunner(runControl);
|
||||
profiler->setServerUrl(serverUrl);
|
||||
connect(profiler, &QmlProfilerRunner::starting,
|
||||
profilerTool, &QmlProfilerTool::finalizeRunControl);
|
||||
QmlProfilerTool::instance(), &QmlProfilerTool::finalizeRunControl);
|
||||
|
||||
addStopDependency(profiler);
|
||||
// We need to open the local server before the application tries to connect.
|
||||
|
||||
@@ -72,8 +72,8 @@ class LocalQmlProfilerSupport : public ProjectExplorer::SimpleTargetRunner
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
LocalQmlProfilerSupport(QmlProfilerTool *profilerTool, ProjectExplorer::RunControl *runControl);
|
||||
LocalQmlProfilerSupport(QmlProfilerTool *profilerTool, ProjectExplorer::RunControl *runControl,
|
||||
LocalQmlProfilerSupport(ProjectExplorer::RunControl *runControl);
|
||||
LocalQmlProfilerSupport(ProjectExplorer::RunControl *runControl,
|
||||
const QUrl &serverUrl);
|
||||
};
|
||||
|
||||
|
||||
@@ -96,6 +96,8 @@ using namespace ProjectExplorer;
|
||||
namespace QmlProfiler {
|
||||
namespace Internal {
|
||||
|
||||
static QmlProfilerTool *m_instance = nullptr;
|
||||
|
||||
class QmlProfilerTool::QmlProfilerToolPrivate
|
||||
{
|
||||
public:
|
||||
@@ -129,6 +131,7 @@ public:
|
||||
QmlProfilerTool::QmlProfilerTool()
|
||||
: d(new QmlProfilerToolPrivate)
|
||||
{
|
||||
m_instance = this;
|
||||
setObjectName(QLatin1String("QmlProfilerTool"));
|
||||
|
||||
d->m_profilerState = new QmlProfilerStateManager(this);
|
||||
@@ -279,6 +282,12 @@ QmlProfilerTool::~QmlProfilerTool()
|
||||
{
|
||||
d->m_profilerModelManager->clearAll();
|
||||
delete d;
|
||||
m_instance = nullptr;
|
||||
}
|
||||
|
||||
QmlProfilerTool *QmlProfilerTool::instance()
|
||||
{
|
||||
return m_instance;
|
||||
}
|
||||
|
||||
void QmlProfilerTool::updateRunActions()
|
||||
|
||||
@@ -52,6 +52,8 @@ public:
|
||||
QmlProfilerTool();
|
||||
~QmlProfilerTool() override;
|
||||
|
||||
static QmlProfilerTool *instance();
|
||||
|
||||
void finalizeRunControl(QmlProfilerRunner *runWorker);
|
||||
|
||||
bool prepareTool();
|
||||
|
||||
@@ -45,7 +45,6 @@ LocalQmlProfilerRunnerTest::LocalQmlProfilerRunnerTest(QObject *parent) : QObjec
|
||||
|
||||
void LocalQmlProfilerRunnerTest::testRunner()
|
||||
{
|
||||
QmlProfilerTool tool;
|
||||
QPointer<ProjectExplorer::RunControl> runControl;
|
||||
QPointer<LocalQmlProfilerSupport> profiler;
|
||||
ProjectExplorer::Runnable debuggee;
|
||||
@@ -66,7 +65,7 @@ void LocalQmlProfilerRunnerTest::testRunner()
|
||||
|
||||
runControl = new ProjectExplorer::RunControl(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
|
||||
runControl->setRunnable(debuggee);
|
||||
profiler = new LocalQmlProfilerSupport(&tool, runControl, serverUrl);
|
||||
profiler = new LocalQmlProfilerSupport(runControl, serverUrl);
|
||||
|
||||
auto connectRunner = [&]() {
|
||||
connect(runControl, &ProjectExplorer::RunControl::aboutToStart, this, [&]() {
|
||||
@@ -116,7 +115,7 @@ void LocalQmlProfilerRunnerTest::testRunner()
|
||||
debuggee.commandLineArguments = QString("-test QmlProfiler,");
|
||||
runControl = new ProjectExplorer::RunControl(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
|
||||
runControl->setRunnable(debuggee);
|
||||
profiler = new LocalQmlProfilerSupport(&tool, runControl, serverUrl);
|
||||
profiler = new LocalQmlProfilerSupport(runControl, serverUrl);
|
||||
connectRunner();
|
||||
runControl->initiateStart();
|
||||
|
||||
@@ -135,7 +134,7 @@ void LocalQmlProfilerRunnerTest::testRunner()
|
||||
serverUrl = Utils::urlFromLocalHostAndFreePort();
|
||||
runControl = new ProjectExplorer::RunControl(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
|
||||
runControl->setRunnable(debuggee);
|
||||
profiler = new LocalQmlProfilerSupport(&tool, runControl, serverUrl);
|
||||
profiler = new LocalQmlProfilerSupport(runControl, serverUrl);
|
||||
connectRunner();
|
||||
runControl->initiateStart();
|
||||
|
||||
@@ -160,7 +159,7 @@ void LocalQmlProfilerRunnerTest::testRunner()
|
||||
|
||||
runControl = new ProjectExplorer::RunControl(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
|
||||
runControl->setRunnable(debuggee);
|
||||
profiler = new LocalQmlProfilerSupport(&tool, runControl, serverUrl);
|
||||
profiler = new LocalQmlProfilerSupport(runControl, serverUrl);
|
||||
connectRunner();
|
||||
runControl->initiateStart();
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ void QmlProfilerToolTest::testAttachToWaitingApplication()
|
||||
QVERIFY(settings);
|
||||
settings->setValue(QLatin1String("AnalyzerQmlAttachDialog/kitId"), newKit->id().toSetting());
|
||||
|
||||
QmlProfilerTool profilerTool;
|
||||
QmlProfilerTool &profilerTool = *QmlProfilerTool::instance();
|
||||
|
||||
QmlProfilerClientManager *clientManager = profilerTool.clientManager();
|
||||
clientManager->setRetryInterval(10);
|
||||
@@ -107,7 +107,7 @@ void QmlProfilerToolTest::testAttachToWaitingApplication()
|
||||
|
||||
void QmlProfilerToolTest::testClearEvents()
|
||||
{
|
||||
QmlProfilerTool profilerTool;
|
||||
QmlProfilerTool &profilerTool = *QmlProfilerTool::instance();
|
||||
QmlProfilerModelManager *modelManager = profilerTool.modelManager();
|
||||
QVERIFY(modelManager);
|
||||
QmlProfilerStateManager *stateManager = profilerTool.stateManager();
|
||||
|
||||
Reference in New Issue
Block a user