forked from qt-creator/qt-creator
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:
@@ -94,9 +94,6 @@ static std::unique_ptr<QmlDebugTranslationClient> 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);
|
||||
|
@@ -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 <qmlprojectmanager/qmlproject.h>
|
||||
#include <qmlprojectmanager/qmlmainfileaspect.h>
|
||||
#include "qmlpreviewconnectionmanager.h"
|
||||
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
#include <projectexplorer/projectmanager.h>
|
||||
#include <projectexplorer/qmldebugcommandlinearguments.h>
|
||||
#include <projectexplorer/target.h>
|
||||
|
||||
#include <qmlprojectmanager/buildsystem/qmlbuildsystem.h>
|
||||
#include <qmlprojectmanager/qmlmainfileaspect.h>
|
||||
#include <qmlprojectmanager/qmlmultilanguageaspect.h>
|
||||
#include <qtsupport/baseqtversion.h>
|
||||
#include <qtsupport/qtkitaspect.h>
|
||||
|
||||
#include <utils/async.h>
|
||||
#include <utils/filepath.h>
|
||||
#include <utils/port.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
#include <utils/url.h>
|
||||
|
||||
#include <QFutureWatcher>
|
||||
|
||||
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<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
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -81,6 +44,7 @@ private:
|
||||
QUrl serverUrl() const;
|
||||
|
||||
QmlPreviewConnectionManager m_connectionManager;
|
||||
std::unique_ptr<Utils::Async<void>> 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<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()
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user