summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Jenssen <tim.jenssen@qt.io>2020-07-21 13:57:29 +0200
committerTim Jenssen <tim.jenssen@qt.io>2020-07-21 15:38:04 +0000
commitce926844d0a5b64abca2f4fd172f8c84aa9ccd54 (patch)
treee3fcf82840e9792c4fa726f5038d95ca46b93aab
parentb1fc2cdbb41a3dd6222619a495ac98292458135d (diff)
downloadqt-creator-ce926844d0a5b64abca2f4fd172f8c84aa9ccd54.tar.gz
qmlpreview: fix init locale issue
The init language was never found, because the findValidI18nDirectoryAsUrl() uses the m_lastLoadedUrl to find the translation file path. Change-Id: I6e9b62f3d846795d68ddef5e3a4caf3e3d953c7c Reviewed-by: Marco Bubke <marco.bubke@qt.io>
-rw-r--r--src/plugins/qmlpreview/qmlpreviewconnectionmanager.cpp26
-rw-r--r--src/plugins/qmlpreview/qmlpreviewconnectionmanager.h1
-rw-r--r--src/plugins/qmlpreview/qmlpreviewplugin.cpp2
-rw-r--r--src/plugins/qmlpreview/qmlpreviewruncontrol.cpp7
-rw-r--r--src/plugins/qmlpreview/qmlpreviewruncontrol.h2
5 files changed, 25 insertions, 13 deletions
diff --git a/src/plugins/qmlpreview/qmlpreviewconnectionmanager.cpp b/src/plugins/qmlpreview/qmlpreviewconnectionmanager.cpp
index 69a33cfa58..7d16f1a542 100644
--- a/src/plugins/qmlpreview/qmlpreviewconnectionmanager.cpp
+++ b/src/plugins/qmlpreview/qmlpreviewconnectionmanager.cpp
@@ -119,9 +119,14 @@ void QmlPreviewConnectionManager::createDebugTranslationClient()
QObject::connect(this, &QmlPreviewConnectionManager::language,
m_qmlDebugTranslationClient.data(), [this](const QString &locale) {
- // service expects a context URL.
- // Search the parent directories of the last loaded URL for i18n files.
- m_qmlDebugTranslationClient->changeLanguage(findValidI18nDirectoryAsUrl(locale), 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_qmlDebugTranslationClient->changeLanguage(findValidI18nDirectoryAsUrl(locale), locale);
+ }
});
QObject::connect(m_qmlDebugTranslationClient.data(), &QmlDebugTranslationClient::debugServiceUnavailable,
this, []() {
@@ -152,6 +157,10 @@ void QmlPreviewConnectionManager::createPreviewClient()
m_lastLoadedUrl = m_targetFileFinder.findUrl(filename);
m_qmlPreviewClient->loadUrl(m_lastLoadedUrl);
+ if (!m_initLocale.isEmpty()) {
+ emit language(m_initLocale);
+ m_initLocale.clear();
+ }
});
QObject::connect(this, &QmlPreviewConnectionManager::rerun,
@@ -163,9 +172,14 @@ void QmlPreviewConnectionManager::createPreviewClient()
QObject::connect(this, &QmlPreviewConnectionManager::language,
m_qmlPreviewClient.data(), [this](const QString &locale) {
- // service expects a context URL.
- // Search the parent directories of the last loaded URL for i18n files.
- m_qmlPreviewClient->language(findValidI18nDirectoryAsUrl(locale), 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);
+ }
});
QObject::connect(m_qmlPreviewClient.data(), &QmlPreviewClient::pathRequested,
diff --git a/src/plugins/qmlpreview/qmlpreviewconnectionmanager.h b/src/plugins/qmlpreview/qmlpreviewconnectionmanager.h
index 7d87ca79f3..788df212b5 100644
--- a/src/plugins/qmlpreview/qmlpreviewconnectionmanager.h
+++ b/src/plugins/qmlpreview/qmlpreviewconnectionmanager.h
@@ -78,6 +78,7 @@ private:
QmlPreviewFileLoader m_fileLoader = nullptr;
QmlPreviewFileClassifier m_fileClassifier = nullptr;
QmlPreviewFpsHandler m_fpsHandler = nullptr;
+ QString m_initLocale;
};
} // namespace Internal
diff --git a/src/plugins/qmlpreview/qmlpreviewplugin.cpp b/src/plugins/qmlpreview/qmlpreviewplugin.cpp
index f064395592..b578be4ac0 100644
--- a/src/plugins/qmlpreview/qmlpreviewplugin.cpp
+++ b/src/plugins/qmlpreview/qmlpreviewplugin.cpp
@@ -154,7 +154,7 @@ public:
RunWorkerFactory runWorkerFactory{
[this](RunControl *runControl) {
QmlPreviewRunner *runner = new QmlPreviewRunner(runControl, m_fileLoader, m_fileClassifer,
- m_fpsHandler, m_zoomFactor, m_locale);
+ m_fpsHandler, m_zoomFactor);
connect(q, &QmlPreviewPlugin::updatePreviews,
runner, &QmlPreviewRunner::loadFile);
connect(q, &QmlPreviewPlugin::rerunPreviews,
diff --git a/src/plugins/qmlpreview/qmlpreviewruncontrol.cpp b/src/plugins/qmlpreview/qmlpreviewruncontrol.cpp
index c513a580f3..2966cf6e2c 100644
--- a/src/plugins/qmlpreview/qmlpreviewruncontrol.cpp
+++ b/src/plugins/qmlpreview/qmlpreviewruncontrol.cpp
@@ -49,8 +49,7 @@ QmlPreviewRunner::QmlPreviewRunner(ProjectExplorer::RunControl *runControl,
QmlPreviewFileLoader fileLoader,
QmlPreviewFileClassifier fileClassifier,
QmlPreviewFpsHandler fpsHandler,
- float initialZoom,
- const QString &initialLocale)
+ float initialZoom)
: RunWorker(runControl)
{
setId("QmlPreviewRunner");
@@ -68,11 +67,9 @@ QmlPreviewRunner::QmlPreviewRunner(ProjectExplorer::RunControl *runControl,
connect(this, &QmlPreviewRunner::language,
&m_connectionManager, &Internal::QmlPreviewConnectionManager::language);
connect(&m_connectionManager, &Internal::QmlPreviewConnectionManager::connectionOpened,
- this, [this, initialZoom, initialLocale]() {
+ this, [this, initialZoom]() {
if (initialZoom > 0)
emit zoom(initialZoom);
- if (!initialLocale.isEmpty())
- emit language(initialLocale);
emit ready();
});
diff --git a/src/plugins/qmlpreview/qmlpreviewruncontrol.h b/src/plugins/qmlpreview/qmlpreviewruncontrol.h
index 7a25a62c10..7108b8f8f2 100644
--- a/src/plugins/qmlpreview/qmlpreviewruncontrol.h
+++ b/src/plugins/qmlpreview/qmlpreviewruncontrol.h
@@ -39,7 +39,7 @@ class QmlPreviewRunner : public ProjectExplorer::RunWorker
public:
QmlPreviewRunner(ProjectExplorer::RunControl *runControl, QmlPreviewFileLoader fileLoader,
QmlPreviewFileClassifier fileClassifier, QmlPreviewFpsHandler fpsHandler,
- float initialZoom, const QString &initialLocale);
+ float initialZoom);
void setServerUrl(const QUrl &serverUrl);
QUrl serverUrl() const;