Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
9
11
12template<typename BaseNameHandler, typename FailHandler>
14 const QUrl &url, BaseNameHandler &&baseNameHandler, FailHandler &&failHandler)
15{
16 const QString path = url.path();
17
18 // Not a reusable type if we don't have an absolute Url
19 const qsizetype lastSlash = path.lastIndexOf(QLatin1Char('/'));
20 if (lastSlash <= -1)
21 return failHandler();
22
23 // ### this might not be correct for .ui.qml files
24 const QStringView baseName = QStringView{path}.mid(lastSlash + 1, path.size() - lastSlash - 5);
25
26 // Not a reusable type if it doesn't start with a upper case letter.
27 return (!baseName.isEmpty() && baseName.at(0).isUpper())
28 ? baseNameHandler(baseName)
29 : failHandler();
30}
31
33{
35 return true;
36 }, []() {
37 return false;
38 });
39}
40
42{
43 return processUrlForClassName(url, [](QStringView nameBase) {
44 return nameBase.toUtf8() + QByteArray("_QMLTYPE_");
45 }, []() {
46 return QByteArray("ANON_QML_TYPE_");
47 }) + QByteArray::number(classIndexCounter.fetchAndAddRelaxed(1));
48}
49
51 const QUrl &baseUrl, const QString &name)
52{
53 QByteArray baseName = processUrlForClassName(baseUrl, [](QStringView nameBase) {
54 return QByteArray(nameBase.toUtf8() + "_QMLTYPE_");
55 }, []() {
56 return QByteArray("ANON_QML_IC_");
57 });
58 return baseName + name.toUtf8() + '_'
59 + QByteArray::number(classIndexCounter.fetchAndAddRelaxed(1));
60}
61
63 int referencingObjectIndex,
64 const QV4::CompiledData::Binding *instantiatingBinding,
65 const QString &instantiatingPropertyName,
66 const QQmlPropertyCache::ConstPtr &referencingObjectPropertyCache)
67 : referencingObjectIndex(referencingObjectIndex)
68 , instantiatingBinding(instantiatingBinding)
69 , instantiatingPropertyName(instantiatingPropertyName)
70 , referencingObjectPropertyCache(referencingObjectPropertyCache)
71{
72}
73
93
95{
98 // rawPropertyCacheForType assumes a given unspecified version means "any version".
99 // There is another overload that takes no version, which we shall not use here.
102 if (result)
103 return result;
104 /* We might end up here if there's a grouped property, and the type hasn't been registered.
105 Still try to get a property cache, as long as the type of the property is well-behaved
106 (i.e., not dynamic)*/
108 // we'll warn about dynamic meta-object later in the property validator
111 }
112 // fall through intentional
115 }
116 }
118}
119
121 QQmlPropertyCacheVector *propertyCaches) const
122{
123 for (QQmlBindingInstantiationContext pendingBinding: *this) {
124 const int groupPropertyObjectIndex = pendingBinding.instantiatingBinding->value.objectIndex;
125
126 if (propertyCaches->at(groupPropertyObjectIndex))
127 continue;
128
129 Q_ASSERT(!pendingBinding.instantiatingPropertyName.isEmpty());
130
131 if (!pendingBinding.referencingObjectPropertyCache) {
132 pendingBinding.referencingObjectPropertyCache
133 = propertyCaches->at(pendingBinding.referencingObjectIndex);
134 }
135
136 if (!pendingBinding.resolveInstantiatingProperty())
137 continue;
138 auto cache = pendingBinding.instantiatingPropertyCache();
139 propertyCaches->set(groupPropertyObjectIndex, cache);
140 }
141}
142
\inmodule QtCore
Definition qatomic.h:112
\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 const QMetaObject * metaObject() const
Definition qmetatype.h:2663
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:78
constexpr bool isEmpty() const noexcept
Returns whether this string view is empty - that is, whether {size() == 0}.
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:129
qsizetype lastIndexOf(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
Definition qstring.h:296
\inmodule QtCore
Definition qurl.h:94
QString path(ComponentFormattingOptions options=FullyDecoded) const
Returns the path of the URL.
Definition qurl.cpp:2468
QCache< int, Employee > cache
[0]
Combined button and popup list for selecting options.
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
@ DynamicMetaObject
GLbitfield flags
GLuint name
GLsizei const GLchar *const * path
GLuint64EXT * result
[6]
auto processUrlForClassName(const QUrl &url, BaseNameHandler &&baseNameHandler, FailHandler &&failHandler)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
ptrdiff_t qsizetype
Definition qtypes.h:165
QUrl url("example.com")
[constructor-url-reference]
QUrl baseUrl
obj metaObject() -> className()
\inmodule QtCore \reentrant
Definition qchar.h:18
static const QMetaObjectPrivate * get(const QMetaObject *metaobject)
\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 QAtomicInt Q_AUTOTEST_EXPORT classIndexCounter
static QByteArray createClassNameForInlineComponent(const QUrl &baseUrl, const QString &name)
const QQmlPropertyData * property(int index) const