1// Copyright (C) 2021 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 QBINDINGSTORAGE_H
5#define QBINDINGSTORAGE_H
6
7#include <QtCore/qglobal.h>
8#include <QtCore/qnamespace.h>
9
10QT_BEGIN_NAMESPACE
11
12template <typename Class, typename T, auto Offset, auto Setter, auto Signal, auto Getter>
13class QObjectCompatProperty;
14struct QPropertyDelayedNotifications;
15class QUntypedPropertyData;
16
17namespace QtPrivate {
18
19class QPropertyBindingData;
20struct BindingEvaluationState;
21struct CompatPropertySafePoint;
22}
23
24struct QBindingStatus
25{
26 QtPrivate::BindingEvaluationState *currentlyEvaluatingBinding = nullptr;
27 QtPrivate::CompatPropertySafePoint *currentCompatProperty = nullptr;
28 Qt::HANDLE threadId = nullptr;
29 QPropertyDelayedNotifications *groupUpdateData = nullptr;
30};
31
32namespace QtPrivate {
33struct QBindingStatusAccessToken;
34Q_AUTOTEST_EXPORT QBindingStatus *getBindingStatus(QBindingStatusAccessToken);
35Q_AUTOTEST_EXPORT void setBindingStatus(QBindingStatus *, QBindingStatusAccessToken);
36}
37
38
39struct QBindingStorageData;
40class Q_CORE_EXPORT QBindingStorage
41{
42 mutable QBindingStorageData *d = nullptr;
43 QBindingStatus *bindingStatus = nullptr;
44
45 template<typename Class, typename T, auto Offset, auto Setter, auto Signal, auto Getter>
46 friend class QObjectCompatProperty;
47 friend class QObjectPrivate;
48 friend class QtPrivate::QPropertyBindingData;
49public:
50 QBindingStorage();
51 ~QBindingStorage();
52
53 bool isEmpty() { return !d; }
54 bool isValid() const noexcept { return bindingStatus; }
55
56 const QBindingStatus *status(QtPrivate::QBindingStatusAccessToken) const;
57
58 void registerDependency(const QUntypedPropertyData *data) const
59 {
60 if (!bindingStatus || !bindingStatus->currentlyEvaluatingBinding)
61 return;
62 registerDependency_helper(data);
63 }
64 QtPrivate::QPropertyBindingData *bindingData(const QUntypedPropertyData *data) const
65 {
66 if (!d)
67 return nullptr;
68 return bindingData_helper(data);
69 }
70
71#if QT_CORE_REMOVED_SINCE(6, 2)
72 void maybeUpdateBindingAndRegister(const QUntypedPropertyData *data) const { registerDependency(data); }
73#endif
74
75 QtPrivate::QPropertyBindingData *bindingData(QUntypedPropertyData *data, bool create)
76 {
77 if (!d && !create)
78 return nullptr;
79 return bindingData_helper(data, create);
80 }
81private:
82 void reinitAfterThreadMove();
83 void clear();
84 void registerDependency_helper(const QUntypedPropertyData *data) const;
85#if QT_CORE_REMOVED_SINCE(6, 2)
86 // ### Unused, but keep for BC
87 void maybeUpdateBindingAndRegister_helper(const QUntypedPropertyData *data) const;
88#endif
89 QtPrivate::QPropertyBindingData *bindingData_helper(const QUntypedPropertyData *data) const;
90 QtPrivate::QPropertyBindingData *bindingData_helper(QUntypedPropertyData *data, bool create);
91};
92
93QT_END_NAMESPACE
94
95#endif // QBINDINGSTORAGE_H
96

source code of qtbase/src/corelib/kernel/qbindingstorage.h