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