Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqmlpropertytopropertybinding_p.h
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
4#ifndef QQMLPROPERTYTOPROPERTYBINDINDING_P_H
5#define QQMLPROPERTYTOPROPERTYBINDINDING_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <private/qqmlabstractbinding_p.h>
19#include <private/qqmlengine_p.h>
20#include <private/qqmlnotifier_p.h>
21#include <private/qqmlvaluetype_p.h>
22
23#include <QtCore/qproperty.h>
24
25QT_BEGIN_NAMESPACE
26
27// Different forms of property-to-property binding
28// unbindable -> unbindable: QQmlAbstractBinding + QQmlNotifierEndpoint
29// unbindable -> bindable: QPropertyBindingPrivate + QQmlNotifierEndpoint
30// bindable -> unbindable: QQmlAbstractBinding + QPropertyObserver
31// bindable -> bindable: QPropertyBindingPrivate only
32
33class QQmlPropertyToPropertyBinding
34{
35public:
36 static Q_QML_EXPORT QQmlAnyBinding create(
37 QQmlEngine *engine, const QQmlProperty &source, const QQmlProperty &target);
38
39private:
40 friend class QQmlPropertyToUnbindablePropertyBinding;
41 friend class QQmlUnbindableToUnbindablePropertyBinding;
42 friend class QQmlBindableToUnbindablePropertyBinding;
43 friend class QQmlPropertyToBindablePropertyBinding;
44 friend class QQmlUnbindableToBindablePropertyBinding;
45 friend class QQmlBindableToBindablePropertyBinding;
46
47 QQmlPropertyToPropertyBinding(
48 QQmlEngine *engine, QObject *sourceObject, QQmlPropertyIndex sourcePropertyIndex);
49
50 template<typename Capture>
51 QVariant readSourceValue(Capture &&capture) const
52 {
53 const QMetaObject *sourceMetaObject = sourceObject->metaObject();
54 const QMetaProperty property
55 = sourceMetaObject->property(sourcePropertyIndex.coreIndex());
56 if (!property.isConstant())
57 capture(sourceMetaObject, property);
58
59 QVariant value;
60
61 const int valueTypeIndex = sourcePropertyIndex.valueTypeIndex();
62 if (valueTypeIndex == -1) {
63 value = property.read(sourceObject);
64 } else {
65 QQmlGadgetPtrWrapper *wrapper
66 = QQmlEnginePrivate::get(engine)->valueTypeInstance(property.metaType());
67 wrapper->read(sourceObject, sourcePropertyIndex.coreIndex());
68 value = wrapper->readOnGadget(wrapper->property(valueTypeIndex));
69 }
70
71 return value;
72 }
73
74 void doConnectNotify(QQmlNotifierEndpoint *endpoint, const QMetaProperty &property)
75 {
76 const int notifyIndex = QMetaObjectPrivate::signalIndex(property.notifySignal());
77
78 // We cannot capture non-bindable properties without signals
79 if (notifyIndex == -1)
80 return;
81
82 if (endpoint->isConnected(sourceObject, notifyIndex))
83 endpoint->cancelNotify();
84 else
85 endpoint->connect(sourceObject, notifyIndex, engine, true);
86 }
87
88 QQmlEngine *engine = nullptr;
89 QObject *sourceObject = nullptr;
90 QQmlPropertyIndex sourcePropertyIndex;
91};
92
94{
95public:
96 Kind kind() const final;
97 void setEnabled(bool e, QQmlPropertyData::WriteFlags flags) final;
98 void update(QQmlPropertyData::WriteFlags flags = QQmlPropertyData::DontRemoveBinding);
99
100protected:
102 QQmlEngine *engine, QObject *sourceObject, QQmlPropertyIndex sourcePropertyIndex,
103 QObject *targetObject, int targetPropertyIndex);
104
105 virtual void captureProperty(
106 const QMetaObject *sourceMetaObject, const QMetaProperty &sourceProperty) = 0;
107
108 QQmlPropertyToPropertyBinding m_binding;
109};
110
113{
114public:
116 QQmlEngine *engine, QObject *sourceObject, QQmlPropertyIndex sourcePropertyIndex,
117 QObject *targetObject, int targetPropertyIndex);
118protected:
119 void captureProperty(
120 const QMetaObject *sourceMetaObject, const QMetaProperty &sourceProperty) final;
121};
122
125{
126public:
128 QQmlEngine *engine, QObject *sourceObject, QQmlPropertyIndex sourcePropertyIndex,
129 QObject *targetObject, int targetPropertyIndex);
130
131 static void update(QPropertyObserver *observer, QUntypedPropertyData *);
132
133protected:
134 void captureProperty(
135 const QMetaObject *sourceMetaObject, const QMetaProperty &sourceProperty) final;
136private:
137 bool m_isObserving = false;
138};
139
142{
143public:
145 QQmlEngine *engine, QObject *sourceObject, QQmlPropertyIndex sourcePropertyIndex,
146 QObject *targetObject, int targetPropertyIndex);
147
148 static bool update(QMetaType metaType, QUntypedPropertyData *dataPtr, void *f);
149 void update();
150
151private:
152 QQmlPropertyToPropertyBinding m_binding;
153 QPointer<QObject> m_targetObject;
154 QQmlPropertyIndex m_targetPropertyIndex;
155};
156
159{
160public:
162 QQmlEngine *engine, QObject *sourceObject, QQmlPropertyIndex sourcePropertyIndex,
163 QObject *targetObject, int targetPropertyIndex);
164 static bool update(QMetaType metaType, QUntypedPropertyData *dataPtr, void *f);
165
166private:
167 QQmlPropertyToPropertyBinding m_binding;
168};
169
170void QQmlUnbindableToUnbindableGuard_callback(QQmlNotifierEndpoint *e, void **);
171void QQmlUnbindableToBindableGuard_callback(QQmlNotifierEndpoint *e, void **);
172
173QT_END_NAMESPACE
174
175#endif
QQmlBindableToBindablePropertyBinding(QQmlEngine *engine, QObject *sourceObject, QQmlPropertyIndex sourcePropertyIndex, QObject *targetObject, int targetPropertyIndex)
static bool update(QMetaType metaType, QUntypedPropertyData *dataPtr, void *f)
void captureProperty(const QMetaObject *sourceMetaObject, const QMetaProperty &sourceProperty) final
QQmlBindableToUnbindablePropertyBinding(QQmlEngine *engine, QObject *sourceObject, QQmlPropertyIndex sourcePropertyIndex, QObject *targetObject, int targetPropertyIndex)
static void update(QPropertyObserver *observer, QUntypedPropertyData *)
void setEnabled(bool e, QQmlPropertyData::WriteFlags flags) final
QQmlPropertyToUnbindablePropertyBinding(QQmlEngine *engine, QObject *sourceObject, QQmlPropertyIndex sourcePropertyIndex, QObject *targetObject, int targetPropertyIndex)
virtual void captureProperty(const QMetaObject *sourceMetaObject, const QMetaProperty &sourceProperty)=0
void update(QQmlPropertyData::WriteFlags flags=QQmlPropertyData::DontRemoveBinding)
QQmlUnbindableToBindablePropertyBinding(QQmlEngine *engine, QObject *sourceObject, QQmlPropertyIndex sourcePropertyIndex, QObject *targetObject, int targetPropertyIndex)
static bool update(QMetaType metaType, QUntypedPropertyData *dataPtr, void *f)
QQmlUnbindableToUnbindablePropertyBinding(QQmlEngine *engine, QObject *sourceObject, QQmlPropertyIndex sourcePropertyIndex, QObject *targetObject, int targetPropertyIndex)
void captureProperty(const QMetaObject *sourceMetaObject, const QMetaProperty &sourceProperty) final
Combined button and popup list for selecting options.
constexpr BindingFunctionVTable bindingFunctionVTableForQQmlPropertyToBindablePropertyBinding
void QQmlUnbindableToBindableGuard_callback(QQmlNotifierEndpoint *e, void **)
void QQmlUnbindableToUnbindableGuard_callback(QQmlNotifierEndpoint *e, void **)