forked from qt-creator/qt-creator
qmlprieview: fix that init language is the chosen one
* removes language feature from preview service * it is handled by an extra DebugTranslationService until now * Qt versions without that extra service can not preview languages anymore * Introduce the use of QmlPreviewRunnerSetting. It makes it easier to add more properties in the future * Language needs an extra handling because it needs the loadUrl to find existing languages. So we save the language to a m_scheduledInitLanguage and emit this after the loadFile call happend. Change-Id: I7f4aec97f7b61d6b290f225282169da594eb9160 Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
@@ -217,6 +217,8 @@ SwitchLanguageComboboxAction::SwitchLanguageComboboxAction(QObject *parent)
|
|||||||
QWidget *SwitchLanguageComboboxAction::createWidget(QWidget *parent)
|
QWidget *SwitchLanguageComboboxAction::createWidget(QWidget *parent)
|
||||||
{
|
{
|
||||||
QPointer<QComboBox> comboBox = new QComboBox(parent);
|
QPointer<QComboBox> comboBox = new QComboBox(parent);
|
||||||
|
// FIXME: this combobox does not work at the moment
|
||||||
|
comboBox->setDisabled(true);
|
||||||
const QString toolTip(tr("Switch the language used by preview."));
|
const QString toolTip(tr("Switch the language used by preview."));
|
||||||
comboBox->setToolTip(toolTip);
|
comboBox->setToolTip(toolTip);
|
||||||
comboBox->addItem(tr("Default"));
|
comboBox->addItem(tr("Default"));
|
||||||
|
@@ -36,24 +36,24 @@ QmlDebugTranslationClient::QmlDebugTranslationClient(QmlDebug::QmlDebugConnectio
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlDebugTranslationClient::changeLanguage(const QUrl &url, const QString &locale)
|
void QmlDebugTranslationClient::changeLanguage(const QUrl &url, const QString &localeIsoCode)
|
||||||
{
|
{
|
||||||
QmlDebug::QPacket packet(dataStreamVersion());
|
QmlDebug::QPacket packet(dataStreamVersion());
|
||||||
packet << static_cast<qint8>(ChangeLanguage) << url << locale;
|
packet << static_cast<qint8>(Command::ChangeLanguage) << url << localeIsoCode;
|
||||||
sendMessage(packet.data());
|
sendMessage(packet.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlDebugTranslationClient::changeWarningColor(const QColor &warningColor)
|
void QmlDebugTranslationClient::changeWarningColor(const QColor &warningColor)
|
||||||
{
|
{
|
||||||
QmlDebug::QPacket packet(dataStreamVersion());
|
QmlDebug::QPacket packet(dataStreamVersion());
|
||||||
packet << static_cast<qint8>(ChangeWarningColor) << warningColor;
|
packet << static_cast<qint8>(Command::ChangeWarningColor) << warningColor;
|
||||||
sendMessage(packet.data());
|
sendMessage(packet.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlDebugTranslationClient::changeElidedTextWarningString(const QString &warningString)
|
void QmlDebugTranslationClient::changeElidedTextWarningString(const QString &warningString)
|
||||||
{
|
{
|
||||||
QmlDebug::QPacket packet(dataStreamVersion());
|
QmlDebug::QPacket packet(dataStreamVersion());
|
||||||
packet << static_cast<qint8>(ChangeElidedTextWarningString) << warningString;
|
packet << static_cast<qint8>(Command::ChangeElidedTextWarningString) << warningString;
|
||||||
sendMessage(packet.data());
|
sendMessage(packet.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,21 +68,21 @@ void QmlDebugTranslationClient::changeElideWarning(bool elideWarning)
|
|||||||
void QmlDebugTranslationClient::setDebugTranslationServiceLogFile(const QString &logFilePath)
|
void QmlDebugTranslationClient::setDebugTranslationServiceLogFile(const QString &logFilePath)
|
||||||
{
|
{
|
||||||
QmlDebug::QPacket packet(dataStreamVersion());
|
QmlDebug::QPacket packet(dataStreamVersion());
|
||||||
packet << static_cast<qint8>(SetDebugTranslationServiceLogFile) << logFilePath;
|
packet << static_cast<qint8>(Command::SetDebugTranslationServiceLogFile) << logFilePath;
|
||||||
sendMessage(packet.data());
|
sendMessage(packet.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlDebugTranslationClient::enableElidedTextWarning()
|
void QmlDebugTranslationClient::enableElidedTextWarning()
|
||||||
{
|
{
|
||||||
QmlDebug::QPacket packet(dataStreamVersion());
|
QmlDebug::QPacket packet(dataStreamVersion());
|
||||||
packet << static_cast<qint8>(EnableElidedTextWarning);
|
packet << static_cast<qint8>(Command::EnableElidedTextWarning);
|
||||||
sendMessage(packet.data());
|
sendMessage(packet.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlDebugTranslationClient::disableElidedTextWarning()
|
void QmlDebugTranslationClient::disableElidedTextWarning()
|
||||||
{
|
{
|
||||||
QmlDebug::QPacket packet(dataStreamVersion());
|
QmlDebug::QPacket packet(dataStreamVersion());
|
||||||
packet << static_cast<qint8>(DisableElidedTextWarning);
|
packet << static_cast<qint8>(Command::DisableElidedTextWarning);
|
||||||
sendMessage(packet.data());
|
sendMessage(packet.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,7 +91,7 @@ void QmlDebugTranslationClient::messageReceived(const QByteArray &data)
|
|||||||
QmlDebug::QPacket packet(dataStreamVersion(), data);
|
QmlDebug::QPacket packet(dataStreamVersion(), data);
|
||||||
qint8 command;
|
qint8 command;
|
||||||
packet >> command;
|
packet >> command;
|
||||||
qDebug() << "invalid command" << command;
|
qDebug() << Q_FUNC_INFO << "invalid command" << command;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlDebugTranslationClient::stateChanged(QmlDebug::QmlDebugClient::State state)
|
void QmlDebugTranslationClient::stateChanged(QmlDebug::QmlDebugClient::State state)
|
||||||
|
@@ -35,19 +35,20 @@ class QMLPREVIEW_EXPORT QmlDebugTranslationClient : public QmlDebug::QmlDebugCli
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
//needs to be in sync with QQmlDebugTranslationClient in qtdeclarative/src/plugins/qmltooling/qmldbg_preview/qqmldebugtranslationservice.h
|
//needs to be in sync with QQmlDebugTranslationClient in qtdeclarative/src/plugins/qmltooling/qmldbg_preview/qqmldebugtranslationservice.h
|
||||||
enum Command {
|
enum class Command {
|
||||||
ChangeLanguage,
|
ChangeLanguage,
|
||||||
|
MissingTranslationsChecked,
|
||||||
|
EnableElidedTextWarning,
|
||||||
|
DisableElidedTextWarning,
|
||||||
ChangeWarningColor,
|
ChangeWarningColor,
|
||||||
ChangeElidedTextWarningString,
|
ChangeElidedTextWarningString,
|
||||||
SetDebugTranslationServiceLogFile,
|
SetDebugTranslationServiceLogFile,
|
||||||
EnableElidedTextWarning,
|
|
||||||
DisableElidedTextWarning,
|
|
||||||
TestAllLanguages
|
TestAllLanguages
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit QmlDebugTranslationClient(QmlDebug::QmlDebugConnection *connection);
|
explicit QmlDebugTranslationClient(QmlDebug::QmlDebugConnection *connection);
|
||||||
|
|
||||||
void changeLanguage(const QUrl &url, const QString &locale);
|
void changeLanguage(const QUrl &url, const QString &localeIsoCode);
|
||||||
void changeWarningColor(const QColor &warningColor);
|
void changeWarningColor(const QColor &warningColor);
|
||||||
void changeElidedTextWarningString(const QString &warningString); //is QByteArray better here?
|
void changeElidedTextWarningString(const QString &warningString); //is QByteArray better here?
|
||||||
void changeElideWarning(bool elideWarning);
|
void changeElideWarning(bool elideWarning);
|
||||||
|
@@ -124,6 +124,7 @@ QmlDebugTranslationWidget::QmlDebugTranslationWidget(QWidget *parent)
|
|||||||
layout()->addWidget(elideWarningCheckBox);
|
layout()->addWidget(elideWarningCheckBox);
|
||||||
connect(elideWarningCheckBox, &QCheckBox::stateChanged, [this] (int state) {
|
connect(elideWarningCheckBox, &QCheckBox::stateChanged, [this] (int state) {
|
||||||
m_elideWarning = (state == Qt::Checked);
|
m_elideWarning = (state == Qt::Checked);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
auto controlLayout = new QHBoxLayout;
|
auto controlLayout = new QHBoxLayout;
|
||||||
@@ -298,14 +299,16 @@ void QmlDebugTranslationWidget::runTest()
|
|||||||
int timerCounter = 1;
|
int timerCounter = 1;
|
||||||
const auto testLanguageList = m_testLanguages;
|
const auto testLanguageList = m_testLanguages;
|
||||||
|
|
||||||
|
if (m_elideWarning)
|
||||||
|
previewPlugin->changeElideWarning(true);
|
||||||
|
|
||||||
auto testLanguages = [previewPlugin, runControl, testLanguageList](int timerCounter, const QString &previewedFile) {
|
auto testLanguages = [previewPlugin, runControl, testLanguageList](int timerCounter, const QString &previewedFile) {
|
||||||
qDebug() << "testLanguages" << previewedFile;
|
|
||||||
for (auto language : testLanguageList) {
|
for (auto language : testLanguageList) {
|
||||||
QTimer::singleShot(timerCounter * 1000, previewPlugin, [previewPlugin, runControl, language, previewedFile]() {
|
QTimer::singleShot(timerCounter * 1000, previewPlugin, [previewPlugin, runControl, language, previewedFile]() {
|
||||||
if (runControl && runControl->isRunning()) {
|
if (runControl && runControl->isRunning()) {
|
||||||
if (!previewedFile.isEmpty())
|
if (!previewedFile.isEmpty())
|
||||||
previewPlugin->setPreviewedFile(previewedFile);
|
previewPlugin->setPreviewedFile(previewedFile);
|
||||||
previewPlugin->setLocale(language);
|
previewPlugin->setLocaleIsoCode(language);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -319,7 +322,7 @@ void QmlDebugTranslationWidget::runTest()
|
|||||||
//delete m_currentRunControl; // who deletes the runcontrol?
|
//delete m_currentRunControl; // who deletes the runcontrol?
|
||||||
m_currentRunControl = nullptr;
|
m_currentRunControl = nullptr;
|
||||||
if (auto previewPlugin = qobject_cast<Internal::QmlPreviewPlugin*>(getPreviewPlugin()))
|
if (auto previewPlugin = qobject_cast<Internal::QmlPreviewPlugin*>(getPreviewPlugin()))
|
||||||
previewPlugin->setLocale(m_lastUsedLanguageBeforeTest);
|
previewPlugin->setLocaleIsoCode(m_lastUsedLanguageBeforeTest);
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(runControl, &ProjectExplorer::RunControl::appendMessage,
|
connect(runControl, &ProjectExplorer::RunControl::appendMessage,
|
||||||
@@ -332,7 +335,7 @@ void QmlDebugTranslationWidget::runTest()
|
|||||||
if (auto runConfiguration = target->activeRunConfiguration()) {
|
if (auto runConfiguration = target->activeRunConfiguration()) {
|
||||||
runControl->setRunConfiguration(runConfiguration);
|
runControl->setRunConfiguration(runConfiguration);
|
||||||
if (runControl->createMainWorker()) {
|
if (runControl->createMainWorker()) {
|
||||||
previewPlugin->setLocale(QString());
|
previewPlugin->setLocaleIsoCode(QString());
|
||||||
runControl->initiateStart();
|
runControl->initiateStart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -399,7 +402,7 @@ void QmlDebugTranslationWidget::appendMessage(const QString &message, Utils::Out
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const QString serviceSeperator = ": QQmlDebugTranslationService: ";
|
const QString serviceSeperator = ": QQmlDebugTranslationService: ";
|
||||||
if (!message.contains(serviceSeperator) || message.contains("DebugTranslation service - language changed"))
|
if (!message.contains(serviceSeperator))
|
||||||
return;
|
return;
|
||||||
QString locationString = message;
|
QString locationString = message;
|
||||||
locationString = locationString.split(serviceSeperator).first();
|
locationString = locationString.split(serviceSeperator).first();
|
||||||
|
@@ -56,13 +56,6 @@ void QmlPreviewClient::zoom(float zoomFactor)
|
|||||||
sendMessage(packet.data());
|
sendMessage(packet.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlPreviewClient::language(const QUrl &context, const QString &locale)
|
|
||||||
{
|
|
||||||
QmlDebug::QPacket packet(dataStreamVersion());
|
|
||||||
packet << static_cast<qint8>(Language) << context << locale;
|
|
||||||
sendMessage(packet.data());
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlPreviewClient::announceFile(const QString &path, const QByteArray &contents)
|
void QmlPreviewClient::announceFile(const QString &path, const QByteArray &contents)
|
||||||
{
|
{
|
||||||
QmlDebug::QPacket packet(dataStreamVersion());
|
QmlDebug::QPacket packet(dataStreamVersion());
|
||||||
|
@@ -43,8 +43,7 @@ public:
|
|||||||
Directory,
|
Directory,
|
||||||
ClearCache,
|
ClearCache,
|
||||||
Zoom,
|
Zoom,
|
||||||
Fps,
|
Fps
|
||||||
Language
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FpsInfo {
|
struct FpsInfo {
|
||||||
@@ -64,7 +63,6 @@ public:
|
|||||||
void loadUrl(const QUrl &url);
|
void loadUrl(const QUrl &url);
|
||||||
void rerun();
|
void rerun();
|
||||||
void zoom(float zoomFactor);
|
void zoom(float zoomFactor);
|
||||||
void language(const QUrl &context, const QString &locale);
|
|
||||||
void announceFile(const QString &path, const QByteArray &contents);
|
void announceFile(const QString &path, const QByteArray &contents);
|
||||||
void announceDirectory(const QString &path, const QStringList &entries);
|
void announceDirectory(const QString &path, const QStringList &entries);
|
||||||
void announceError(const QString &path);
|
void announceError(const QString &path);
|
||||||
|
@@ -36,16 +36,14 @@
|
|||||||
namespace QmlPreview {
|
namespace QmlPreview {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
QmlPreviewConnectionManager::~QmlPreviewConnectionManager()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlPreviewConnectionManager::QmlPreviewConnectionManager(QObject *parent) :
|
QmlPreviewConnectionManager::QmlPreviewConnectionManager(QObject *parent) :
|
||||||
QmlDebug::QmlDebugConnectionManager(parent)
|
QmlDebug::QmlDebugConnectionManager(parent)
|
||||||
{
|
{
|
||||||
setTarget(nullptr);
|
setTarget(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QmlPreviewConnectionManager::~QmlPreviewConnectionManager() = default;
|
||||||
|
|
||||||
void QmlPreviewConnectionManager::setTarget(ProjectExplorer::Target *target)
|
void QmlPreviewConnectionManager::setTarget(ProjectExplorer::Target *target)
|
||||||
{
|
{
|
||||||
QtSupport::BaseQtVersion::populateQmlFileFinder(&m_projectFileFinder, target);
|
QtSupport::BaseQtVersion::populateQmlFileFinder(&m_projectFileFinder, target);
|
||||||
@@ -117,13 +115,11 @@ void QmlPreviewConnectionManager::createDebugTranslationClient()
|
|||||||
{
|
{
|
||||||
m_qmlDebugTranslationClient = new QmlDebugTranslationClient(connection());
|
m_qmlDebugTranslationClient = new QmlDebugTranslationClient(connection());
|
||||||
connect(this, &QmlPreviewConnectionManager::language,
|
connect(this, &QmlPreviewConnectionManager::language,
|
||||||
m_qmlDebugTranslationClient.data(), [this](const QString &locale) {
|
m_qmlDebugTranslationClient, [this](const QString &locale) {
|
||||||
|
m_lastUsedLanguage = locale;
|
||||||
if (m_lastLoadedUrl.isEmpty()) {
|
// findValidI18nDirectoryAsUrl does not work if we didn't load any file
|
||||||
// findValidI18nDirectoryAsUrl does not work if we didn't load any file
|
// service expects a context URL.
|
||||||
m_initLocale = locale;
|
if (!m_lastLoadedUrl.isEmpty()) {
|
||||||
} else {
|
|
||||||
// service expects a context URL.
|
|
||||||
// Search the parent directories of the last loaded URL for i18n files.
|
// Search the parent directories of the last loaded URL for i18n files.
|
||||||
m_qmlDebugTranslationClient->changeLanguage(findValidI18nDirectoryAsUrl(locale), locale);
|
m_qmlDebugTranslationClient->changeLanguage(findValidI18nDirectoryAsUrl(locale), locale);
|
||||||
}
|
}
|
||||||
@@ -159,10 +155,9 @@ void QmlPreviewConnectionManager::createPreviewClient()
|
|||||||
|
|
||||||
m_lastLoadedUrl = m_targetFileFinder.findUrl(filename);
|
m_lastLoadedUrl = m_targetFileFinder.findUrl(filename);
|
||||||
m_qmlPreviewClient->loadUrl(m_lastLoadedUrl);
|
m_qmlPreviewClient->loadUrl(m_lastLoadedUrl);
|
||||||
if (!m_initLocale.isEmpty()) {
|
// emit language after a file was loaded and do it every time,
|
||||||
emit language(m_initLocale);
|
// because this also triggers the check for missing translations
|
||||||
m_initLocale.clear();
|
emit language(m_lastUsedLanguage);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(this, &QmlPreviewConnectionManager::rerun,
|
connect(this, &QmlPreviewConnectionManager::rerun,
|
||||||
@@ -171,19 +166,6 @@ void QmlPreviewConnectionManager::createPreviewClient()
|
|||||||
connect(this, &QmlPreviewConnectionManager::zoom,
|
connect(this, &QmlPreviewConnectionManager::zoom,
|
||||||
m_qmlPreviewClient.data(), &QmlPreviewClient::zoom);
|
m_qmlPreviewClient.data(), &QmlPreviewClient::zoom);
|
||||||
|
|
||||||
connect(this, &QmlPreviewConnectionManager::language,
|
|
||||||
m_qmlPreviewClient.data(), [this](const QString &locale) {
|
|
||||||
|
|
||||||
if (m_lastLoadedUrl.isEmpty()) {
|
|
||||||
// findValidI18nDirectoryAsUrl does not work if we didn't load any file
|
|
||||||
m_initLocale = locale;
|
|
||||||
} else {
|
|
||||||
// service expects a context URL.
|
|
||||||
// Search the parent directories of the last loaded URL for i18n files.
|
|
||||||
m_qmlPreviewClient->language(findValidI18nDirectoryAsUrl(locale), locale);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(m_qmlPreviewClient.data(), &QmlPreviewClient::pathRequested,
|
connect(m_qmlPreviewClient.data(), &QmlPreviewClient::pathRequested,
|
||||||
this, [this](const QString &path) {
|
this, [this](const QString &path) {
|
||||||
const bool found = m_projectFileFinder.findFileOrDirectory(
|
const bool found = m_projectFileFinder.findFileOrDirectory(
|
||||||
|
@@ -76,10 +76,10 @@ private:
|
|||||||
QPointer<QmlDebugTranslationClient> m_qmlDebugTranslationClient;
|
QPointer<QmlDebugTranslationClient> m_qmlDebugTranslationClient;
|
||||||
Utils::FileSystemWatcher m_fileSystemWatcher;
|
Utils::FileSystemWatcher m_fileSystemWatcher;
|
||||||
QUrl m_lastLoadedUrl;
|
QUrl m_lastLoadedUrl;
|
||||||
|
QString m_lastUsedLanguage;
|
||||||
QmlPreviewFileLoader m_fileLoader = nullptr;
|
QmlPreviewFileLoader m_fileLoader = nullptr;
|
||||||
QmlPreviewFileClassifier m_fileClassifier = nullptr;
|
QmlPreviewFileClassifier m_fileClassifier = nullptr;
|
||||||
QmlPreviewFpsHandler m_fpsHandler = nullptr;
|
QmlPreviewFpsHandler m_fpsHandler = nullptr;
|
||||||
QString m_initLocale;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -150,8 +150,8 @@ public:
|
|||||||
QmlPreview::QmlPreviewFileClassifier m_fileClassifer = nullptr;
|
QmlPreview::QmlPreviewFileClassifier m_fileClassifer = nullptr;
|
||||||
float m_zoomFactor = -1.0;
|
float m_zoomFactor = -1.0;
|
||||||
QmlPreview::QmlPreviewFpsHandler m_fpsHandler = nullptr;
|
QmlPreview::QmlPreviewFpsHandler m_fpsHandler = nullptr;
|
||||||
QString m_locale;
|
QString m_localeIsoCode;
|
||||||
bool elideWarning = false;
|
bool m_translationElideWarning = false;
|
||||||
QPointer<QmlDebugTranslationWidget> m_qmlDebugTranslationWidget;
|
QPointer<QmlDebugTranslationWidget> m_qmlDebugTranslationWidget;
|
||||||
|
|
||||||
RunWorkerFactory localRunWorkerFactory{
|
RunWorkerFactory localRunWorkerFactory{
|
||||||
@@ -163,8 +163,15 @@ public:
|
|||||||
|
|
||||||
RunWorkerFactory runWorkerFactory{
|
RunWorkerFactory runWorkerFactory{
|
||||||
[this](RunControl *runControl) {
|
[this](RunControl *runControl) {
|
||||||
QmlPreviewRunner *runner = new QmlPreviewRunner(runControl, m_fileLoader, m_fileClassifer,
|
QmlPreviewRunner *runner = new QmlPreviewRunner(QmlPreviewRunnerSetting{
|
||||||
m_fpsHandler, m_zoomFactor);
|
runControl,
|
||||||
|
m_fileLoader,
|
||||||
|
m_fileClassifer,
|
||||||
|
m_fpsHandler,
|
||||||
|
m_zoomFactor,
|
||||||
|
m_localeIsoCode,
|
||||||
|
m_translationElideWarning
|
||||||
|
});
|
||||||
connect(q, &QmlPreviewPlugin::updatePreviews,
|
connect(q, &QmlPreviewPlugin::updatePreviews,
|
||||||
runner, &QmlPreviewRunner::loadFile);
|
runner, &QmlPreviewRunner::loadFile);
|
||||||
connect(q, &QmlPreviewPlugin::rerunPreviews,
|
connect(q, &QmlPreviewPlugin::rerunPreviews,
|
||||||
@@ -173,7 +180,7 @@ public:
|
|||||||
this, &QmlPreviewPluginPrivate::previewCurrentFile);
|
this, &QmlPreviewPluginPrivate::previewCurrentFile);
|
||||||
connect(q, &QmlPreviewPlugin::zoomFactorChanged,
|
connect(q, &QmlPreviewPlugin::zoomFactorChanged,
|
||||||
runner, &QmlPreviewRunner::zoom);
|
runner, &QmlPreviewRunner::zoom);
|
||||||
connect(q, &QmlPreviewPlugin::localeChanged,
|
connect(q, &QmlPreviewPlugin::localeIsoCodeChanged,
|
||||||
runner, &QmlPreviewRunner::language);
|
runner, &QmlPreviewRunner::language);
|
||||||
connect(q, &QmlPreviewPlugin::elideWarningChanged,
|
connect(q, &QmlPreviewPlugin::elideWarningChanged,
|
||||||
runner, &QmlPreviewRunner::changeElideWarning);
|
runner, &QmlPreviewRunner::changeElideWarning);
|
||||||
@@ -207,7 +214,7 @@ QmlPreviewPluginPrivate::QmlPreviewPluginPrivate(QmlPreviewPlugin *parent)
|
|||||||
&QAction::setEnabled);
|
&QAction::setEnabled);
|
||||||
connect(action, &QAction::triggered, this, [this]() {
|
connect(action, &QAction::triggered, this, [this]() {
|
||||||
if (auto multiLanguageAspect = QmlProjectManager::QmlMultiLanguageAspect::current())
|
if (auto multiLanguageAspect = QmlProjectManager::QmlMultiLanguageAspect::current())
|
||||||
m_locale = multiLanguageAspect->currentLocale();
|
m_localeIsoCode = multiLanguageAspect->currentLocale();
|
||||||
|
|
||||||
ProjectExplorerPlugin::runStartupProject(Constants::QML_PREVIEW_RUN_MODE);
|
ProjectExplorerPlugin::runStartupProject(Constants::QML_PREVIEW_RUN_MODE);
|
||||||
});
|
});
|
||||||
@@ -387,30 +394,31 @@ void QmlPreviewPlugin::setFpsHandler(QmlPreviewFpsHandler fpsHandler)
|
|||||||
emit fpsHandlerChanged(d->m_fpsHandler);
|
emit fpsHandlerChanged(d->m_fpsHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QmlPreviewPlugin::locale() const
|
QString QmlPreviewPlugin::localeIsoCode() const
|
||||||
{
|
{
|
||||||
return d->m_locale;
|
return d->m_localeIsoCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlPreviewPlugin::setLocale(const QString &locale)
|
void QmlPreviewPlugin::setLocaleIsoCode(const QString &localeIsoCode)
|
||||||
{
|
{
|
||||||
if (auto multiLanguageAspect = QmlProjectManager::QmlMultiLanguageAspect::current())
|
if (auto multiLanguageAspect = QmlProjectManager::QmlMultiLanguageAspect::current())
|
||||||
multiLanguageAspect->setCurrentLocale(locale);
|
multiLanguageAspect->setCurrentLocale(localeIsoCode);
|
||||||
if (d->m_locale == locale)
|
if (d->m_localeIsoCode == localeIsoCode)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
d->m_locale = locale;
|
d->m_localeIsoCode = localeIsoCode;
|
||||||
emit localeChanged(d->m_locale);
|
emit localeIsoCodeChanged(d->m_localeIsoCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QmlPreviewPlugin::elideWarning() const
|
bool QmlPreviewPlugin::elideWarning() const
|
||||||
{
|
{
|
||||||
return d->elideWarning;
|
return d->m_translationElideWarning;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlPreviewPlugin::changeElideWarning(bool elideWarning)
|
void QmlPreviewPlugin::changeElideWarning(bool elideWarning)
|
||||||
{
|
{
|
||||||
d->elideWarning = elideWarning;
|
d->m_translationElideWarning = elideWarning;
|
||||||
|
emit elideWarningChanged(elideWarning);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlPreviewPlugin::setFileLoader(QmlPreviewFileLoader fileLoader)
|
void QmlPreviewPlugin::setFileLoader(QmlPreviewFileLoader fileLoader)
|
||||||
|
@@ -58,7 +58,7 @@ class QmlPreviewPlugin : public ExtensionSystem::IPlugin
|
|||||||
Q_PROPERTY(QmlPreview::QmlPreviewFpsHandler fpsHandler READ fpsHandler
|
Q_PROPERTY(QmlPreview::QmlPreviewFpsHandler fpsHandler READ fpsHandler
|
||||||
WRITE setFpsHandler NOTIFY fpsHandlerChanged)
|
WRITE setFpsHandler NOTIFY fpsHandlerChanged)
|
||||||
Q_PROPERTY(float zoomFactor READ zoomFactor WRITE setZoomFactor NOTIFY zoomFactorChanged)
|
Q_PROPERTY(float zoomFactor READ zoomFactor WRITE setZoomFactor NOTIFY zoomFactorChanged)
|
||||||
Q_PROPERTY(QString locale READ locale WRITE setLocale NOTIFY localeChanged)
|
Q_PROPERTY(QString localeIsoCode READ localeIsoCode WRITE setLocaleIsoCode NOTIFY localeIsoCodeChanged)
|
||||||
Q_PROPERTY(bool elideWarning READ elideWarning WRITE changeElideWarning NOTIFY elideWarningChanged)
|
Q_PROPERTY(bool elideWarning READ elideWarning WRITE changeElideWarning NOTIFY elideWarningChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -84,8 +84,8 @@ public:
|
|||||||
QmlPreview::QmlPreviewFpsHandler fpsHandler() const;
|
QmlPreview::QmlPreviewFpsHandler fpsHandler() const;
|
||||||
void setFpsHandler(QmlPreview::QmlPreviewFpsHandler fpsHandler);
|
void setFpsHandler(QmlPreview::QmlPreviewFpsHandler fpsHandler);
|
||||||
|
|
||||||
QString locale() const;
|
QString localeIsoCode() const;
|
||||||
void setLocale(const QString &locale);
|
void setLocaleIsoCode(const QString &localeIsoCode);
|
||||||
|
|
||||||
bool elideWarning() const;
|
bool elideWarning() const;
|
||||||
void changeElideWarning(bool elideWarning);
|
void changeElideWarning(bool elideWarning);
|
||||||
@@ -103,7 +103,7 @@ signals:
|
|||||||
void fpsHandlerChanged(QmlPreview::QmlPreviewFpsHandler fpsHandler);
|
void fpsHandlerChanged(QmlPreview::QmlPreviewFpsHandler fpsHandler);
|
||||||
|
|
||||||
void zoomFactorChanged(float zoomFactor);
|
void zoomFactorChanged(float zoomFactor);
|
||||||
void localeChanged(const QString &locale);
|
void localeIsoCodeChanged(const QString &localeIsoCode);
|
||||||
void elideWarningChanged(bool elideWarning);
|
void elideWarningChanged(bool elideWarning);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@@ -45,17 +45,13 @@ namespace QmlPreview {
|
|||||||
|
|
||||||
static const QString QmlServerUrl = "QmlServerUrl";
|
static const QString QmlServerUrl = "QmlServerUrl";
|
||||||
|
|
||||||
QmlPreviewRunner::QmlPreviewRunner(ProjectExplorer::RunControl *runControl,
|
QmlPreviewRunner::QmlPreviewRunner(const QmlPreviewRunnerSetting &settings)
|
||||||
QmlPreviewFileLoader fileLoader,
|
: RunWorker(settings.runControl)
|
||||||
QmlPreviewFileClassifier fileClassifier,
|
|
||||||
QmlPreviewFpsHandler fpsHandler,
|
|
||||||
float initialZoom)
|
|
||||||
: RunWorker(runControl)
|
|
||||||
{
|
{
|
||||||
setId("QmlPreviewRunner");
|
setId("QmlPreviewRunner");
|
||||||
m_connectionManager.setFileLoader(fileLoader);
|
m_connectionManager.setFileLoader(settings.fileLoader);
|
||||||
m_connectionManager.setFileClassifier(fileClassifier);
|
m_connectionManager.setFileClassifier(settings.fileClassifier);
|
||||||
m_connectionManager.setFpsHandler(fpsHandler);
|
m_connectionManager.setFpsHandler(settings.fpsHandler);
|
||||||
|
|
||||||
connect(this, &QmlPreviewRunner::loadFile,
|
connect(this, &QmlPreviewRunner::loadFile,
|
||||||
&m_connectionManager, &Internal::QmlPreviewConnectionManager::loadFile);
|
&m_connectionManager, &Internal::QmlPreviewConnectionManager::loadFile);
|
||||||
@@ -70,24 +66,29 @@ QmlPreviewRunner::QmlPreviewRunner(ProjectExplorer::RunControl *runControl,
|
|||||||
&m_connectionManager, &Internal::QmlPreviewConnectionManager::changeElideWarning);
|
&m_connectionManager, &Internal::QmlPreviewConnectionManager::changeElideWarning);
|
||||||
|
|
||||||
connect(&m_connectionManager, &Internal::QmlPreviewConnectionManager::connectionOpened,
|
connect(&m_connectionManager, &Internal::QmlPreviewConnectionManager::connectionOpened,
|
||||||
this, [this, initialZoom]() {
|
this, [this, settings]() {
|
||||||
if (initialZoom > 0)
|
if (settings.zoom > 0)
|
||||||
emit zoom(initialZoom);
|
emit zoom(settings.zoom);
|
||||||
|
if (!settings.language.isEmpty())
|
||||||
|
emit language(settings.language);
|
||||||
|
if (settings.translationElideWarning)
|
||||||
|
emit changeElideWarning(true);
|
||||||
|
|
||||||
emit ready();
|
emit ready();
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(&m_connectionManager, &Internal::QmlPreviewConnectionManager::restart,
|
connect(&m_connectionManager, &Internal::QmlPreviewConnectionManager::restart,
|
||||||
runControl, [this, runControl]() {
|
runControl(), [this]() {
|
||||||
if (!runControl->isRunning())
|
if (!runControl()->isRunning())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this->connect(runControl, &ProjectExplorer::RunControl::stopped, runControl, [runControl]() {
|
this->connect(runControl(), &ProjectExplorer::RunControl::stopped, [this]() {
|
||||||
ProjectExplorer::ProjectExplorerPlugin::runRunConfiguration(
|
ProjectExplorer::ProjectExplorerPlugin::runRunConfiguration(
|
||||||
runControl->runConfiguration(),
|
runControl()->runConfiguration(),
|
||||||
ProjectExplorer::Constants::QML_PREVIEW_RUN_MODE, true);
|
ProjectExplorer::Constants::QML_PREVIEW_RUN_MODE, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
runControl->initiateStop();
|
runControl()->initiateStop();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -32,14 +32,22 @@
|
|||||||
|
|
||||||
namespace QmlPreview {
|
namespace QmlPreview {
|
||||||
|
|
||||||
|
struct QmlPreviewRunnerSetting {
|
||||||
|
ProjectExplorer::RunControl *runControl = nullptr;
|
||||||
|
QmlPreviewFileLoader fileLoader;
|
||||||
|
QmlPreviewFileClassifier fileClassifier;
|
||||||
|
QmlPreviewFpsHandler fpsHandler;
|
||||||
|
float zoom = 1.0;
|
||||||
|
QString language;
|
||||||
|
bool translationElideWarning = false;
|
||||||
|
};
|
||||||
|
|
||||||
class QmlPreviewRunner : public ProjectExplorer::RunWorker
|
class QmlPreviewRunner : public ProjectExplorer::RunWorker
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QmlPreviewRunner(ProjectExplorer::RunControl *runControl, QmlPreviewFileLoader fileLoader,
|
QmlPreviewRunner(const QmlPreviewRunnerSetting &settings);
|
||||||
QmlPreviewFileClassifier fileClassifier, QmlPreviewFpsHandler fpsHandler,
|
|
||||||
float initialZoom);
|
|
||||||
|
|
||||||
void setServerUrl(const QUrl &serverUrl);
|
void setServerUrl(const QUrl &serverUrl);
|
||||||
QUrl serverUrl() const;
|
QUrl serverUrl() const;
|
||||||
|
@@ -91,24 +91,6 @@ void QmlPreviewClientTest::testZoom()
|
|||||||
QVERIFY(packet.atEnd());
|
QVERIFY(packet.atEnd());
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlPreviewClientTest::testLanguate()
|
|
||||||
{
|
|
||||||
TestableQmlPreviewClient client;
|
|
||||||
QUrl url("file:///some/file.qml");
|
|
||||||
QString locale("qt_QT");
|
|
||||||
client.language(url, locale);
|
|
||||||
QCOMPARE(client.messages.count(), 1);
|
|
||||||
QmlDebug::QPacket packet(client.dataStreamVersion(), client.messages.takeFirst());
|
|
||||||
qint8 command;
|
|
||||||
QUrl resultUrl;
|
|
||||||
QString resultLocale;
|
|
||||||
packet >> command >> resultUrl >> resultLocale;
|
|
||||||
QCOMPARE(static_cast<QmlPreviewClient::Command>(command), QmlPreviewClient::Language);
|
|
||||||
QCOMPARE(resultUrl, url);
|
|
||||||
QCOMPARE(resultLocale, locale);
|
|
||||||
QVERIFY(packet.atEnd());
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlPreviewClientTest::testMessageReceived()
|
void QmlPreviewClientTest::testMessageReceived()
|
||||||
{
|
{
|
||||||
TestableQmlPreviewClient client;
|
TestableQmlPreviewClient client;
|
||||||
|
@@ -36,7 +36,6 @@ private slots:
|
|||||||
void testLoadFile();
|
void testLoadFile();
|
||||||
void testAnnounceFile();
|
void testAnnounceFile();
|
||||||
void testZoom();
|
void testZoom();
|
||||||
void testLanguate();
|
|
||||||
void testMessageReceived();
|
void testMessageReceived();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -78,21 +78,6 @@ void QmlPreviewPluginTest::testZoomFactorProperty()
|
|||||||
QCOMPARE(spy.count(), 2);
|
QCOMPARE(spy.count(), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlPreviewPluginTest::testLocaleProperty()
|
|
||||||
{
|
|
||||||
ExtensionSystem::IPlugin *plugin = getPlugin();
|
|
||||||
QVERIFY(plugin);
|
|
||||||
|
|
||||||
QSignalSpy spy(plugin, SIGNAL(localeChanged(QString)));
|
|
||||||
|
|
||||||
QCOMPARE(plugin->property("locale").toString(), QString());
|
|
||||||
plugin->setProperty("locale", "de_DE");
|
|
||||||
QCOMPARE(plugin->property("locale").toString(), QString("de_DE"));
|
|
||||||
plugin->setProperty("locale", "qt_QT");
|
|
||||||
QCOMPARE(plugin->property("locale").toString(), QString("qt_QT"));
|
|
||||||
QCOMPARE(spy.count(), 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlPreviewPluginTest::testFpsHandlerProperty()
|
void QmlPreviewPluginTest::testFpsHandlerProperty()
|
||||||
{
|
{
|
||||||
ExtensionSystem::IPlugin *plugin = getPlugin();
|
ExtensionSystem::IPlugin *plugin = getPlugin();
|
||||||
|
@@ -42,7 +42,6 @@ public:
|
|||||||
private slots:
|
private slots:
|
||||||
void testFileLoaderProperty();
|
void testFileLoaderProperty();
|
||||||
void testZoomFactorProperty();
|
void testZoomFactorProperty();
|
||||||
void testLocaleProperty();
|
|
||||||
void testFpsHandlerProperty();
|
void testFpsHandlerProperty();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user