From c1fcd7fb3ab07ec65b0e98d82ecd3a3edc744739 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Wed, 20 Nov 2024 08:51:07 +0100 Subject: [PATCH] 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 --- src/plugins/qmlpreview/qmlpreviewplugin.cpp | 4 -- .../qmlpreview/qmlpreviewruncontrol.cpp | 55 +++++-------------- 2 files changed, 14 insertions(+), 45 deletions(-) diff --git a/src/plugins/qmlpreview/qmlpreviewplugin.cpp b/src/plugins/qmlpreview/qmlpreviewplugin.cpp index 1661136c32a..b3825f8d1e5 100644 --- a/src/plugins/qmlpreview/qmlpreviewplugin.cpp +++ b/src/plugins/qmlpreview/qmlpreviewplugin.cpp @@ -94,9 +94,6 @@ static std::unique_ptr defaultCreateDebugTranslationC return client; } -static void defaultRefreshTranslationFunction() -{} - class QmlPreviewPluginPrivate : public QObject { public: @@ -134,7 +131,6 @@ QmlPreviewPluginPrivate::QmlPreviewPluginPrivate(QmlPreviewPlugin *parent) m_settings.fileClassifier = &defaultFileClassifier; m_settings.fpsHandler = &defaultFpsHandler; m_settings.createDebugTranslationClientMethod = &defaultCreateDebugTranslationClientMethod; - m_settings.refreshTranslationsFunction = &defaultRefreshTranslationFunction; Core::ActionContainer *menu = Core::ActionManager::actionContainer( Constants::M_BUILDPROJECT); diff --git a/src/plugins/qmlpreview/qmlpreviewruncontrol.cpp b/src/plugins/qmlpreview/qmlpreviewruncontrol.cpp index e5ff2811524..242715d7c38 100644 --- a/src/plugins/qmlpreview/qmlpreviewruncontrol.cpp +++ b/src/plugins/qmlpreview/qmlpreviewruncontrol.cpp @@ -1,64 +1,27 @@ // Copyright (C) 2019 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 -#include "qmlpreviewconnectionmanager.h" #include "qmlpreviewruncontrol.h" -#include -#include +#include "qmlpreviewconnectionmanager.h" #include -#include -#include #include #include +#include +#include #include -#include -#include #include #include -#include -#include #include -#include - using namespace ProjectExplorer; using namespace Utils; 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::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 m_futureWatcher; -}; - class QmlPreviewRunner : public ProjectExplorer::RunWorker { Q_OBJECT @@ -81,6 +44,7 @@ private: QUrl serverUrl() const; QmlPreviewConnectionManager m_connectionManager; + std::unique_ptr> m_translationUpdater; }; QmlPreviewRunner::QmlPreviewRunner(RunControl *runControl, const QmlPreviewRunnerSetting &settings) @@ -130,11 +94,19 @@ QmlPreviewRunner::QmlPreviewRunner(RunControl *runControl, const QmlPreviewRunne runControl->initiateStop(); }); - addStartDependency(new RefreshTranslationWorker(runControl, settings)); + if (settings.refreshTranslationsFunction) { + m_translationUpdater.reset(new Async); + 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() { + if (m_translationUpdater) + m_translationUpdater->start(); m_connectionManager.setTarget(runControl()->target()); m_connectionManager.connectToServer(runControl()->qmlChannel()); reportStarted(); @@ -142,6 +114,7 @@ void QmlPreviewRunner::start() void QmlPreviewRunner::stop() { + m_translationUpdater.reset(); m_connectionManager.disconnectFromServer(); reportStopped(); }