29QQmlAnyBinding QQmlPropertyToPropertyBinding::create(
30 QQmlEngine *engine,
const QQmlProperty &source,
const QQmlProperty &target)
32 QQmlAnyBinding result;
33 if (target.isBindable() && !QQmlPropertyPrivate::get(target)->isValueType()) {
34 QPropertyBindingPrivate *binding =
nullptr;
35 if (source.isBindable())
36 binding =
new QQmlBindableToBindablePropertyBinding(engine, source, target);
38 binding =
new QQmlUnbindableToBindablePropertyBinding(engine, source, target);
39 result = QPropertyBindingPrivate::makeUntyped(binding);
43 if (source.isBindable()) {
44 result =
new QQmlBindableToUnbindablePropertyBinding(engine, source, target);
48 result =
new QQmlUnbindableToUnbindablePropertyBinding(engine, source, target);
88 QObject *target = targetObject();
89 if (QQmlData::wasDeleted(target))
92 const QQmlPropertyData *d =
nullptr;
94 getPropertyData(&d, &vtd);
98 if (Q_UNLIKELY(updatingFlag()))
101 setUpdatingFlag(
true);
103 if (canUseAccessor())
104 flags.setFlag(QQmlPropertyData::BypassInterceptor);
106 QVariant value = m_binding.readSourceValue(
107 [&](
const QMetaObject *sourceMetaObject,
const QMetaProperty &property) {
108 captureProperty(sourceMetaObject, property);
111 QV4::ExecutionEngine *v4 = m_binding.engine->handle();
114 const QMetaType targetMetaType = vtd.isValid() ? vtd.propType() : d->propType();
115 const QMetaType valueMetaType = value.metaType();
117 if (valueMetaType != targetMetaType && targetMetaType != QMetaType::fromType<QVariant>()) {
120 QVariant coerced(targetMetaType);
121 QV4::Scope scope(v4);
122 QV4::ScopedValue jsValue(
123 scope, value.isValid()
124 ? v4->metaTypeToJS(valueMetaType, value.constData())
125 : QV4::Encode::undefined());
128 if (QV4::ExecutionEngine::metaTypeFromJS(jsValue, targetMetaType, coerced.data()))
129 value = std::move(coerced);
132 QQmlPropertyPrivate::writeValueProperty(target, *d, vtd, value, {}, flags);
133 setUpdatingFlag(
false);
165 const QMetaObject *sourceMetaObject,
const QMetaProperty &sourceProperty)
167 Q_UNUSED(sourceProperty);
173 QUntypedBindable bindable;
174 void *argv[] = { &bindable };
175 sourceMetaObject->metacall(
176 m_binding.sourceObject, QMetaObject::BindableProperty,
177 m_binding.sourcePropertyIndex.coreIndex(), argv);
178 bindable.observe(
this);
179 m_isObserving =
true;
194 QQmlEngine *engine,
const QQmlProperty &source,
const QQmlProperty &target,
195 const QtPrivate::BindingFunctionVTable *vtable)
200 errorCallBack = [](QPropertyBindingPrivate *that) {
201 auto self =
static_cast<QQmlPropertyToBindablePropertyBinding *>(that);
202 if (self->m_binding.engine) {
203 const auto error = self->bindingError();
204 if (error.type() == QPropertyBindingError::BindingLoop) {
205 qmlWarning(self->m_binding.sourceObject)
206 << QStringLiteral(
"Binding loop detected for property bound to ")
207 << self->propertyDataPtr;