forked from qt-creator/qt-creator
QmlPreview: introduce RefreshTranslationWorker
Change-Id: I327cdd5d869f6cfdd47a826fd42306b8de69aa14 Reviewed-by: Marco Bubke <marco.bubke@qt.io> Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
This commit is contained in:
@@ -12,7 +12,6 @@
|
||||
#include <QMessageBox>
|
||||
|
||||
namespace QmlPreview {
|
||||
namespace Internal {
|
||||
|
||||
QmlPreviewConnectionManager::QmlPreviewConnectionManager(QObject *parent) :
|
||||
QmlDebug::QmlDebugConnectionManager(parent)
|
||||
@@ -44,7 +43,7 @@ void QmlPreviewConnectionManager::setFpsHandler(QmlPreviewFpsHandler fpsHandler)
|
||||
m_fpsHandler = fpsHandler;
|
||||
}
|
||||
|
||||
void QmlPreviewConnectionManager::setQmlDebugTranslationClientCreator(QmlDebugTranslationClientCreator creator)
|
||||
void QmlPreviewConnectionManager::setQmlDebugTranslationClientCreator(QmlDebugTranslationClientFactoryFunction creator)
|
||||
{
|
||||
m_createDebugTranslationClientMethod = creator;
|
||||
}
|
||||
@@ -249,5 +248,4 @@ void QmlPreviewConnectionManager::destroyClients()
|
||||
m_fileSystemWatcher.clear();
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QmlPreview
|
||||
|
@@ -17,7 +17,6 @@ class Target;
|
||||
}
|
||||
|
||||
namespace QmlPreview {
|
||||
namespace Internal {
|
||||
|
||||
class QmlPreviewConnectionManager : public QmlDebug::QmlDebugConnectionManager
|
||||
{
|
||||
@@ -30,7 +29,7 @@ public:
|
||||
void setFileLoader(QmlPreviewFileLoader fileLoader);
|
||||
void setFileClassifier(QmlPreviewFileClassifier fileClassifier);
|
||||
void setFpsHandler(QmlPreviewFpsHandler fpsHandler);
|
||||
void setQmlDebugTranslationClientCreator(QmlDebugTranslationClientCreator creator);
|
||||
void setQmlDebugTranslationClientCreator(QmlDebugTranslationClientFactoryFunction creator);
|
||||
|
||||
signals:
|
||||
void loadFile(const QString &filename, const QString &changedFile, const QByteArray &contents);
|
||||
@@ -58,8 +57,7 @@ private:
|
||||
QmlPreviewFileLoader m_fileLoader = nullptr;
|
||||
QmlPreviewFileClassifier m_fileClassifier = nullptr;
|
||||
QmlPreviewFpsHandler m_fpsHandler = nullptr;
|
||||
QmlDebugTranslationClientCreator m_createDebugTranslationClientMethod;
|
||||
QmlDebugTranslationClientFactoryFunction m_createDebugTranslationClientMethod;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QmlPreview
|
||||
|
@@ -14,7 +14,6 @@
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
namespace QmlPreview {
|
||||
namespace Internal {
|
||||
|
||||
void QmlPreviewFileOnTargetFinder::setTarget(ProjectExplorer::Target *target)
|
||||
{
|
||||
@@ -96,5 +95,4 @@ QUrl QmlPreviewFileOnTargetFinder::findUrl(const QString &filePath, bool *succes
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QmlPreview
|
||||
|
@@ -12,7 +12,6 @@ class Target;
|
||||
}
|
||||
|
||||
namespace QmlPreview {
|
||||
namespace Internal {
|
||||
|
||||
class QmlPreviewFileOnTargetFinder
|
||||
{
|
||||
@@ -27,5 +26,4 @@ private:
|
||||
QPointer<ProjectExplorer::Target> m_target;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QmlPreview
|
||||
|
@@ -96,6 +96,9 @@ static std::unique_ptr<QmlDebugTranslationClient> defaultCreateDebugTranslationC
|
||||
return client;
|
||||
}
|
||||
|
||||
static void defaultRefreshTranslationFunction()
|
||||
{}
|
||||
|
||||
class QmlPreviewPluginPrivate : public QObject
|
||||
{
|
||||
public:
|
||||
@@ -146,6 +149,7 @@ 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);
|
||||
@@ -306,11 +310,16 @@ void QmlPreviewPlugin::setLocaleIsoCode(const QString &localeIsoCode)
|
||||
emit localeIsoCodeChanged(d->m_localeIsoCode);
|
||||
}
|
||||
|
||||
void QmlPreviewPlugin::setQmlDebugTranslationClientCreator(QmlDebugTranslationClientCreator creator)
|
||||
void QmlPreviewPlugin::setQmlDebugTranslationClientCreator(QmlDebugTranslationClientFactoryFunction creator)
|
||||
{
|
||||
d->m_settings.createDebugTranslationClientMethod = creator;
|
||||
}
|
||||
|
||||
void QmlPreviewPlugin::setRefreshTranslationsFunction(QmlPreviewRefreshTranslationFunction refreshTranslationsFunction)
|
||||
{
|
||||
d->m_settings.refreshTranslationsFunction = refreshTranslationsFunction;
|
||||
}
|
||||
|
||||
void QmlPreviewPlugin::setFileLoader(QmlPreviewFileLoader fileLoader)
|
||||
{
|
||||
if (d->m_settings.fileLoader == fileLoader)
|
||||
|
@@ -25,8 +25,9 @@ using QmlPreviewFileClassifier = bool (*)(const QString &);
|
||||
using QmlPreviewFileLoader = QByteArray (*)(const QString &, bool *);
|
||||
using QmlPreviewFpsHandler = void (*)(quint16[8]);
|
||||
using QmlPreviewRunControlList = QList<ProjectExplorer::RunControl *>;
|
||||
using QmlDebugTranslationClientCreator =
|
||||
using QmlDebugTranslationClientFactoryFunction =
|
||||
std::function<std::unique_ptr<QmlDebugTranslationClient>(QmlDebug::QmlDebugConnection *)>;
|
||||
using QmlPreviewRefreshTranslationFunction = std::function<void ()>;
|
||||
|
||||
class QMLPREVIEW_EXPORT QmlPreviewPlugin : public ExtensionSystem::IPlugin
|
||||
{
|
||||
@@ -71,7 +72,8 @@ public:
|
||||
QString localeIsoCode() const;
|
||||
void setLocaleIsoCode(const QString &localeIsoCode);
|
||||
|
||||
void setQmlDebugTranslationClientCreator(QmlDebugTranslationClientCreator creator);
|
||||
void setQmlDebugTranslationClientCreator(QmlDebugTranslationClientFactoryFunction creator);
|
||||
void setRefreshTranslationsFunction(QmlPreviewRefreshTranslationFunction refreshTranslationsFunction);
|
||||
|
||||
void previewCurrentFile();
|
||||
void addPreview(ProjectExplorer::RunControl *preview);
|
||||
|
@@ -16,19 +16,50 @@
|
||||
#include <qtsupport/baseqtversion.h>
|
||||
#include <qtsupport/qtkitinformation.h>
|
||||
|
||||
#include <utils/async.h>
|
||||
#include <utils/filepath.h>
|
||||
#include <utils/port.h>
|
||||
#include <utils/process.h>
|
||||
#include <utils/url.h>
|
||||
|
||||
#include <QFutureWatcher>
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
using namespace Utils;
|
||||
using namespace QmlPreview::Internal;
|
||||
|
||||
namespace QmlPreview {
|
||||
|
||||
static const QString QmlServerUrl = "QmlServerUrl";
|
||||
|
||||
class RefreshTranslationWorker final : public ProjectExplorer::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);
|
||||
}
|
||||
~RefreshTranslationWorker()
|
||||
{
|
||||
m_futureWatcher.cancel();
|
||||
m_futureWatcher.waitForFinished();
|
||||
}
|
||||
|
||||
private:
|
||||
void startRefreshTranslationsAsync()
|
||||
{
|
||||
m_futureWatcher.setFuture(Utils::asyncRun([this] {
|
||||
m_runnerSettings.refreshTranslationsFunction();
|
||||
stop();
|
||||
}));
|
||||
}
|
||||
QmlPreviewRunnerSetting m_runnerSettings;
|
||||
QFutureWatcher<void> m_futureWatcher;
|
||||
};
|
||||
|
||||
class QmlPreviewRunner : public ProjectExplorer::RunWorker
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -51,11 +82,12 @@ private:
|
||||
void start() override;
|
||||
void stop() override;
|
||||
|
||||
Internal::QmlPreviewConnectionManager m_connectionManager;
|
||||
QmlPreviewConnectionManager m_connectionManager;
|
||||
RefreshTranslationWorker m_refreshTranslationWorker;
|
||||
};
|
||||
|
||||
QmlPreviewRunner::QmlPreviewRunner(RunControl *runControl, const QmlPreviewRunnerSetting &settings)
|
||||
: RunWorker(runControl)
|
||||
: RunWorker(runControl), m_refreshTranslationWorker(runControl, settings)
|
||||
{
|
||||
setId("QmlPreviewRunner");
|
||||
m_connectionManager.setFileLoader(settings.fileLoader);
|
||||
@@ -99,6 +131,8 @@ QmlPreviewRunner::QmlPreviewRunner(RunControl *runControl, const QmlPreviewRunne
|
||||
|
||||
runControl->initiateStop();
|
||||
});
|
||||
|
||||
addStartDependency(&m_refreshTranslationWorker);
|
||||
}
|
||||
|
||||
void QmlPreviewRunner::start()
|
||||
|
@@ -16,7 +16,8 @@ struct QmlPreviewRunnerSetting
|
||||
QmlPreviewFpsHandler fpsHandler;
|
||||
float zoomFactor = -1.0;
|
||||
QString language;
|
||||
QmlDebugTranslationClientCreator createDebugTranslationClientMethod;
|
||||
QmlDebugTranslationClientFactoryFunction createDebugTranslationClientMethod;
|
||||
QmlPreviewRefreshTranslationFunction refreshTranslationsFunction;
|
||||
};
|
||||
|
||||
class QmlPreviewRunWorkerFactory final : public ProjectExplorer::RunWorkerFactory
|
||||
|
Reference in New Issue
Block a user