diff --git a/src/plugins/qmlpreview/qmlpreviewplugin.cpp b/src/plugins/qmlpreview/qmlpreviewplugin.cpp index f0e19106280..eae6dec02ed 100644 --- a/src/plugins/qmlpreview/qmlpreviewplugin.cpp +++ b/src/plugins/qmlpreview/qmlpreviewplugin.cpp @@ -138,12 +138,7 @@ public: QString m_localeIsoCode; QmlDebugTranslationClientCreator m_createDebugTranslationClientMethod; - RunWorkerFactory localRunWorkerFactory{ - RunWorkerFactory::make(), - {Constants::QML_PREVIEW_RUN_MODE}, - {}, // All runconfig. - {Constants::DESKTOP_DEVICE_TYPE} - }; + LocalQmlPreviewSupportFactory localRunWorkerFactory; RunWorkerFactory runWorkerFactory{ [this](RunControl *runControl) { diff --git a/src/plugins/qmlpreview/qmlpreviewruncontrol.cpp b/src/plugins/qmlpreview/qmlpreviewruncontrol.cpp index 879a4302d0b..0f45914bbe6 100644 --- a/src/plugins/qmlpreview/qmlpreviewruncontrol.cpp +++ b/src/plugins/qmlpreview/qmlpreviewruncontrol.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -14,11 +15,12 @@ #include #include +#include #include #include #include -#include +using namespace ProjectExplorer; using namespace Utils; namespace QmlPreview { @@ -60,10 +62,10 @@ QmlPreviewRunner::QmlPreviewRunner(const QmlPreviewRunnerSetting &settings) if (!runControl()->isRunning()) return; - this->connect(runControl(), &ProjectExplorer::RunControl::stopped, [this]() { - auto rc = new ProjectExplorer::RunControl(ProjectExplorer::Constants::QML_PREVIEW_RUN_MODE); + this->connect(runControl(), &RunControl::stopped, [this] { + auto rc = new RunControl(ProjectExplorer::Constants::QML_PREVIEW_RUN_MODE); rc->copyDataFromRunControl(runControl()); - ProjectExplorer::ProjectExplorerPlugin::startRunControl(rc); + ProjectExplorerPlugin::startRunControl(rc); }); runControl()->initiateStop(); @@ -93,46 +95,57 @@ QUrl QmlPreviewRunner::serverUrl() const return recordedData(QmlServerUrl).toUrl(); } -LocalQmlPreviewSupport::LocalQmlPreviewSupport(ProjectExplorer::RunControl *runControl) - : SimpleTargetRunner(runControl) +class LocalQmlPreviewSupport final : public SimpleTargetRunner { - setId("LocalQmlPreviewSupport"); - const QUrl serverUrl = Utils::urlFromLocalSocket(); +public: + LocalQmlPreviewSupport(RunControl *runControl) + : SimpleTargetRunner(runControl) + { + setId("LocalQmlPreviewSupport"); + const QUrl serverUrl = Utils::urlFromLocalSocket(); - QmlPreviewRunner *preview = qobject_cast( - runControl->createWorker(ProjectExplorer::Constants::QML_PREVIEW_RUNNER)); - preview->setServerUrl(serverUrl); + QmlPreviewRunner *preview = qobject_cast( + runControl->createWorker(ProjectExplorer::Constants::QML_PREVIEW_RUNNER)); + preview->setServerUrl(serverUrl); - addStopDependency(preview); - addStartDependency(preview); + addStopDependency(preview); + addStartDependency(preview); - setStartModifier([this, runControl, serverUrl] { - CommandLine cmd = commandLine(); + setStartModifier([this, runControl, serverUrl] { + CommandLine cmd = commandLine(); - QStringList qmlProjectRunConfigurationArguments = cmd.splitArguments(); + if (const auto aspect = runControl->aspect()) { + const auto currentTarget = runControl->target(); + const auto qmlBuildSystem = qobject_cast(currentTarget->buildSystem()); - const auto currentTarget = runControl->target(); - const auto *qmlBuildSystem = qobject_cast(currentTarget->buildSystem()); + const QString mainScript = aspect->mainScript; + const QString currentFile = aspect->currentFile; - if (const auto aspect = runControl->aspect()) { - const QString mainScript = aspect->mainScript; - const QString currentFile = aspect->currentFile; + const QString mainScriptFromProject = qmlBuildSystem->targetFile( + FilePath::fromString(mainScript)).toString(); - const QString mainScriptFromProject = qmlBuildSystem->targetFile( - Utils::FilePath::fromString(mainScript)).toString(); + QStringList qmlProjectRunConfigurationArguments = cmd.splitArguments(); - if (!currentFile.isEmpty() && qmlProjectRunConfigurationArguments.last().contains(mainScriptFromProject)) { - qmlProjectRunConfigurationArguments.removeLast(); - cmd = Utils::CommandLine(cmd.executable(), qmlProjectRunConfigurationArguments); - cmd.addArg(currentFile); + if (!currentFile.isEmpty() && qmlProjectRunConfigurationArguments.last().contains(mainScriptFromProject)) { + qmlProjectRunConfigurationArguments.removeLast(); + cmd = CommandLine(cmd.executable(), qmlProjectRunConfigurationArguments); + cmd.addArg(currentFile); + } } - } - cmd.addArg(QmlDebug::qmlDebugLocalArguments(QmlDebug::QmlPreviewServices, serverUrl.path())); - setCommandLine(cmd); + cmd.addArg(QmlDebug::qmlDebugLocalArguments(QmlDebug::QmlPreviewServices, serverUrl.path())); + setCommandLine(cmd); - forceRunOnHost(); - }); + forceRunOnHost(); + }); + } +}; + +LocalQmlPreviewSupportFactory::LocalQmlPreviewSupportFactory() +{ + setProduct(); + addSupportedRunMode(ProjectExplorer::Constants::QML_PREVIEW_RUN_MODE); + addSupportedDeviceType(ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE); } -} // namespace QmlPreview +} // QmlPreview diff --git a/src/plugins/qmlpreview/qmlpreviewruncontrol.h b/src/plugins/qmlpreview/qmlpreviewruncontrol.h index 4a9bf486bf4..3a519bc4414 100644 --- a/src/plugins/qmlpreview/qmlpreviewruncontrol.h +++ b/src/plugins/qmlpreview/qmlpreviewruncontrol.h @@ -44,12 +44,10 @@ private: Internal::QmlPreviewConnectionManager m_connectionManager; }; -class LocalQmlPreviewSupport : public ProjectExplorer::SimpleTargetRunner +class LocalQmlPreviewSupportFactory final : public ProjectExplorer::RunWorkerFactory { - Q_OBJECT - public: - LocalQmlPreviewSupport(ProjectExplorer::RunControl *runControl); + LocalQmlPreviewSupportFactory(); }; -} // namespace QmlPreview +} // QmlPreview