aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmljavascriptexpression.cpp
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2021-10-07 14:25:50 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2021-10-08 19:47:39 +0200
commitd4039298e710b6b79c018589bcc2145e22e1d5aa (patch)
treea00a0075710be50e1f3f9740324ad0f9a70e24b0 /src/qml/qml/qqmljavascriptexpression.cpp
parent6bed610c2f74d0a4694d230dbb2516fe3cf7e49a (diff)
QQmlEngine: Fine grained translation binding tracking
This commit changes translation bindings in such a way that they always depend on the a newly introduced translationLanguage property of the QML engine. Moreover, captureTranslationBinding is changed in the same way, hence any binding containing a call to a translation function like qsTr will also be refreshed. After those changes, QQmlEngine::retranslate can be implemented as a notify on translationLanguage. Finally, QQmlTranslationPropertyBinding is also changed to depend on translationLanguage instead of uiLanguage to ensure consistency between the various binding types. Note that we do not use the existing uiLanguage property of QJSEngine. If we were to do this, changing uiLanguage would already trigger the binding reevaluation, which is a behavior change. In case someone is manually connecting uiLanguageChanged to QQmlEngine::retranslate, this would cause a double evaluation of translation bindings. In a future change, we can however introduce a new enableAutoTranslationUpdate method, which would cause binding evaluation as soon as uiLanguage is changed. Special care is taken for ListModel/ListElement, which does not store a proper translation binding, but instead operates on QV4::CompiledData::Binding. For now, we simply refresh the complete ListModel in case it contains a translation binding. It should be possible to optimize this further in a future change. Note that only "static" ListElement properties can contain translations: The dynamic insertion API makes it impossible to insert a translation, as it would already be resolved to a string when insert is called. [ChangeLog][QQmlEngine] QQmlEngine::retranslate no longer refreshes all bindings, but only translation bindings. Pick-to: 6.2 Fixes: QTBUG-96192 Change-Id: I54d213fd46b6914e8f686843b49e155909117218 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/qml/qml/qqmljavascriptexpression.cpp')
-rw-r--r--src/qml/qml/qqmljavascriptexpression.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/qml/qml/qqmljavascriptexpression.cpp b/src/qml/qml/qqmljavascriptexpression.cpp
index b8b34d2071..854a22d8ba 100644
--- a/src/qml/qml/qqmljavascriptexpression.cpp
+++ b/src/qml/qml/qqmljavascriptexpression.cpp
@@ -221,9 +221,6 @@ public:
while (QQmlJavaScriptExpressionGuard *g = capture.guards.takeFirst())
g->Delete();
- if (!watcher.wasDeleted())
- capture.expression->setTranslationsCaptured(capture.translationCaptured);
-
ep->propertyCapture = lastPropertyCapture;
}
@@ -389,6 +386,21 @@ void QQmlPropertyCapture::captureProperty(
captureNonBindableProperty(o, propertyData->notifyIndex(), propertyData->coreIndex(), doNotify);
}
+void QQmlPropertyCapture::captureTranslation()
+{
+ // use a unique invalid index to avoid needlessly querying the metaobject for
+ // the correct index of of the translationLanguage property
+ int const invalidIndex = -2;
+ for (auto trigger = expression->qpropertyChangeTriggers; trigger;
+ trigger = trigger->next) {
+ if (trigger->target == engine && trigger->propertyIndex == invalidIndex)
+ return; // already installed
+ }
+ auto trigger = expression->allocatePropertyChangeTrigger(engine, invalidIndex);
+
+ trigger->setSource(QQmlEnginePrivate::get(engine)->translationLanguage);
+}
+
void QQmlPropertyCapture::captureBindableProperty(
QObject *o, const QMetaObject *metaObjectForBindable, int c)
{