QmlPreview: Remove RefreshTranslationWorker

Merge it with QmlPreviewRunner. No need for a separate worker.

Fix some includes.

Task-number: QTCREATORBUG-29168
Change-Id: Id37a05539aa9afc7ae9e47ef32d75423ed1c186f
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Jarek Kobus
2024-11-20 08:51:07 +01:00
parent 78282fe794
commit c1fcd7fb3a
2 changed files with 14 additions and 45 deletions

View File

@@ -94,9 +94,6 @@ static std::unique_ptr<QmlDebugTranslationClient> defaultCreateDebugTranslationC
return client; return client;
} }
static void defaultRefreshTranslationFunction()
{}
class QmlPreviewPluginPrivate : public QObject class QmlPreviewPluginPrivate : public QObject
{ {
public: public:
@@ -134,7 +131,6 @@ QmlPreviewPluginPrivate::QmlPreviewPluginPrivate(QmlPreviewPlugin *parent)
m_settings.fileClassifier = &defaultFileClassifier; m_settings.fileClassifier = &defaultFileClassifier;
m_settings.fpsHandler = &defaultFpsHandler; m_settings.fpsHandler = &defaultFpsHandler;
m_settings.createDebugTranslationClientMethod = &defaultCreateDebugTranslationClientMethod; m_settings.createDebugTranslationClientMethod = &defaultCreateDebugTranslationClientMethod;
m_settings.refreshTranslationsFunction = &defaultRefreshTranslationFunction;
Core::ActionContainer *menu = Core::ActionManager::actionContainer( Core::ActionContainer *menu = Core::ActionManager::actionContainer(
Constants::M_BUILDPROJECT); Constants::M_BUILDPROJECT);

View File

@@ -1,64 +1,27 @@
// Copyright (C) 2019 The Qt Company Ltd. // Copyright (C) 2019 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "qmlpreviewconnectionmanager.h"
#include "qmlpreviewruncontrol.h" #include "qmlpreviewruncontrol.h"
#include <qmlprojectmanager/qmlproject.h> #include "qmlpreviewconnectionmanager.h"
#include <qmlprojectmanager/qmlmainfileaspect.h>
#include <projectexplorer/projectexplorer.h> #include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/projectmanager.h>
#include <projectexplorer/qmldebugcommandlinearguments.h> #include <projectexplorer/qmldebugcommandlinearguments.h>
#include <projectexplorer/target.h> #include <projectexplorer/target.h>
#include <qmlprojectmanager/buildsystem/qmlbuildsystem.h>
#include <qmlprojectmanager/qmlmainfileaspect.h>
#include <qmlprojectmanager/qmlmultilanguageaspect.h> #include <qmlprojectmanager/qmlmultilanguageaspect.h>
#include <qtsupport/baseqtversion.h>
#include <qtsupport/qtkitaspect.h>
#include <utils/async.h> #include <utils/async.h>
#include <utils/filepath.h> #include <utils/filepath.h>
#include <utils/port.h>
#include <utils/qtcprocess.h>
#include <utils/url.h> #include <utils/url.h>
#include <QFutureWatcher>
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace Utils; using namespace Utils;
namespace QmlPreview { namespace QmlPreview {
class RefreshTranslationWorker final : public RunWorker
{
public:
explicit RefreshTranslationWorker(ProjectExplorer::RunControl *runControl,
const QmlPreviewRunnerSetting &runnerSettings)
: ProjectExplorer::RunWorker(runControl), m_runnerSettings(runnerSettings)
{
setId("RefreshTranslationWorker");
connect(this, &RunWorker::started, this, &RefreshTranslationWorker::startRefreshTranslationsAsync);
connect(this, &RunWorker::stopped, &m_futureWatcher, &QFutureWatcher<void>::cancel);
connect(&m_futureWatcher, &QFutureWatcherBase::finished, this, &RefreshTranslationWorker::stop);
}
~RefreshTranslationWorker()
{
m_futureWatcher.cancel();
m_futureWatcher.waitForFinished();
}
private:
void startRefreshTranslationsAsync()
{
m_futureWatcher.setFuture(Utils::asyncRun([this] {
m_runnerSettings.refreshTranslationsFunction();
}));
}
QmlPreviewRunnerSetting m_runnerSettings;
QFutureWatcher<void> m_futureWatcher;
};
class QmlPreviewRunner : public ProjectExplorer::RunWorker class QmlPreviewRunner : public ProjectExplorer::RunWorker
{ {
Q_OBJECT Q_OBJECT
@@ -81,6 +44,7 @@ private:
QUrl serverUrl() const; QUrl serverUrl() const;
QmlPreviewConnectionManager m_connectionManager; QmlPreviewConnectionManager m_connectionManager;
std::unique_ptr<Utils::Async<void>> m_translationUpdater;
}; };
QmlPreviewRunner::QmlPreviewRunner(RunControl *runControl, const QmlPreviewRunnerSetting &settings) QmlPreviewRunner::QmlPreviewRunner(RunControl *runControl, const QmlPreviewRunnerSetting &settings)
@@ -130,11 +94,19 @@ QmlPreviewRunner::QmlPreviewRunner(RunControl *runControl, const QmlPreviewRunne
runControl->initiateStop(); runControl->initiateStop();
}); });
addStartDependency(new RefreshTranslationWorker(runControl, settings)); if (settings.refreshTranslationsFunction) {
m_translationUpdater.reset(new Async<void>);
m_translationUpdater->setParent(this);
m_translationUpdater->setConcurrentCallData(settings.refreshTranslationsFunction);
// Cancel and blocking wait for finished when deleting m_translationUpdater.
m_translationUpdater->setFutureSynchronizer(nullptr);
}
} }
void QmlPreviewRunner::start() void QmlPreviewRunner::start()
{ {
if (m_translationUpdater)
m_translationUpdater->start();
m_connectionManager.setTarget(runControl()->target()); m_connectionManager.setTarget(runControl()->target());
m_connectionManager.connectToServer(runControl()->qmlChannel()); m_connectionManager.connectToServer(runControl()->qmlChannel());
reportStarted(); reportStarted();
@@ -142,6 +114,7 @@ void QmlPreviewRunner::start()
void QmlPreviewRunner::stop() void QmlPreviewRunner::stop()
{ {
m_translationUpdater.reset();
m_connectionManager.disconnectFromServer(); m_connectionManager.disconnectFromServer();
reportStopped(); reportStopped();
} }