1 | // Copyright (C) 2016 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 QQMLPROPERTY_H |
5 | #define QQMLPROPERTY_H |
6 | |
7 | #include <QtCore/qstring.h> |
8 | #include <QtCore/qhashfunctions.h> |
9 | #include <QtQml/qtqmlglobal.h> |
10 | #include <QtCore/qmetaobject.h> |
11 | #include <QtQml/qqmlregistration.h> |
12 | |
13 | QT_BEGIN_NAMESPACE |
14 | |
15 | |
16 | class QObject; |
17 | class QVariant; |
18 | class QQmlContext; |
19 | class QQmlEngine; |
20 | |
21 | class QQmlPropertyPrivate; |
22 | class Q_QML_EXPORT QQmlProperty |
23 | { |
24 | Q_GADGET |
25 | QML_ANONYMOUS |
26 | QML_ADDED_IN_VERSION(2, 15) |
27 | |
28 | Q_PROPERTY(QObject *object READ object CONSTANT FINAL) |
29 | Q_PROPERTY(QString name READ name CONSTANT FINAL) |
30 | public: |
31 | enum PropertyTypeCategory { |
32 | InvalidCategory, |
33 | List, |
34 | Object, |
35 | Normal |
36 | }; |
37 | |
38 | enum Type { |
39 | Invalid, |
40 | Property, |
41 | SignalProperty |
42 | }; |
43 | |
44 | QQmlProperty(); |
45 | ~QQmlProperty(); |
46 | |
47 | QQmlProperty(QObject *); |
48 | QQmlProperty(QObject *, QQmlContext *); |
49 | QQmlProperty(QObject *, QQmlEngine *); |
50 | |
51 | QQmlProperty(QObject *, const QString &); |
52 | QQmlProperty(QObject *, const QString &, QQmlContext *); |
53 | QQmlProperty(QObject *, const QString &, QQmlEngine *); |
54 | |
55 | QQmlProperty(const QQmlProperty &); |
56 | QQmlProperty &operator=(const QQmlProperty &); |
57 | |
58 | QQmlProperty(QQmlProperty &&other) noexcept : d(std::exchange(obj&: other.d, new_val: nullptr)) {} |
59 | QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QQmlProperty) |
60 | |
61 | void swap(QQmlProperty &other) noexcept { qt_ptr_swap(lhs&: d, rhs&: other.d); } |
62 | bool operator==(const QQmlProperty &) const; |
63 | |
64 | Type type() const; |
65 | bool isValid() const; |
66 | bool isProperty() const; |
67 | bool isSignalProperty() const; |
68 | |
69 | int propertyType() const; |
70 | QMetaType propertyMetaType() const; |
71 | PropertyTypeCategory propertyTypeCategory() const; |
72 | const char *propertyTypeName() const; |
73 | |
74 | QString name() const; |
75 | |
76 | QVariant read() const; |
77 | static QVariant read(const QObject *, const QString &); |
78 | static QVariant read(const QObject *, const QString &, QQmlContext *); |
79 | static QVariant read(const QObject *, const QString &, QQmlEngine *); |
80 | |
81 | bool write(const QVariant &) const; |
82 | static bool write(QObject *, const QString &, const QVariant &); |
83 | static bool write(QObject *, const QString &, const QVariant &, QQmlContext *); |
84 | static bool write(QObject *, const QString &, const QVariant &, QQmlEngine *); |
85 | |
86 | bool reset() const; |
87 | |
88 | bool hasNotifySignal() const; |
89 | bool needsNotifySignal() const; |
90 | bool connectNotifySignal(QObject *dest, const char *slot) const; |
91 | bool connectNotifySignal(QObject *dest, int method) const; |
92 | |
93 | bool isWritable() const; |
94 | bool isBindable() const; |
95 | bool isDesignable() const; |
96 | bool isResettable() const; |
97 | QObject *object() const; |
98 | |
99 | int index() const; |
100 | QMetaProperty property() const; |
101 | QMetaMethod method() const; |
102 | |
103 | private: |
104 | friend class QQmlPropertyPrivate; |
105 | QQmlPropertyPrivate *d = nullptr; |
106 | }; |
107 | typedef QList<QQmlProperty> QQmlProperties; |
108 | |
109 | inline size_t qHash (const QQmlProperty &key, size_t seed = 0) |
110 | { |
111 | return qHashMulti(seed, args: key.object(), args: key.name()); |
112 | } |
113 | |
114 | Q_DECLARE_TYPEINFO(QQmlProperty, Q_RELOCATABLE_TYPE); |
115 | |
116 | QT_END_NAMESPACE |
117 | |
118 | #endif // QQMLPROPERTY_H |
119 | |