Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qqmlpropertycachecreator.cpp
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
5
6#include <private/qqmlengine_p.h>
7
8#if QT_CONFIG(regularexpression)
9#include <QtCore/qregularexpression.h>
10#endif
11
13
15
16
18{
19 switch (type) {
21 case QV4::CompiledData::CommonType::Var: return QMetaType::fromType<QVariant>();
22 case QV4::CompiledData::CommonType::Int: return QMetaType::fromType<int>();
23 case QV4::CompiledData::CommonType::Bool: return QMetaType::fromType<bool>();
24 case QV4::CompiledData::CommonType::Real: return QMetaType::fromType<qreal>();
25 case QV4::CompiledData::CommonType::String: return QMetaType::fromType<QString>();
26 case QV4::CompiledData::CommonType::Url: return QMetaType::fromType<QUrl>();
27 case QV4::CompiledData::CommonType::Time: return QMetaType::fromType<QTime>();
28 case QV4::CompiledData::CommonType::Date: return QMetaType::fromType<QDate>();
29 case QV4::CompiledData::CommonType::DateTime: return QMetaType::fromType<QDateTime>();
30#if QT_CONFIG(regularexpression)
31 case QV4::CompiledData::CommonType::RegExp: return QMetaType::fromType<QRegularExpression>();
32#else
34#endif
35 case QV4::CompiledData::CommonType::Rect: return QMetaType::fromType<QRectF>();
36 case QV4::CompiledData::CommonType::Point: return QMetaType::fromType<QPointF>();
37 case QV4::CompiledData::CommonType::Size: return QMetaType::fromType<QSizeF>();
39 };
40 return QMetaType {};
41}
42
44{
45 switch (type) {
47 case QV4::CompiledData::CommonType::Var: return QMetaType::fromType<QList<QVariant>>();
48 case QV4::CompiledData::CommonType::Int: return QMetaType::fromType<QList<int>>();
49 case QV4::CompiledData::CommonType::Bool: return QMetaType::fromType<QList<bool>>();
50 case QV4::CompiledData::CommonType::Real: return QMetaType::fromType<QList<qreal>>();
51 case QV4::CompiledData::CommonType::String: return QMetaType::fromType<QList<QString>>();
52 case QV4::CompiledData::CommonType::Url: return QMetaType::fromType<QList<QUrl>>();
53 case QV4::CompiledData::CommonType::Time: return QMetaType::fromType<QList<QTime>>();
54 case QV4::CompiledData::CommonType::Date: return QMetaType::fromType<QList<QDate>>();
55 case QV4::CompiledData::CommonType::DateTime: return QMetaType::fromType<QList<QDateTime>>();
56#if QT_CONFIG(regularexpression)
57 case QV4::CompiledData::CommonType::RegExp: return QMetaType::fromType<QList<QRegularExpression>>();
58#else
60#endif
61 case QV4::CompiledData::CommonType::Rect: return QMetaType::fromType<QList<QRectF>>();
62 case QV4::CompiledData::CommonType::Point: return QMetaType::fromType<QList<QPointF>>();
63 case QV4::CompiledData::CommonType::Size: return QMetaType::fromType<QList<QSizeF>>();
65 };
66 return QMetaType {};
67}
68
69template<typename BaseNameHandler, typename FailHandler>
71 const QUrl &url, BaseNameHandler &&baseNameHandler, FailHandler &&failHandler)
72{
73 const QString path = url.path();
74
75 // Not a reusable type if we don't have an absolute Url
76 const qsizetype lastSlash = path.lastIndexOf(QLatin1Char('/'));
77 if (lastSlash <= -1)
78 return failHandler();
79
80 // ### this might not be correct for .ui.qml files
81 const QStringView baseName = QStringView{path}.mid(lastSlash + 1, path.size() - lastSlash - 5);
82
83 // Not a reusable type if it doesn't start with a upper case letter.
84 return (!baseName.isEmpty() && baseName.at(0).isUpper())
85 ? baseNameHandler(baseName)
86 : failHandler();
87}
88
90{
92 return true;
93 }, []() {
94 return false;
95 });
96}
97
99{
100 return processUrlForClassName(url, [](QStringView nameBase) {
101 return QByteArray(nameBase.toUtf8() + "_QMLTYPE_"
103 }, []() {
104 return QByteArray();
105 });
106}
107
109 const QUrl &baseUrl, const QString &name)
110{
111 QByteArray baseName = processUrlForClassName(baseUrl, [](QStringView nameBase) {
112 return QByteArray(nameBase.toUtf8() + "_QMLTYPE_");
113 }, []() {
114 return QByteArray("ANON_QML_IC_");
115 });
116 return baseName + name.toUtf8() + '_'
118}
119
121 int referencingObjectIndex,
122 const QV4::CompiledData::Binding *instantiatingBinding,
123 const QString &instantiatingPropertyName,
124 const QQmlPropertyCache::ConstPtr &referencingObjectPropertyCache)
125 : referencingObjectIndex(referencingObjectIndex)
126 , instantiatingBinding(instantiatingBinding)
127 , instantiatingPropertyName(instantiatingPropertyName)
128 , referencingObjectPropertyCache(referencingObjectPropertyCache)
129{
130}
131
133{
136 return true;
137 }
138
140 return false;
141
144
145 bool notInRevision = false;
147 .property(instantiatingPropertyName, &notInRevision,
149 return instantiatingProperty != nullptr;
150}
151
153{
156 // rawPropertyCacheForType assumes a given unspecified version means "any version".
157 // There is another overload that takes no version, which we shall not use here.
162 }
163 }
165}
166
168 QQmlPropertyCacheVector *propertyCaches) const
169{
170 for (QQmlBindingInstantiationContext pendingBinding: *this) {
171 const int groupPropertyObjectIndex = pendingBinding.instantiatingBinding->value.objectIndex;
172
173 if (propertyCaches->at(groupPropertyObjectIndex))
174 continue;
175
176 if (pendingBinding.instantiatingPropertyName.isEmpty()) {
177 // Generalized group property.
178 auto cache = propertyCaches->at(pendingBinding.referencingObjectIndex);
179 propertyCaches->set(groupPropertyObjectIndex, cache);
180 continue;
181 }
182
183 if (!pendingBinding.referencingObjectPropertyCache) {
184 pendingBinding.referencingObjectPropertyCache
185 = propertyCaches->at(pendingBinding.referencingObjectIndex);
186 }
187
188 if (!pendingBinding.resolveInstantiatingProperty())
189 continue;
190 auto cache = pendingBinding.instantiatingPropertyCache();
191 propertyCaches->set(groupPropertyObjectIndex, cache);
192 }
193}
194
\inmodule QtCore
Definition qatomic.h:112
T fetchAndAddRelaxed(T valueToAdd) noexcept
\inmodule QtCore
Definition qbytearray.h:57
static QByteArray number(int, int base=10)
Returns a byte-array representing the whole number n as text.
constexpr bool isUpper() const noexcept
Returns true if the character is an uppercase letter, for example category() is Letter_Uppercase.
Definition qchar.h:475
\inmodule QtCore
Definition qmetatype.h:320
static QQmlPropertyCache::ConstPtr rawPropertyCacheForType(QMetaType metaType)
static const QMetaObject * metaObjectForValueType(QMetaType type)
static QQmlPropertyCache::ConstPtr propertyCache(QObject *object, QTypeRevision version=QTypeRevision())
Returns a QQmlPropertyCache for obj if one is available.
QQmlPropertyCache::ConstPtr at(int index) const
void set(int index, const QQmlPropertyCache::ConstPtr &replacement)
QTypeRevision typeVersion() const
QMetaType propType() const
\inmodule QtCore
Definition qstringview.h:76
constexpr bool isEmpty() const noexcept
Returns whether this string view is empty - that is, whether {size() == 0}.
QByteArray toUtf8() const
Returns a UTF-8 representation of the string view as a QByteArray.
constexpr QChar at(qsizetype n) const noexcept
Returns the character at position n in this string view.
constexpr QStringView mid(qsizetype pos, qsizetype n=-1) const noexcept
Returns the substring of length length starting at position start in this object.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
qsizetype lastIndexOf(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
Definition qstring.h:279
\inmodule QtCore
Definition qurl.h:94
QString path(ComponentFormattingOptions options=FullyDecoded) const
Returns the path of the URL.
Definition qurl.cpp:2465
QCache< int, Employee > cache
[0]
Combined button and popup list for selecting options.
GLenum type
GLuint name
GLsizei const GLchar *const * path
auto processUrlForClassName(const QUrl &url, BaseNameHandler &&baseNameHandler, FailHandler &&failHandler)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
ptrdiff_t qsizetype
Definition qtypes.h:70
QUrl url("example.com")
[constructor-url-reference]
QUrl baseUrl
\inmodule QtCore \reentrant
Definition qchar.h:17
\inmodule QtCore
QQmlPropertyCache::ConstPtr referencingObjectPropertyCache
const QV4::CompiledData::Binding * instantiatingBinding
const QQmlPropertyData * instantiatingProperty
QQmlPropertyCache::ConstPtr instantiatingPropertyCache() const
void resolveMissingPropertyCaches(QQmlPropertyCacheVector *propertyCaches) const
static bool canCreateClassNameTypeByUrl(const QUrl &url)
static QByteArray createClassNameTypeByUrl(const QUrl &url)
static QMetaType listTypeForPropertyType(QV4::CompiledData::CommonType type)
static QAtomicInt Q_AUTOTEST_EXPORT classIndexCounter
static QByteArray createClassNameForInlineComponent(const QUrl &baseUrl, const QString &name)
static QMetaType metaTypeForPropertyType(QV4::CompiledData::CommonType type)
const QQmlPropertyData * property(int index) const