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