diff options
author | hjk <hjk@qt.io> | 2019-08-07 18:05:15 +0200 |
---|---|---|
committer | hjk <hjk@qt.io> | 2019-08-09 12:34:42 +0000 |
commit | f9c221eb54ca3174c57f736b7afd5914147ab2a2 (patch) | |
tree | 1d58370c31fd3c342ddd133f659ee01adb017b22 /src/plugins/qmlprofiler | |
parent | a88970db34357adaaedd7514490d94702744a7ec (diff) |
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>
Diffstat (limited to 'src/plugins/qmlprofiler')
-rw-r--r-- | src/plugins/qmlprofiler/qmlprofilerplugin.cpp | 28 | ||||
-rw-r--r-- | src/plugins/qmlprofiler/qmlprofilerruncontrol.cpp | 10 | ||||
-rw-r--r-- | src/plugins/qmlprofiler/qmlprofilerruncontrol.h | 4 | ||||
-rw-r--r-- | src/plugins/qmlprofiler/qmlprofilertool.cpp | 9 | ||||
-rw-r--r-- | src/plugins/qmlprofiler/qmlprofilertool.h | 2 | ||||
-rw-r--r-- | src/plugins/qmlprofiler/tests/localqmlprofilerrunner_test.cpp | 9 | ||||
-rw-r--r-- | src/plugins/qmlprofiler/tests/qmlprofilertool_test.cpp | 4 |
7 files changed, 29 insertions, 37 deletions
diff --git a/src/plugins/qmlprofiler/qmlprofilerplugin.cpp b/src/plugins/qmlprofiler/qmlprofilerplugin.cpp index 942ab9344d..b961a5827b 100644 --- a/src/plugins/qmlprofiler/qmlprofilerplugin.cpp +++ b/src/plugins/qmlprofiler/qmlprofilerplugin.cpp @@ -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) diff --git a/src/plugins/qmlprofiler/qmlprofilerruncontrol.cpp b/src/plugins/qmlprofiler/qmlprofilerruncontrol.cpp index c9cc305d75..4d56267ca4 100644 --- a/src/plugins/qmlprofiler/qmlprofilerruncontrol.cpp +++ b/src/plugins/qmlprofiler/qmlprofilerruncontrol.cpp @@ -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. diff --git a/src/plugins/qmlprofiler/qmlprofilerruncontrol.h b/src/plugins/qmlprofiler/qmlprofilerruncontrol.h index 0bdd9315cb..ac40e16301 100644 --- a/src/plugins/qmlprofiler/qmlprofilerruncontrol.h +++ b/src/plugins/qmlprofiler/qmlprofilerruncontrol.h @@ -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); }; diff --git a/src/plugins/qmlprofiler/qmlprofilertool.cpp b/src/plugins/qmlprofiler/qmlprofilertool.cpp index d951eb4dce..9caef0885c 100644 --- a/src/plugins/qmlprofiler/qmlprofilertool.cpp +++ b/src/plugins/qmlprofiler/qmlprofilertool.cpp @@ -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() diff --git a/src/plugins/qmlprofiler/qmlprofilertool.h b/src/plugins/qmlprofiler/qmlprofilertool.h index 180f1c090c..77759cc690 100644 --- a/src/plugins/qmlprofiler/qmlprofilertool.h +++ b/src/plugins/qmlprofiler/qmlprofilertool.h @@ -52,6 +52,8 @@ public: QmlProfilerTool(); ~QmlProfilerTool() override; + static QmlProfilerTool *instance(); + void finalizeRunControl(QmlProfilerRunner *runWorker); bool prepareTool(); diff --git a/src/plugins/qmlprofiler/tests/localqmlprofilerrunner_test.cpp b/src/plugins/qmlprofiler/tests/localqmlprofilerrunner_test.cpp index 7fa1a6e34f..49eeacdde3 100644 --- a/src/plugins/qmlprofiler/tests/localqmlprofilerrunner_test.cpp +++ b/src/plugins/qmlprofiler/tests/localqmlprofilerrunner_test.cpp @@ -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(); diff --git a/src/plugins/qmlprofiler/tests/qmlprofilertool_test.cpp b/src/plugins/qmlprofiler/tests/qmlprofilertool_test.cpp index 66edba16da..ab085ea458 100644 --- a/src/plugins/qmlprofiler/tests/qmlprofilertool_test.cpp +++ b/src/plugins/qmlprofiler/tests/qmlprofilertool_test.cpp @@ -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(); |