aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlobjectcreator.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2020-03-24 21:03:05 +0100
committerSimon Hausmann <simon.hausmann@qt.io>2020-04-03 07:04:26 +0200
commit36fc392147ea79bb665058ea165c86f6cd6680d7 (patch)
treed95cb07098a6bf41111ea95b96c5a0fc65eba6a4 /src/qml/qml/qqmlobjectcreator.cpp
parente40098c5303e7af4b12c64093b120405c63fdf8d (diff)
Implement support for property observers
Syntactically we call them signal handler expressions :-), now also working when the underlying property doesn't emit an old-style signal but is just a QProperty. Change-Id: I719a3e428f44af0fd48036434aefa682a02f7de1 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlobjectcreator.cpp')
-rw-r--r--src/qml/qml/qqmlobjectcreator.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp
index 564835ff8b..c8564ba294 100644
--- a/src/qml/qml/qqmlobjectcreator.cpp
+++ b/src/qml/qml/qqmlobjectcreator.cpp
@@ -909,15 +909,22 @@ bool QQmlObjectCreator::setPropertyBinding(const QQmlPropertyData *bindingProper
QQmlPropertyPrivate::removeBinding(_bindingTarget, QQmlPropertyIndex(bindingProperty->coreIndex()));
if (binding->type == QV4::CompiledData::Binding::Type_Script || binding->isTranslationBinding()) {
- if (binding->flags & QV4::CompiledData::Binding::IsSignalHandlerExpression) {
+ if (binding->flags & QV4::CompiledData::Binding::IsSignalHandlerExpression
+ || binding->flags & QV4::CompiledData::Binding::IsPropertyObserver) {
QV4::Function *runtimeFunction = compilationUnit->runtimeFunctions[binding->value.compiledScriptIndex];
int signalIndex = _propertyCache->methodIndexToSignalIndex(bindingProperty->coreIndex());
- QQmlBoundSignal *bs = new QQmlBoundSignal(_bindingTarget, signalIndex, _scopeObject, engine);
QQmlBoundSignalExpression *expr = new QQmlBoundSignalExpression(
_bindingTarget, signalIndex, context,
_scopeObject, runtimeFunction, currentQmlContext());
- bs->takeExpression(expr);
+ if (bindingProperty->isQProperty()) {
+ auto &observer = QQmlData::get(_scopeObject)->propertyObservers.emplace_back(expr);
+ void *argv[] = { &observer };
+ _bindingTarget->qt_metacall(QMetaObject::RegisterQPropertyObserver, bindingProperty->coreIndex(), argv);
+ } else {
+ QQmlBoundSignal *bs = new QQmlBoundSignal(_bindingTarget, signalIndex, _scopeObject, engine);
+ bs->takeExpression(expr);
+ }
} else if (bindingProperty->isQProperty()) {
QUntypedPropertyBinding qmlBinding;
if (binding->isTranslationBinding()) {