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
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#include <QtCore/qpointer.h>
30
32
33class QQmlContext;
35class QQmlJavaScriptExpression;
36class QQmlMetaObject;
37class QQmlAbstractBinding;
38class QQmlBoundSignalExpression;
39
40class Q_QML_EXPORT QQmlPropertyPrivate final : public QQmlRefCounted<QQmlPropertyPrivate>
41{
42public:
43 enum class InitFlag {
44 None = 0x0,
45 AllowId = 0x1,
46 AllowSignal = 0x2
47 };
48 Q_DECLARE_FLAGS(InitFlags, InitFlag);
49
50 // like SequencePrototype, but we want to avoid tight coupling
51 enum class ListCopyResult
52 {
53 Copied,
54 WasEqual,
55 TypeMismatch
56 };
57
58 QQmlRefPointer<QQmlContextData> context;
59 QPointer<QQmlEngine> engine;
60 QPointer<QObject> object;
61
62 QQmlPropertyData core;
63 QQmlPropertyData valueTypeData;
64
65 QString nameCache;
66
67 // ### Qt7: Get rid of this.
68 static bool resolveUrlsOnAssignment();
69
70 QQmlPropertyPrivate() {}
71
72 QQmlPropertyIndex encodedIndex() const
73 { return encodedIndex(core, valueTypeData); }
74 static QQmlPropertyIndex encodedIndex(const QQmlPropertyData &core, const QQmlPropertyData &valueTypeData)
75 { return QQmlPropertyIndex(core.coreIndex(), valueTypeData.coreIndex()); }
76
77 QQmlRefPointer<QQmlContextData> effectiveContext() const;
78
79 void initProperty(QObject *obj, const QString &name, InitFlags flags = InitFlag::None);
80 void initDefault(QObject *obj);
81
82 bool isValueType() const;
83 QMetaType propertyType() const;
84 QQmlProperty::Type type() const;
85 QQmlProperty::PropertyTypeCategory propertyTypeCategory() const;
86
87 QVariant readValueProperty();
88 bool writeValueProperty(const QVariant &, QQmlPropertyData::WriteFlags);
89
90 static QQmlMetaObject rawMetaObjectForType(QMetaType metaType);
91 static bool writeEnumProperty(const QMetaProperty &prop, int idx, QObject *object,
92 const QVariant &value, int flags);
93 static bool writeValueProperty(QObject *,
94 const QQmlPropertyData &, const QQmlPropertyData &valueTypeData,
95 const QVariant &, const QQmlRefPointer<QQmlContextData> &,
96 QQmlPropertyData::WriteFlags flags = {});
97 static bool resetValueProperty(QObject *,
98 const QQmlPropertyData &, const QQmlPropertyData &valueTypeData,
99 const QQmlRefPointer<QQmlContextData> &,
100 QQmlPropertyData::WriteFlags flags = {});
101
102 /*!
103 \internal
104 Attempts to convert \a value to a QQmlListProperty. The existing \a listProperty will be modified (so use a
105 temporary one if that is not desired).
106 \a listProperty is passed as a QQmlListProperty<QObject>, but might actually be a list property of a more specific
107 type. The actual type of the list property is given by \a actualListType.
108 */
109 static ListCopyResult convertToQQmlListProperty(QQmlListProperty<QObject> *listProperty,
110 QMetaType actualListType,
111 const QVariant &value);
112 static QVariant convertToWriteTargetType(const QVariant &value, QMetaType targetMetaType);
113 static bool write(QObject *, const QQmlPropertyData &, const QVariant &,
114 const QQmlRefPointer<QQmlContextData> &,
115 QQmlPropertyData::WriteFlags flags = {});
116 static bool reset(QObject *, const QQmlPropertyData &,
117 QQmlPropertyData::WriteFlags flags = {});
118 static void findAliasTarget(QObject *, QQmlPropertyIndex, QObject **, QQmlPropertyIndex *);
119
120 struct ResolvedAlias
121 {
122 QObject *targetObject;
123 QQmlPropertyIndex targetIndex;
124 };
125 /*!
126 \internal
127 Given an alias property specified by \a baseObject and \a baseIndex, this function
128 computes the alias target.
129 */
130 static ResolvedAlias findAliasTarget(QObject *baseObject, QQmlPropertyIndex baseIndex);
131
132 enum BindingFlag {
133 None = 0,
134 DontEnable = 0x1,
135 OverrideSticky = 0x2
136 };
137 Q_DECLARE_FLAGS(BindingFlags, BindingFlag)
138
139 static void setBinding(QQmlAbstractBinding *binding, BindingFlags flags = None,
140 QQmlPropertyData::WriteFlags writeFlags = QQmlPropertyData::DontRemoveBinding);
141
142 static bool removeBinding(const QQmlProperty &that, BindingFlags flags = None);
143 static bool removeBinding(QObject *o, QQmlPropertyIndex index, BindingFlags flags = None);
144 static bool removeBinding(QQmlAbstractBinding *b, QQmlPropertyPrivate::BindingFlags flags = None);
145 static QQmlAbstractBinding *binding(QObject *, QQmlPropertyIndex index);
146
147 static QQmlProperty restore(QObject *, const QQmlPropertyData &, const QQmlPropertyData *,
148 const QQmlRefPointer<QQmlContextData> &);
149
150 int signalIndex() const;
151
152 static inline QQmlPropertyPrivate *get(const QQmlProperty &p) { return p.d; }
153
154 // "Public" (to QML) methods
155 static QQmlAbstractBinding *binding(const QQmlProperty &that);
156 static void setBinding(const QQmlProperty &that, QQmlAbstractBinding *);
157 static QQmlBoundSignalExpression *signalExpression(const QQmlProperty &that);
158 static void setSignalExpression(const QQmlProperty &that, QQmlBoundSignalExpression *);
159 static void takeSignalExpression(const QQmlProperty &that, QQmlBoundSignalExpression *);
160 static bool write(const QQmlProperty &that, const QVariant &, QQmlPropertyData::WriteFlags);
161 static QQmlPropertyIndex propertyIndex(const QQmlProperty &that);
162 static QMetaMethod findSignalByName(const QMetaObject *mo, const QByteArray &);
163 static QMetaProperty findPropertyByName(const QMetaObject *mo, const QByteArray &);
164 static bool connect(const QObject *sender, int signal_index,
165 const QObject *receiver, int method_index,
166 int type = 0, int *types = nullptr);
167 static void flushSignal(const QObject *sender, int signal_index);
168
169 static QList<QUrl> urlSequence(const QVariant &value);
170 static QList<QUrl> urlSequence(
171 const QVariant &value, const QQmlRefPointer<QQmlContextData> &ctxt);
172 static QQmlProperty create(
173 QObject *target, const QString &propertyName,
174 const QQmlRefPointer<QQmlContextData> &context,
175 QQmlPropertyPrivate::InitFlags flags);
176};
177
178Q_DECLARE_OPERATORS_FOR_FLAGS(QQmlPropertyPrivate::BindingFlags)
179Q_DECLARE_OPERATORS_FOR_FLAGS(QQmlPropertyPrivate::InitFlags);
180
181QT_END_NAMESPACE
182
183#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[]