aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlpropertybinding.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2020-04-15 09:17:02 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2020-04-22 09:54:02 +0200
commitca1098ec1ef83589a78178eee3d28faa7d067017 (patch)
treebb541620259b76e39f9d2c3fa5cfaacb86d8bb5c /src/qml/qml/qqmlpropertybinding.cpp
parent28a31148ca02dbb530fd92dfafbcf71c64af4b70 (diff)
Add support for binding ahead-of-time compiled bindings to QProperties
When the ahead-of-time built binding returns the same type as the QProperty, then we can connect them directly with a small shim and pass through the context and scope objects. Change-Id: I9cb49d1fa35490a4ccb06965397674d5534c067d Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlpropertybinding.cpp')
-rw-r--r--src/qml/qml/qqmlpropertybinding.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/qml/qml/qqmlpropertybinding.cpp b/src/qml/qml/qqmlpropertybinding.cpp
index 9fffafa649..e005635fad 100644
--- a/src/qml/qml/qqmlpropertybinding.cpp
+++ b/src/qml/qml/qqmlpropertybinding.cpp
@@ -47,6 +47,21 @@ QUntypedPropertyBinding QQmlPropertyBinding::create(const QQmlPropertyData *pd,
QObject *obj, const QQmlRefPointer<QQmlContextData> &ctxt,
QV4::ExecutionContext *scope)
{
+ if (auto aotFunction = function->aotFunction; aotFunction && aotFunction->returnType.id() == pd->propType()) {
+ return QUntypedPropertyBinding(aotFunction->returnType,
+ [
+ aotFunction,
+ unit = QQmlRefPointer<QV4::ExecutableCompilationUnit>(function->executableCompilationUnit()),
+ scopeObject = QPointer<QObject>(obj),
+ context = ctxt
+ ](const QMetaType &, void *dataPtr) -> QUntypedPropertyBinding::BindingEvaluationResult {
+ Q_UNUSED(unit); // to keep refcount
+ aotFunction->functionPtr(context->asQQmlContext(), scopeObject.data(), dataPtr);
+ return QPropertyBindingError::NoError;
+ },
+ QPropertyBindingSourceLocation());
+ }
+
auto binding = new QQmlPropertyBinding(QMetaType(pd->propType()));
binding->setNotifyOnValueChanged(true);
binding->setContext(ctxt);