29QQmlAnyBinding QQmlPropertyToPropertyBinding::create(
30 QQmlEngine *engine,
const QQmlProperty &source,
const QQmlProperty &target)
32 QQmlAnyBinding result;
33 if (target.isBindable() && !QQmlPropertyPrivate::get(target)->isValueType()) {
34 if (source.isBindable()) {
35 result = QUntypedPropertyBinding(
new QQmlBindableToBindablePropertyBinding(
36 engine, source, target));
40 result = QUntypedPropertyBinding(
new QQmlUnbindableToBindablePropertyBinding(
41 engine, source, target));
45 if (source.isBindable()) {
46 result =
new QQmlBindableToUnbindablePropertyBinding(engine, source, target);
50 result =
new QQmlUnbindableToUnbindablePropertyBinding(engine, source, target);
90 QObject *target = targetObject();
91 if (QQmlData::wasDeleted(target))
94 const QQmlPropertyData *d =
nullptr;
96 getPropertyData(&d, &vtd);
100 if (Q_UNLIKELY(updatingFlag()))
103 setUpdatingFlag(
true);
105 if (canUseAccessor())
106 flags.setFlag(QQmlPropertyData::BypassInterceptor);
108 QVariant value = m_binding.readSourceValue(
109 [&](
const QMetaObject *sourceMetaObject,
const QMetaProperty &property) {
110 captureProperty(sourceMetaObject, property);
113 QV4::ExecutionEngine *v4 = m_binding.engine->handle();
116 const QMetaType targetMetaType = vtd.isValid() ? vtd.propType() : d->propType();
117 const QMetaType valueMetaType = value.metaType();
119 if (valueMetaType != targetMetaType && targetMetaType != QMetaType::fromType<QVariant>()) {
122 QVariant coerced(targetMetaType);
123 QV4::Scope scope(v4);
124 QV4::ScopedValue jsValue(
125 scope, value.isValid()
126 ? v4->metaTypeToJS(valueMetaType, value.constData())
127 : QV4::Encode::undefined());
130 if (QV4::ExecutionEngine::metaTypeFromJS(jsValue, targetMetaType, coerced.data()))
131 value = std::move(coerced);
134 QQmlPropertyPrivate::writeValueProperty(target, *d, vtd, value, {}, flags);
135 setUpdatingFlag(
false);
167 const QMetaObject *sourceMetaObject,
const QMetaProperty &sourceProperty)
169 Q_UNUSED(sourceProperty);
175 QUntypedBindable bindable;
176 void *argv[] = { &bindable };
177 sourceMetaObject->metacall(
178 m_binding.sourceObject, QMetaObject::BindableProperty,
179 m_binding.sourcePropertyIndex.coreIndex(), argv);
180 bindable.observe(
this);
181 m_isObserving =
true;