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_P_H |
5 | #define QQMLPROPERTY_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 "qqmlproperty.h" |
19 | |
20 | #include <private/qobject_p.h> |
21 | #include <private/qqmlcontextdata_p.h> |
22 | #include <private/qqmlpropertydata_p.h> |
23 | #include <private/qqmlpropertyindex_p.h> |
24 | #include <private/qqmlrefcount_p.h> |
25 | #include <private/qtqmlglobal_p.h> |
26 | |
27 | #include <QtQml/qqmlengine.h> |
28 | |
29 | QT_BEGIN_NAMESPACE |
30 | |
31 | class QQmlContext; |
32 | class QQmlEnginePrivate; |
33 | class QQmlJavaScriptExpression; |
34 | class QQmlMetaObject; |
35 | class QQmlAbstractBinding; |
36 | class QQmlBoundSignalExpression; |
37 | |
38 | class Q_QML_PRIVATE_EXPORT QQmlPropertyPrivate : public QQmlRefCounted<QQmlPropertyPrivate> |
39 | { |
40 | public: |
41 | enum class InitFlag { |
42 | None = 0x0, |
43 | AllowId = 0x1, |
44 | AllowSignal = 0x2 |
45 | }; |
46 | Q_DECLARE_FLAGS(InitFlags, InitFlag); |
47 | |
48 | QQmlRefPointer<QQmlContextData> context; |
49 | QPointer<QQmlEngine> engine; |
50 | QPointer<QObject> object; |
51 | |
52 | QQmlPropertyData core; |
53 | QQmlPropertyData valueTypeData; |
54 | |
55 | QString nameCache; |
56 | |
57 | // ### Qt7: Get rid of this. |
58 | static bool resolveUrlsOnAssignment(); |
59 | |
60 | QQmlPropertyPrivate() {} |
61 | |
62 | QQmlPropertyIndex encodedIndex() const |
63 | { return encodedIndex(core, valueTypeData); } |
64 | static QQmlPropertyIndex encodedIndex(const QQmlPropertyData &core, const QQmlPropertyData &valueTypeData) |
65 | { return QQmlPropertyIndex(core.coreIndex(), valueTypeData.coreIndex()); } |
66 | |
67 | QQmlRefPointer<QQmlContextData> effectiveContext() const; |
68 | |
69 | void initProperty(QObject *obj, const QString &name, InitFlags flags = InitFlag::None); |
70 | void initDefault(QObject *obj); |
71 | |
72 | bool isValueType() const; |
73 | QMetaType propertyType() const; |
74 | QQmlProperty::Type type() const; |
75 | QQmlProperty::PropertyTypeCategory propertyTypeCategory() const; |
76 | |
77 | QVariant readValueProperty(); |
78 | bool writeValueProperty(const QVariant &, QQmlPropertyData::WriteFlags); |
79 | |
80 | static QQmlMetaObject rawMetaObjectForType(QMetaType metaType); |
81 | static bool writeEnumProperty(const QMetaProperty &prop, int idx, QObject *object, |
82 | const QVariant &value, int flags); |
83 | static bool writeValueProperty(QObject *, |
84 | const QQmlPropertyData &, const QQmlPropertyData &valueTypeData, |
85 | const QVariant &, const QQmlRefPointer<QQmlContextData> &, |
86 | QQmlPropertyData::WriteFlags flags = {}); |
87 | static bool resetValueProperty(QObject *, |
88 | const QQmlPropertyData &, const QQmlPropertyData &valueTypeData, |
89 | const QQmlRefPointer<QQmlContextData> &, |
90 | QQmlPropertyData::WriteFlags flags = {}); |
91 | static bool write(QObject *, const QQmlPropertyData &, const QVariant &, |
92 | const QQmlRefPointer<QQmlContextData> &, |
93 | QQmlPropertyData::WriteFlags flags = {}); |
94 | static bool reset(QObject *, const QQmlPropertyData &, |
95 | QQmlPropertyData::WriteFlags flags = {}); |
96 | static void findAliasTarget(QObject *, QQmlPropertyIndex, QObject **, QQmlPropertyIndex *); |
97 | |
98 | struct ResolvedAlias |
99 | { |
100 | QObject *targetObject; |
101 | QQmlPropertyIndex targetIndex; |
102 | }; |
103 | /*! |
104 | \internal |
105 | Given an alias property specified by \a baseObject and \a baseIndex, this function |
106 | computes the alias target. |
107 | */ |
108 | static ResolvedAlias findAliasTarget(QObject *baseObject, QQmlPropertyIndex baseIndex); |
109 | |
110 | enum BindingFlag { |
111 | None = 0, |
112 | DontEnable = 0x1 |
113 | }; |
114 | Q_DECLARE_FLAGS(BindingFlags, BindingFlag) |
115 | |
116 | static void setBinding(QQmlAbstractBinding *binding, BindingFlags flags = None, |
117 | QQmlPropertyData::WriteFlags writeFlags = QQmlPropertyData::DontRemoveBinding); |
118 | |
119 | static void removeBinding(const QQmlProperty &that); |
120 | static void removeBinding(QObject *o, QQmlPropertyIndex index); |
121 | static void removeBinding(QQmlAbstractBinding *b); |
122 | static QQmlAbstractBinding *binding(QObject *, QQmlPropertyIndex index); |
123 | |
124 | static QQmlProperty restore(QObject *, const QQmlPropertyData &, const QQmlPropertyData *, |
125 | const QQmlRefPointer<QQmlContextData> &); |
126 | |
127 | int signalIndex() const; |
128 | |
129 | static inline QQmlPropertyPrivate *get(const QQmlProperty &p) { return p.d; } |
130 | |
131 | // "Public" (to QML) methods |
132 | static QQmlAbstractBinding *binding(const QQmlProperty &that); |
133 | static void setBinding(const QQmlProperty &that, QQmlAbstractBinding *); |
134 | static QQmlBoundSignalExpression *signalExpression(const QQmlProperty &that); |
135 | static void setSignalExpression(const QQmlProperty &that, QQmlBoundSignalExpression *); |
136 | static void takeSignalExpression(const QQmlProperty &that, QQmlBoundSignalExpression *); |
137 | static bool write(const QQmlProperty &that, const QVariant &, QQmlPropertyData::WriteFlags); |
138 | static QQmlPropertyIndex propertyIndex(const QQmlProperty &that); |
139 | static QMetaMethod findSignalByName(const QMetaObject *mo, const QByteArray &); |
140 | static QMetaProperty findPropertyByName(const QMetaObject *mo, const QByteArray &); |
141 | static bool connect(const QObject *sender, int signal_index, |
142 | const QObject *receiver, int method_index, |
143 | int type = 0, int *types = nullptr); |
144 | static void flushSignal(const QObject *sender, int signal_index); |
145 | |
146 | static QList<QUrl> urlSequence(const QVariant &value); |
147 | static QList<QUrl> urlSequence( |
148 | const QVariant &value, const QQmlRefPointer<QQmlContextData> &ctxt); |
149 | static QQmlProperty create( |
150 | QObject *target, const QString &propertyName, |
151 | const QQmlRefPointer<QQmlContextData> &context, |
152 | QQmlPropertyPrivate::InitFlags flags); |
153 | |
154 | }; |
155 | |
156 | Q_DECLARE_OPERATORS_FOR_FLAGS(QQmlPropertyPrivate::BindingFlags) |
157 | Q_DECLARE_OPERATORS_FOR_FLAGS(QQmlPropertyPrivate::InitFlags); |
158 | |
159 | QT_END_NAMESPACE |
160 | |
161 | #endif // QQMLPROPERTY_P_H |
162 | |