aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2020-03-24 11:21:25 +0100
committerSimon Hausmann <simon.hausmann@qt.io>2020-04-02 22:23:04 +0200
commite40098c5303e7af4b12c64093b120405c63fdf8d (patch)
tree9636894ed820567731f9b4dd41870392ce052a70 /src
parent63bf6ac4c483cc64b48c410c6e1afb404f2bcbd1 (diff)
Add support for translation bindings on QProperty based properties
Change-Id: I439653123cdc96df97a1801664655c9d28a8b9b5 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/qml/jsapi/qjsengine_p.h3
-rw-r--r--src/qml/qml/qqmlapplicationengine.cpp2
-rw-r--r--src/qml/qml/qqmlobjectcreator.cpp10
-rw-r--r--src/qml/qml/qqmlpropertybinding.cpp24
-rw-r--r--src/qml/qml/qqmlpropertybinding_p.h12
5 files changed, 43 insertions, 8 deletions
diff --git a/src/qml/jsapi/qjsengine_p.h b/src/qml/jsapi/qjsengine_p.h
index 37376a1485..0aff6595b6 100644
--- a/src/qml/jsapi/qjsengine_p.h
+++ b/src/qml/jsapi/qjsengine_p.h
@@ -53,6 +53,7 @@
#include <QtCore/private/qobject_p.h>
#include <QtCore/qmutex.h>
+#include <QtCore/qproperty.h>
#include "qjsengine.h"
#include "private/qtqmlglobal_p.h"
#include <private/qqmlmetatype_p.h>
@@ -107,7 +108,7 @@ public:
// Shared by QQmlEngine
mutable QRecursiveMutex mutex;
- QString uiLanguage;
+ QProperty<QString> uiLanguage;
// These methods may be called from the QML loader thread
inline QQmlPropertyCache *cache(QObject *obj, QTypeRevision version = QTypeRevision());
diff --git a/src/qml/qml/qqmlapplicationengine.cpp b/src/qml/qml/qqmlapplicationengine.cpp
index a633d3f58b..6fe8dc5227 100644
--- a/src/qml/qml/qqmlapplicationengine.cpp
+++ b/src/qml/qml/qqmlapplicationengine.cpp
@@ -95,7 +95,7 @@ void QQmlApplicationEnginePrivate::_q_loadTranslations()
Q_Q(QQmlApplicationEngine);
QScopedPointer<QTranslator> translator(new QTranslator);
- if (!uiLanguage.isEmpty()) {
+ if (!uiLanguage.value().isEmpty()) {
QLocale locale(uiLanguage);
if (translator->load(locale, QLatin1String("qml"), QLatin1String("_"), translationsDirectory, QLatin1String(".qm"))) {
if (activeTranslator)
diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp
index 2ee2969d43..564835ff8b 100644
--- a/src/qml/qml/qqmlobjectcreator.cpp
+++ b/src/qml/qml/qqmlobjectcreator.cpp
@@ -919,9 +919,13 @@ bool QQmlObjectCreator::setPropertyBinding(const QQmlPropertyData *bindingProper
bs->takeExpression(expr);
} else if (bindingProperty->isQProperty()) {
- // ### TODO: support binding->isTranslationBinding()
- QV4::Function *runtimeFunction = compilationUnit->runtimeFunctions[binding->value.compiledScriptIndex];
- auto qmlBinding = QQmlPropertyBinding::create(bindingProperty, runtimeFunction, _scopeObject, context, currentQmlContext());
+ QUntypedPropertyBinding qmlBinding;
+ if (binding->isTranslationBinding()) {
+ qmlBinding = QQmlTranslationPropertyBinding::create(bindingProperty, compilationUnit, binding);
+ } else {
+ QV4::Function *runtimeFunction = compilationUnit->runtimeFunctions[binding->value.compiledScriptIndex];
+ qmlBinding = QQmlPropertyBinding::create(bindingProperty, runtimeFunction, _scopeObject, context, currentQmlContext());
+ }
void *argv[] = { &qmlBinding };
_bindingTarget->qt_metacall(QMetaObject::SetQPropertyBinding, bindingProperty->coreIndex(), argv);
} else {
diff --git a/src/qml/qml/qqmlpropertybinding.cpp b/src/qml/qml/qqmlpropertybinding.cpp
index ca64cf412a..9fffafa649 100644
--- a/src/qml/qml/qqmlpropertybinding.cpp
+++ b/src/qml/qml/qqmlpropertybinding.cpp
@@ -57,7 +57,7 @@ QUntypedPropertyBinding QQmlPropertyBinding::create(const QQmlPropertyData *pd,
void QQmlPropertyBinding::expressionChanged()
{
- setDirty(true);
+ markDirtyAndNotifyObservers();
}
QQmlPropertyBinding::QQmlPropertyBinding(const QMetaType &mt)
@@ -98,4 +98,26 @@ QUntypedPropertyBinding::BindingEvaluationResult QQmlPropertyBinding::evaluateAn
return true;
}
+QUntypedPropertyBinding QQmlTranslationPropertyBinding::create(const QQmlPropertyData *pd, const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit, const QV4::CompiledData::Binding *binding)
+{
+ auto translationBinding = [compilationUnit, binding](const QMetaType &metaType, void *dataPtr) {
+ // Create a dependency to the uiLanguage
+ QJSEnginePrivate::get(compilationUnit->engine)->uiLanguage.value();
+
+ QVariant resultVariant(compilationUnit->bindingValueAsString(binding));
+ if (metaType.id() != QMetaType::QString)
+ resultVariant.convert(metaType.id());
+
+ int compareResult = 0;
+ if (QMetaType::compare(dataPtr, resultVariant.constData(), metaType.id(), &compareResult)
+ && compareResult == 0)
+ return false;
+ QMetaType::destruct(metaType.id(), dataPtr);
+ QMetaType::construct(metaType.id(), dataPtr, resultVariant.constData());
+ return true;
+ };
+
+ return QUntypedPropertyBinding(QMetaType(pd->propType()), translationBinding, QPropertyBindingSourceLocation());
+}
+
QT_END_NAMESPACE
diff --git a/src/qml/qml/qqmlpropertybinding_p.h b/src/qml/qml/qqmlpropertybinding_p.h
index 3bd6772413..5097f40e6f 100644
--- a/src/qml/qml/qqmlpropertybinding_p.h
+++ b/src/qml/qml/qqmlpropertybinding_p.h
@@ -61,8 +61,8 @@
QT_BEGIN_NAMESPACE
-class QQmlPropertyBinding final : public QQmlJavaScriptExpression,
- public QPropertyBindingPrivate
+class QQmlPropertyBinding : public QQmlJavaScriptExpression,
+ public QPropertyBindingPrivate
{
public:
static QUntypedPropertyBinding create(const QQmlPropertyData *pd, QV4::Function *function,
@@ -78,6 +78,14 @@ private:
void *dataPtr);
};
+class QQmlTranslationPropertyBinding
+{
+public:
+ static QUntypedPropertyBinding create(const QQmlPropertyData *pd,
+ const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit,
+ const QV4::CompiledData::Binding *binding);
+};
+
QT_END_NAMESPACE
#endif // QQMLPROPERTYBINDING_P_H