Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qqmlpropertytopropertybinding.cpp
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5#include <private/qqmlvmemetaobject_p.h>
6
8
20 QQmlEngine *engine, QObject *sourceObject, int sourcePropertyIndex,
21 QObject *targetObject, int targetPropertyIndex)
22 : QQmlNotifierEndpoint(QQmlPropertyGuard)
23 , m_engine(engine)
24 , m_sourceObject(sourceObject)
25 , m_sourcePropertyIndex(sourcePropertyIndex)
26{
28}
29
34
35void QQmlPropertyToPropertyBinding::setEnabled(bool e, QQmlPropertyData::WriteFlags flags)
36{
37 const bool wasEnabled = enabledFlag();
40 if (e && !wasEnabled)
42}
43
44void QQmlPropertyToPropertyBinding::captureProperty(
45 const QMetaObject *sourceMetaObject, int notifyIndex,
46 bool isSourceBindable, bool isTargetBindable)
47{
48 if (isSourceBindable) {
49 // if the property is a QPropery, and we're binding to a QProperty
50 // the automatic capturing process already takes care of everything
51 if (isTargetBindable)
52 return;
53
54 // We have already captured.
55 if (observer)
56 return;
57
58 observer = std::make_unique<Observer>(this);
59 QUntypedBindable bindable;
60 void *argv[] = { &bindable };
61 sourceMetaObject->metacall(
62 m_sourceObject, QMetaObject::BindableProperty, m_sourcePropertyIndex, argv);
63 bindable.observe(observer.get());
64 return;
65 }
66
67 // We cannot capture non-bindable properties without signals
68 if (notifyIndex == -1)
69 return;
70
71 if (isConnected(m_sourceObject, notifyIndex))
73 else
74 connect(m_sourceObject, notifyIndex, m_engine, true);
75}
76
77void QQmlPropertyToPropertyBinding::update(QQmlPropertyData::WriteFlags flags)
78{
79 if (!enabledFlag())
80 return;
81
82 // Check that the target has not been deleted
85 return;
86
87 const QQmlPropertyData *d = nullptr;
89 getPropertyData(&d, &vtd);
90 Q_ASSERT(d);
91
92 // Check for a binding update loop
93 if (Q_UNLIKELY(updatingFlag())) {
95 QQmlPropertyPrivate::restore(target, *d, &vtd, nullptr));
96 return;
97 }
98
99 setUpdatingFlag(true);
100
101 if (canUseAccessor())
103
104 const QMetaObject *sourceMetaObject = m_sourceObject->metaObject();
105 const QMetaProperty property = sourceMetaObject->property(m_sourcePropertyIndex);
106 if (!property.isConstant()) {
107 captureProperty(sourceMetaObject, QMetaObjectPrivate::signalIndex(property.notifySignal()),
108 property.isBindable(), !vtd.isValid() && d->isBindable());
109 }
110
112 target, *d, vtd, property.read(m_sourceObject), {}, flags);
113
114 setUpdatingFlag(false);
115}
116
118{
119 static_cast<QQmlPropertyToPropertyBinding *>(e)->update();
120}
121
122void QQmlPropertyToPropertyBinding::Observer::trigger(
124{
125 static_cast<Observer *>(observer)->binding->update();
126}
127
\inmodule QtCore
\inmodule QtCore
Definition qobject.h:103
QQmlPropertyIndex targetPropertyIndex() const
static void printBindingLoopError(const QQmlProperty &prop)
QObject * targetObject() const
void setTarget(const QQmlProperty &)
void getPropertyData(const QQmlPropertyData **propertyData, QQmlPropertyData *valueTypeData) const
static bool wasDeleted(const QObject *)
Definition qqmldata_p.h:312
The QQmlEngine class provides an environment for instantiating QML components.
Definition qqmlengine.h:57
void cancelNotify()
Cancel any notifies that are in progress.
void connect(QObject *source, int sourceSignal, QQmlEngine *engine, bool doNotify=true)
static QQmlProperty restore(QObject *, const QQmlPropertyData &, const QQmlPropertyData *, const QQmlRefPointer< QQmlContextData > &)
bool writeValueProperty(const QVariant &, QQmlPropertyData::WriteFlags)
QQmlPropertyToPropertyBinding(QQmlEngine *engine, QObject *sourceObject, int sourcePropertyIndex, QObject *targetObject, int targetPropertyIndex)
void setEnabled(bool e, QQmlPropertyData::WriteFlags flags) final
void update(QQmlPropertyData::WriteFlags flags=QQmlPropertyData::DontRemoveBinding)
\inmodule QtCore
Definition qproperty.h:679
void observe(QPropertyObserver *observer) const
Definition qproperty.h:723
Combined button and popup list for selecting options.
#define Q_UNLIKELY(x)
GLenum target
GLbitfield flags
void QQmlPropertyGuard_callback(QQmlNotifierEndpoint *e, void **)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
const char property[13]
Definition qwizard.cpp:101
QJSEngine engine
[0]
static Q_CORE_EXPORT int signalIndex(const QMetaMethod &m)
\inmodule QtCore