QmlPreview: Have a dedicated run worker factory class

More similar to what the rest is doing or heading to.

Change-Id: I835ef19810cbce146d3ae22b3881c0e89d1b1fb9
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2023-01-05 13:15:04 +01:00
parent 67195f4270
commit 53f46e0643
3 changed files with 50 additions and 44 deletions

View File

@@ -138,12 +138,7 @@ public:
QString m_localeIsoCode;
QmlDebugTranslationClientCreator m_createDebugTranslationClientMethod;
RunWorkerFactory localRunWorkerFactory{
RunWorkerFactory::make<LocalQmlPreviewSupport>(),
{Constants::QML_PREVIEW_RUN_MODE},
{}, // All runconfig.
{Constants::DESKTOP_DEVICE_TYPE}
};
LocalQmlPreviewSupportFactory localRunWorkerFactory;
RunWorkerFactory runWorkerFactory{
[this](RunControl *runControl) {

View File

@@ -7,6 +7,7 @@
#include <qmlprojectmanager/qmlmainfileaspect.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/session.h>
#include <projectexplorer/target.h>
@@ -14,11 +15,12 @@
#include <qtsupport/baseqtversion.h>
#include <qtsupport/qtkitinformation.h>
#include <utils/filepath.h>
#include <utils/port.h>
#include <utils/qtcprocess.h>
#include <utils/url.h>
#include <utils/fileutils.h>
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<QmlPreviewRunner *>(
runControl->createWorker(ProjectExplorer::Constants::QML_PREVIEW_RUNNER));
preview->setServerUrl(serverUrl);
QmlPreviewRunner *preview = qobject_cast<QmlPreviewRunner *>(
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<QmlProjectManager::QmlMainFileAspect>()) {
const auto currentTarget = runControl->target();
const auto qmlBuildSystem = qobject_cast<QmlProjectManager::QmlBuildSystem *>(currentTarget->buildSystem());
const auto currentTarget = runControl->target();
const auto *qmlBuildSystem = qobject_cast<QmlProjectManager::QmlBuildSystem *>(currentTarget->buildSystem());
const QString mainScript = aspect->mainScript;
const QString currentFile = aspect->currentFile;
if (const auto aspect = runControl->aspect<QmlProjectManager::QmlMainFileAspect>()) {
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<LocalQmlPreviewSupport>();
addSupportedRunMode(ProjectExplorer::Constants::QML_PREVIEW_RUN_MODE);
addSupportedDeviceType(ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE);
}
} // namespace QmlPreview
} // QmlPreview

View File

@@ -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