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