5#ifndef QQMLANYBINDINGPTR_P_H
6#define QQMLANYBINDINGPTR_P_H
19#include <qqmlproperty.h>
20#include <private/qqmlpropertybinding_p.h>
21#include <private/qqmlbinding_p.h>
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
52
53
54
55
56
59 if (prop.isBindable()) {
60 QUntypedBindable bindable = prop.property().bindable(prop.object());
61 binding = bindable.binding();
63 binding = QQmlPropertyPrivate::binding(prop);
69
70
71
72
77 binding = std::forward<
decltype(result)>(result);
82 const auto coreIndex = index.coreIndex();
85 if (index.hasValueTypeIndex())
86 return result(QQmlPropertyPrivate::binding(object, index));
88 if (QQmlPropertyCache::ConstPtr propertyCache = QQmlData::ensurePropertyCache(object)) {
89 const QQmlPropertyData *property = propertyCache->property(coreIndex);
90 return (property->acceptsQBinding())
91 ? result(property->propertyBindable(object).binding())
92 : result(QQmlPropertyPrivate::binding(object, index));
95 const QMetaObject *metaObject = object->metaObject();
96 const QMetaProperty metaProp = metaObject->property(coreIndex);
97 return metaProp.isBindable()
98 ? result(metaProp.bindable(object).binding())
99 : result(QQmlPropertyPrivate::binding(object, index));
103
104
105
106
110 if (prop.isBindable()) {
111 QUntypedBindable bindable = prop.property().bindable(prop.object());
112 binding = bindable.takeBinding();
114 auto qmlBinding = QQmlPropertyPrivate::binding(prop);
116 binding = qmlBinding;
117 qmlBinding->setEnabled(
false, QQmlPropertyData::DontRemoveBinding | QQmlPropertyData::BypassInterceptor);
118 qmlBinding->removeFromObject();
125
126
127
128
129
130
132 QObject *obj,
const QQmlRefPointer<QQmlContextData> &ctxt,
133 QV4::ExecutionContext *scope)
136 auto propPriv = QQmlPropertyPrivate::get(prop);
137 if (prop.isBindable()) {
138 auto index = QQmlPropertyIndex(propPriv->core.coreIndex(), -1);
139 binding = QQmlPropertyBinding::create(&propPriv->core,
141 scope, prop.object(), index);
143 auto qmlBinding = QQmlBinding::create(&propPriv->core, function, obj, ctxt, scope);
144 qmlBinding->setTarget(prop);
145 binding = qmlBinding;
151
152
153
154
155
156
158 QObject *obj, QQmlContext *ctxt)
161 auto propPriv = QQmlPropertyPrivate::get(prop);
162 if (prop.isBindable()) {
163 auto index = QQmlPropertyIndex(propPriv->core.coreIndex(), -1);
164 binding = QQmlPropertyBinding::createFromScriptString(&propPriv->core, script, obj, ctxt, prop.object(), index);
166 auto qmlBinding = QQmlBinding::create(&propPriv->core, script, obj, ctxt);
167 qmlBinding->setTarget(prop);
168 binding = qmlBinding;
175
176
177
180 if (prop.isBindable())
181 prop.property().bindable(prop.object()).takeBinding();
183 QQmlPropertyPrivate::removeBinding(prop, QQmlPropertyPrivate::OverrideSticky);
187
188
189
190
191
192
193 static QQmlAnyBinding createFromCodeString(
const QQmlProperty &prop,
const QString& code, QObject *obj,
const QQmlRefPointer<QQmlContextData> &ctxt,
const QString &url, quint16 lineNumber) {
195 auto propPriv = QQmlPropertyPrivate::get(prop);
196 if (prop.isBindable()) {
197 auto index = QQmlPropertyIndex(propPriv->core.coreIndex(), -1);
198 binding = QQmlPropertyBinding::createFromCodeString(&propPriv->core,
201 prop.object(), index);
203 auto qmlBinding = QQmlBinding::create(&propPriv->core, code, obj, ctxt, url, lineNumber);
204 qmlBinding->setTarget(prop);
205 binding = qmlBinding;
211
212
213
214
215 static QQmlAnyBinding createTranslationBinding(
const QQmlProperty &prop,
const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit,
const QV4::CompiledData::Binding *translationBinding, QObject *scopeObject=
nullptr, QQmlRefPointer<QQmlContextData> context={})
218 auto propPriv = QQmlPropertyPrivate::get(prop);
219 if (prop.isBindable()) {
220 binding = QQmlTranslationPropertyBinding::create(&propPriv->core, compilationUnit, translationBinding);
222 auto qmlBinding = QQmlBinding::createTranslationBinding(compilationUnit, translationBinding, scopeObject, context);
223 binding = qmlBinding;
224 qmlBinding->setTarget(prop);
230
231
232
233
234
235
236
237
238
246 Q_ASSERT(!d.isNull());
248 auto abstractBinding = asAbstractBinding();
249 Q_ASSERT(abstractBinding->targetObject() == target.object() || QQmlPropertyPrivate::get(target)->core.isAlias());
250 Q_ASSERT(!target.isBindable() || QQmlPropertyPrivate::get(target)->isValueType());
252 QQmlPropertyPrivate::setBinding(abstractBinding, QQmlPropertyPrivate::None, QQmlPropertyData::DontRemoveBinding | QQmlPropertyData::BypassInterceptor);
254 QQmlPropertyPrivate::setBinding(abstractBinding);
256 Q_ASSERT(target.isBindable());
257 QUntypedBindable bindable;
258 void *argv[] = {&bindable};
260 target.object()->qt_metacall(QMetaObject::BindableProperty, target.index(), argv);
262 QMetaObject::metacall(target.object(), QMetaObject::BindableProperty, target.index(), argv);
264 bindable.setBinding(asUntypedPropertyBinding());
269
270
271
272
273
276 auto abstractBinding = asAbstractBinding();
277 if (abstractBinding->kind() != QQmlAbstractBinding::QmlBinding)
279 return static_cast<QQmlBinding *>(abstractBinding)->hasError();
281 return asUntypedPropertyBinding().error().hasError();
290 return d.asT1()->isSticky();
291 return d.asT2()->isSticky();
299 d.asT1()->setSticky(sticky);
301 d.asT2()->setSticky(sticky);
305
306
307
319
320
321
322
327
328
329
330
335
336
337
338
341 if (d.isT1() || d.isNull())
343 auto priv = d.asT2();
344 return QUntypedPropertyBinding {priv};
348
349
350
351
354 if (d.isT2() || d.isNull())
360
361
362
363
369 auto binding =
static_cast<QQmlBinding *>(d.asT1());
370 binding->setEnabledFlag(
true);
373 auto bindingPriv = d.asT2();
374 PendingBindingObserverList bindingObservers;
375 bindingPriv->evaluateRecursive(bindingObservers);
376 bindingPriv->notifyNonRecursive(bindingObservers);
382
383
384
396
397
398
410
411
412
423
424
425
429 auto binding = QPropertyBindingPrivate::get(untypedBinding);
438
439
440
441
445 auto binding = QPropertyBindingPrivate::get(untypedBinding);
446 QPropertyBindingPrivatePtr ptr(binding);
448 d =
static_cast<QPropertyBindingPrivate *>(ptr.take());
485 void clear()
noexcept {
492 }
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)
Combined button and popup list for selecting options.