4#ifndef QQMLANYBINDINGPTR_P_H
5#define QQMLANYBINDINGPTR_P_H
18#include <qqmlproperty.h>
19#include <private/qqmlpropertybinding_p.h>
20#include <private/qqmlbinding_p.h>
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
51
52
53
54
55
58 if (prop.isBindable()) {
59 QUntypedBindable bindable = prop.property().bindable(prop.object());
60 binding = bindable.binding();
62 binding = QQmlPropertyPrivate::binding(prop);
68
69
70
71
76 binding = std::forward<
decltype(result)>(result);
81 const auto coreIndex = index.coreIndex();
84 if (index.hasValueTypeIndex())
85 return result(QQmlPropertyPrivate::binding(object, index));
87 if (QQmlPropertyCache::ConstPtr propertyCache = QQmlData::ensurePropertyCache(object)) {
88 const QQmlPropertyData *property = propertyCache->property(coreIndex);
89 return (property->acceptsQBinding())
90 ? result(property->propertyBindable(object).binding())
91 : result(QQmlPropertyPrivate::binding(object, index));
94 const QMetaObject *metaObject = object->metaObject();
95 const QMetaProperty metaProp = metaObject->property(coreIndex);
96 return metaProp.isBindable()
97 ? result(metaProp.bindable(object).binding())
98 : result(QQmlPropertyPrivate::binding(object, index));
102
103
104
105
109 if (prop.isBindable()) {
110 QUntypedBindable bindable = prop.property().bindable(prop.object());
111 binding = bindable.takeBinding();
113 auto qmlBinding = QQmlPropertyPrivate::binding(prop);
115 binding = qmlBinding;
116 qmlBinding->setEnabled(
false, QQmlPropertyData::DontRemoveBinding | QQmlPropertyData::BypassInterceptor);
117 qmlBinding->removeFromObject();
124
125
126
127
128
129
131 QObject *obj,
const QQmlRefPointer<QQmlContextData> &ctxt,
132 QV4::ExecutionContext *scope)
135 auto propPriv = QQmlPropertyPrivate::get(prop);
136 if (prop.isBindable()) {
137 auto index = QQmlPropertyIndex(propPriv->core.coreIndex(), -1);
138 binding = QQmlPropertyBinding::create(&propPriv->core,
140 scope, prop.object(), index);
142 auto qmlBinding = QQmlBinding::create(&propPriv->core, function, obj, ctxt, scope);
143 qmlBinding->setTarget(prop);
144 binding = qmlBinding;
150
151
152
153
154
155
157 QObject *obj, QQmlContext *ctxt)
160 auto propPriv = QQmlPropertyPrivate::get(prop);
161 if (prop.isBindable()) {
162 auto index = QQmlPropertyIndex(propPriv->core.coreIndex(), -1);
163 binding = QQmlPropertyBinding::createFromScriptString(&propPriv->core, script, obj, ctxt, prop.object(), index);
165 auto qmlBinding = QQmlBinding::create(&propPriv->core, script, obj, ctxt);
166 qmlBinding->setTarget(prop);
167 binding = qmlBinding;
174
175
176
179 if (prop.isBindable())
180 prop.property().bindable(prop.object()).takeBinding();
182 QQmlPropertyPrivate::removeBinding(prop, QQmlPropertyPrivate::OverrideSticky);
186
187
188
189
190
191
192 static QQmlAnyBinding createFromCodeString(
const QQmlProperty &prop,
const QString& code, QObject *obj,
const QQmlRefPointer<QQmlContextData> &ctxt,
const QString &url, quint16 lineNumber) {
194 auto propPriv = QQmlPropertyPrivate::get(prop);
195 if (prop.isBindable()) {
196 auto index = QQmlPropertyIndex(propPriv->core.coreIndex(), -1);
197 binding = QQmlPropertyBinding::createFromCodeString(&propPriv->core,
200 prop.object(), index);
202 auto qmlBinding = QQmlBinding::create(&propPriv->core, code, obj, ctxt, url, lineNumber);
203 qmlBinding->setTarget(prop);
204 binding = qmlBinding;
210
211
212
213
214 static QQmlAnyBinding createTranslationBinding(
const QQmlProperty &prop,
const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit,
const QV4::CompiledData::Binding *translationBinding, QObject *scopeObject=
nullptr, QQmlRefPointer<QQmlContextData> context={})
217 auto propPriv = QQmlPropertyPrivate::get(prop);
218 if (prop.isBindable()) {
219 binding = QQmlTranslationPropertyBinding::create(&propPriv->core, compilationUnit, translationBinding);
221 auto qmlBinding = QQmlBinding::createTranslationBinding(compilationUnit, translationBinding, scopeObject, context);
222 binding = qmlBinding;
223 qmlBinding->setTarget(prop);
229
230
231
232
233
234
235
236
237
245 Q_ASSERT(!d.isNull());
247 auto abstractBinding = asAbstractBinding();
248 Q_ASSERT(abstractBinding->targetObject() == target.object() || QQmlPropertyPrivate::get(target)->core.isAlias());
249 Q_ASSERT(!target.isBindable() || QQmlPropertyPrivate::get(target)->isValueType());
251 QQmlPropertyPrivate::setBinding(abstractBinding, QQmlPropertyPrivate::None, QQmlPropertyData::DontRemoveBinding | QQmlPropertyData::BypassInterceptor);
253 QQmlPropertyPrivate::setBinding(abstractBinding);
255 Q_ASSERT(target.isBindable());
256 QUntypedBindable bindable;
257 void *argv[] = {&bindable};
259 target.object()->qt_metacall(QMetaObject::BindableProperty, target.index(), argv);
261 QMetaObject::metacall(target.object(), QMetaObject::BindableProperty, target.index(), argv);
263 bindable.setBinding(asUntypedPropertyBinding());
268
269
270
271
272
275 auto abstractBinding = asAbstractBinding();
276 if (abstractBinding->kind() != QQmlAbstractBinding::QmlBinding)
278 return static_cast<QQmlBinding *>(abstractBinding)->hasError();
280 return asUntypedPropertyBinding().error().hasError();
289 return d.asT1()->isSticky();
290 return d.asT2()->isSticky();
298 d.asT1()->setSticky(sticky);
300 d.asT2()->setSticky(sticky);
304
305
306
318
319
320
321
326
327
328
329
334
335
336
337
340 if (d.isT1() || d.isNull())
342 auto priv = d.asT2();
343 return QUntypedPropertyBinding {priv};
347
348
349
350
353 if (d.isT2() || d.isNull())
359
360
361
362
368 auto binding =
static_cast<QQmlBinding *>(d.asT1());
369 binding->setEnabledFlag(
true);
372 auto bindingPriv = d.asT2();
373 PendingBindingObserverList bindingObservers;
374 bindingPriv->evaluateRecursive(bindingObservers);
375 bindingPriv->notifyNonRecursive(bindingObservers);
381
382
383
395
396
397
409
410
411
422
423
424
428 auto binding = QPropertyBindingPrivate::get(untypedBinding);
437
438
439
440
444 auto binding = QPropertyBindingPrivate::get(untypedBinding);
445 QPropertyBindingPrivatePtr ptr(binding);
447 d =
static_cast<QPropertyBindingPrivate *>(ptr.take());
484 void clear()
noexcept {
491 }
else if (
d.
isT2()) {
QQmlAnyBinding is an abstraction over the various bindings in QML.
QUntypedPropertyBinding asUntypedPropertyBinding() const
static QQmlAnyBinding createFromCodeString(const QQmlProperty &prop, const QString &code, QObject *obj, const QQmlRefPointer< QQmlContextData > &ctxt, const QString &url, quint16 lineNumber)
static void removeBindingFrom(QQmlProperty &prop)
static QQmlAnyBinding createFromScriptString(const QQmlProperty &prop, const QQmlScriptString &script, QObject *obj, QQmlContext *ctxt)
void setSticky(bool sticky=true)
bool isUntypedPropertyBinding() const
static QQmlAnyBinding createTranslationBinding(const QQmlProperty &prop, const QQmlRefPointer< QV4::ExecutableCompilationUnit > &compilationUnit, const QV4::CompiledData::Binding *translationBinding, QObject *scopeObject=nullptr, QQmlRefPointer< QQmlContextData > context={})
QQmlAnyBinding & operator=(std::nullptr_t)
Stores a null binding.
static QQmlAnyBinding takeFrom(const QQmlProperty &prop)
Removes the binding from the property prop, and returns it as a QQmlAnyBinding if there was any.
QQmlAbstractBinding * asAbstractBinding() const
static QQmlAnyBinding ofProperty(QObject *object, QQmlPropertyIndex index)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void installOn(const QQmlProperty &target, InterceptorMode mode=IgnoreInterceptors)
QQmlAnyBinding & operator=(QQmlAbstractBinding *binding)
bool isAbstractPropertyBinding() const
QQmlAnyBinding(QQmlAnyBinding &&other) noexcept
static QQmlAnyBinding ofProperty(const QQmlProperty &prop)
QQmlAnyBinding(const QQmlAnyBinding &other) noexcept
QQmlAnyBinding & operator=(QQmlAbstractBinding::Ptr &&binding)
static QQmlAnyBinding createFromFunction(const QQmlProperty &prop, QV4::Function *function, QObject *obj, const QQmlRefPointer< QQmlContextData > &ctxt, QV4::ExecutionContext *scope)
constexpr QQmlAnyBinding() noexcept=default
QQmlAnyBinding(std::nullptr_t)
QQmlAnyBinding & operator=(const QQmlAbstractBinding::Ptr &binding)