Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqmlproperty_p.h
Go to the documentation of this file.
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// Qt-Security score:significant
4
5#ifndef QQMLPROPERTY_P_H
6#define QQMLPROPERTY_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include "qqmlproperty.h"
20
21#include <private/qobject_p.h>
22#include <private/qqmlcontextdata_p.h>
23#include <private/qqmlpropertydata_p.h>
24#include <private/qqmlpropertyindex_p.h>
25#include <private/qqmlrefcount_p.h>
26#include <private/qtqmlglobal_p.h>
27
28#include <QtQml/qqmlengine.h>
29
30#include <QtCore/qpointer.h>
31
33
34class QQmlContext;
36class QQmlJavaScriptExpression;
37class QQmlMetaObject;
38class QQmlAbstractBinding;
39class QQmlBoundSignalExpression;
40
41class Q_QML_EXPORT QQmlPropertyPrivate final : public QQmlRefCounted<QQmlPropertyPrivate>
42{
43public:
44 enum class InitFlag {
45 None = 0x0,
46 AllowId = 0x1,
47 AllowSignal = 0x2
48 };
49 Q_DECLARE_FLAGS(InitFlags, InitFlag);
50
51 // like SequencePrototype, but we want to avoid tight coupling
52 enum class ListCopyResult
53 {
54 Copied,
55 WasEqual,
56 TypeMismatch
57 };
58
59 QQmlRefPointer<QQmlContextData> context;
60 QPointer<QQmlEngine> engine;
61 QPointer<QObject> object;
62
63 QQmlPropertyData core;
64 QQmlPropertyData valueTypeData;
65
66 QString nameCache;
67
68 // ### Qt7: Get rid of this.
69 static bool resolveUrlsOnAssignment();
70
71 QQmlPropertyPrivate() {}
72
73 QQmlPropertyIndex encodedIndex() const
74 { return encodedIndex(core, valueTypeData); }
75 static QQmlPropertyIndex encodedIndex(const QQmlPropertyData &core, const QQmlPropertyData &valueTypeData)
76 { return QQmlPropertyIndex(core.coreIndex(), valueTypeData.coreIndex()); }
77
78 QQmlRefPointer<QQmlContextData> effectiveContext() const;
79
80 void initProperty(QObject *obj, const QString &name, InitFlags flags = InitFlag::None);
81 void initDefault(QObject *obj);
82
83 bool isValueType() const;
84 QMetaType propertyType() const;
85 QQmlProperty::Type type() const;
86 QQmlProperty::PropertyTypeCategory propertyTypeCategory() const;
87
88 QVariant readValueProperty();
89 bool writeValueProperty(const QVariant &, QQmlPropertyData::WriteFlags);
90
91 static QQmlMetaObject rawMetaObjectForType(QMetaType metaType);
92 static bool writeEnumProperty(const QMetaProperty &prop, int idx, QObject *object,
93 const QVariant &value, int flags);
94 static bool writeValueProperty(QObject *,
95 const QQmlPropertyData &, const QQmlPropertyData &valueTypeData,
96 const QVariant &, const QQmlRefPointer<QQmlContextData> &,
97 QQmlPropertyData::WriteFlags flags = {});
98 static bool resetValueProperty(QObject *,
99 const QQmlPropertyData &, const QQmlPropertyData &valueTypeData,
100 const QQmlRefPointer<QQmlContextData> &,
101 QQmlPropertyData::WriteFlags flags = {});
102
103 /*!
104 \internal
105 Attempts to convert \a value to a QQmlListProperty. The existing \a listProperty will be modified (so use a
106 temporary one if that is not desired).
107 \a listProperty is passed as a QQmlListProperty<QObject>, but might actually be a list property of a more specific
108 type. The actual type of the list property is given by \a actualListType.
109 */
110 static ListCopyResult convertToQQmlListProperty(QQmlListProperty<QObject> *listProperty,
111 QMetaType actualListType,
112 const QVariant &value);
113 static QVariant convertToWriteTargetType(const QVariant &value, QMetaType targetMetaType);
114 static bool write(QObject *, const QQmlPropertyData &, const QVariant &,
115 const QQmlRefPointer<QQmlContextData> &,
116 QQmlPropertyData::WriteFlags flags = {});
117 static bool reset(QObject *, const QQmlPropertyData &,
118 QQmlPropertyData::WriteFlags flags = {});
119 static void findAliasTarget(QObject *, QQmlPropertyIndex, QObject **, QQmlPropertyIndex *);
120
121 struct ResolvedAlias
122 {
123 QObject *targetObject;
124 QQmlPropertyIndex targetIndex;
125 };
126 /*!
127 \internal
128 Given an alias property specified by \a baseObject and \a baseIndex, this function
129 computes the alias target.
130 */
131 static ResolvedAlias findAliasTarget(QObject *baseObject, QQmlPropertyIndex baseIndex);
132
133 enum BindingFlag {
134 None = 0,
135 DontEnable = 0x1,
136 OverrideSticky = 0x2
137 };
138 Q_DECLARE_FLAGS(BindingFlags, BindingFlag)
139
140 static void setBinding(QQmlAbstractBinding *binding, BindingFlags flags = None,
141 QQmlPropertyData::WriteFlags writeFlags = QQmlPropertyData::DontRemoveBinding);
142
143 static bool removeBinding(const QQmlProperty &that, BindingFlags flags = None);
144 static bool removeBinding(QObject *o, QQmlPropertyIndex index, BindingFlags flags = None);
145 static bool removeBinding(QQmlAbstractBinding *b, QQmlPropertyPrivate::BindingFlags flags = None);
146 static QQmlAbstractBinding *binding(QObject *, QQmlPropertyIndex index);
147
148 static QQmlProperty restore(QObject *, const QQmlPropertyData &, const QQmlPropertyData *,
149 const QQmlRefPointer<QQmlContextData> &);
150
151 int signalIndex() const;
152
153 static inline QQmlPropertyPrivate *get(const QQmlProperty &p) { return p.d; }
154
155 // "Public" (to QML) methods
156 static QQmlAbstractBinding *binding(const QQmlProperty &that);
157 static void setBinding(const QQmlProperty &that, QQmlAbstractBinding *);
158 static QQmlBoundSignalExpression *signalExpression(const QQmlProperty &that);
159 static void setSignalExpression(const QQmlProperty &that, QQmlBoundSignalExpression *);
160 static void takeSignalExpression(const QQmlProperty &that, QQmlBoundSignalExpression *);
161 static bool write(const QQmlProperty &that, const QVariant &, QQmlPropertyData::WriteFlags);
162 static QQmlPropertyIndex propertyIndex(const QQmlProperty &that);
163 static QMetaMethod findSignalByName(const QMetaObject *mo, const QByteArray &);
164 static QMetaProperty findPropertyByName(const QMetaObject *mo, const QByteArray &);
165 static bool connect(const QObject *sender, int signal_index,
166 const QObject *receiver, int method_index,
167 int type = 0, int *types = nullptr);
168 static void flushSignal(const QObject *sender, int signal_index);
169
170 static QList<QUrl> urlSequence(const QVariant &value);
171 static QList<QUrl> urlSequence(
172 const QVariant &value, const QQmlRefPointer<QQmlContextData> &ctxt);
173 static QQmlProperty create(
174 QObject *target, const QString &propertyName,
175 const QQmlRefPointer<QQmlContextData> &context,
176 QQmlPropertyPrivate::InitFlags flags);
177};
178
179Q_DECLARE_OPERATORS_FOR_FLAGS(QQmlPropertyPrivate::BindingFlags)
180Q_DECLARE_OPERATORS_FOR_FLAGS(QQmlPropertyPrivate::InitFlags);
181
182QT_END_NAMESPACE
183
184#endif // QQMLPROPERTY_P_H
friend class QQmlEnginePrivate
void setSender(qintptr sender)
void cancelNotify()
Cancel any notifies that are in progress.
bool isNotifying() const
Returns true if a notify is in progress.
QObject * senderAsObject() const
void connect(QObject *source, int sourceSignal, QQmlEngine *engine, bool doNotify=true)
QQmlNotifier * senderAsNotifier() const
bool isConnected(QQmlNotifier *) const
void stopNotifying(qintptr *originalSenderPtr)
qintptr sender() const
void connect(QQmlNotifier *)
bool isConnected(QObject *source, int sourceSignal) const
void startNotifying(qintptr *originalSenderPtr)
QQmlNotifierEndpoint(Callback callback)
Combined button and popup list for selecting options.
void QQmlUnbindableToUnbindableGuard_callback(QQmlNotifierEndpoint *, void **)
void QQmlVMEMetaObjectEndpoint_callback(QQmlNotifierEndpoint *, void **)
void QQmlBoundSignal_callback(QQmlNotifierEndpoint *, void **)
void QQmlUnbindableToBindableGuard_callback(QQmlNotifierEndpoint *, void **)
QT_BEGIN_NAMESPACE typedef void(* Callback)(QQmlNotifierEndpoint *, void **)
void QQmlDirtyReferenceObject_callback(QQmlNotifierEndpoint *, void **)
void QQmlJavaScriptExpressionGuard_callback(QQmlNotifierEndpoint *, void **)
static Callback QQmlNotifier_callbacks[]