aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEgor Nemtsev <enemtsev@luxoft.com>2019-02-08 12:53:38 +0300
committerBramastyo Harimukti Santoso <bramastyo.harimukti.santoso@pelagicore.com>2019-02-11 09:06:15 +0000
commit7e8ec0575afd2cc046d1ba7a2e7033c135b932b5 (patch)
tree580b8464de89e188eee7caf55e80f10b69348363
parentf9262c38c4b06b24f138d699b667fe73668738aa (diff)
[utils] fix Config Translation binding loop warning on initialization
Change-Id: I6faec08704d82dcaeba8f69125a5b01a53c74952 Reviewed-by: Bramastyo Harimukti Santoso <bramastyo.harimukti.santoso@pelagicore.com>
-rw-r--r--imports_shared/shared/utils/Config.qml6
-rw-r--r--plugins/translation/translation.cpp12
-rw-r--r--plugins/translation/translation.h7
3 files changed, 18 insertions, 7 deletions
diff --git a/imports_shared/shared/utils/Config.qml b/imports_shared/shared/utils/Config.qml
index 98c69291..dde165cb 100644
--- a/imports_shared/shared/utils/Config.qml
+++ b/imports_shared/shared/utils/Config.qml
@@ -61,9 +61,11 @@ QtObject {
property alias languageLocale: translation.languageLocale
readonly property var translation: Translation {
id: translation
+ path: root.assetPath + "translations/"
Component.onCompleted: {
- translation.setPath(root.assetPath + "translations/");
- languageLocale = Qt.locale().name;
+ Qt.callLater( function() { //not to have binding loop warning "QML ApplicationModel: Binding loop detected for property "localeCode"
+ languageLocale = Qt.locale().name;
+ })
}
}
}
diff --git a/plugins/translation/translation.cpp b/plugins/translation/translation.cpp
index 6b5933ca..13fb4fc2 100644
--- a/plugins/translation/translation.cpp
+++ b/plugins/translation/translation.cpp
@@ -44,16 +44,22 @@ Translation::Translation(QObject *parent)
void Translation::setPath(const QUrl &languageFilePath)
{
- m_languageFilePath = languageFilePath.toLocalFile();
+ m_languageFilePath = languageFilePath;
// find the available translations
m_availableTranslations.clear();
- QDirIterator it(m_languageFilePath, {QStringLiteral("*.qm")}, QDir::Files|QDir::Readable);
+ QDirIterator it(m_languageFilePath.toLocalFile(), {QStringLiteral("*.qm")}, QDir::Files|QDir::Readable);
while (it.hasNext()) {
it.next();
m_availableTranslations.append(it.fileInfo().baseName());
}
emit availableTranslationsChanged();
+ emit pathChanged();
+}
+
+QUrl Translation::path()
+{
+ return m_languageFilePath;
}
void Translation::setLanguageLocale(const QString &languageLocale)
@@ -84,7 +90,7 @@ QString Translation::formatTime(const QDateTime &dt, bool twentyFourH) const
bool Translation::loadTranslationFile(const QString &langLocale)
{
- QString fileToLoad(m_languageFilePath);
+ QString fileToLoad(m_languageFilePath.toLocalFile());
fileToLoad += langLocale + ".qm";
const bool loaded = m_translator.load(fileToLoad);
diff --git a/plugins/translation/translation.h b/plugins/translation/translation.h
index 4691fb3f..9863428e 100644
--- a/plugins/translation/translation.h
+++ b/plugins/translation/translation.h
@@ -43,11 +43,13 @@ class Translation : public QObject
Q_PROPERTY(QString languageLocale READ languageLocale WRITE setLanguageLocale NOTIFY languageLocaleChanged)
Q_PROPERTY(QStringList availableTranslations READ availableTranslations NOTIFY availableTranslationsChanged)
+ Q_PROPERTY(QUrl path READ path WRITE setPath NOTIFY pathChanged)
public:
explicit Translation(QObject *parent = nullptr);
- Q_INVOKABLE void setPath(const QUrl &languageFilePath);
+ void setPath(const QUrl &languageFilePath);
+ QUrl path();
void setLanguageLocale(const QString &languageLocale);
QString languageLocale() const;
@@ -59,12 +61,13 @@ public:
signals:
void languageLocaleChanged();
void availableTranslationsChanged();
+ void pathChanged();
private:
bool loadTranslationFile(const QString &langLocale);
QString m_languageLocale;
- QString m_languageFilePath;
+ QUrl m_languageFilePath;
QTranslator m_translator;