6#include <private/qqmlextensionplugin_p.h>
7#include <private/qqmlmetatypedata_p.h>
8#include <private/qqmlpropertycachecreator_p.h>
9#include <private/qqmltype_p_p.h>
10#include <private/qqmltypeloader_p.h>
11#include <private/qqmltypemodule_p.h>
12#include <private/qqmlvaluetype_p.h>
13#include <private/qv4executablecompilationunit_p.h>
15#include <QtCore/qcoreapplication.h>
16#include <QtCore/qmutex.h>
17#include <QtCore/qloggingcategory.h>
35 ModuleUri(
const std::unique_ptr<QQmlTypeModule> &module) :
QString(module->module()) {}
64 d->extraData.interfaceTypeData =
type.iid;
65 d->typeId =
type.typeId;
66 d->listId =
type.listId;
68 d->version =
type.version;
69 data->registerType(
d);
77 data->registerType(
d);
80 d->version =
type.version;
82 if (
type.qObjectApi) {
83 d->baseMetaObject =
type.instanceMetaObject;
84 d->typeId =
type.typeId;
85 d->revision =
type.revision;
89 d->extraData.singletonTypeData->singletonInstanceInfo->scriptCallback =
type.scriptApi;
90 d->extraData.singletonTypeData->singletonInstanceInfo->qobjectCallback =
type.qObjectApi;
92 d->extraData.singletonTypeData->singletonInstanceInfo->instanceMetaObject
93 =
type.qObjectApi ?
type.instanceMetaObject :
nullptr;
94 d->extraData.singletonTypeData->extFunc =
type.extensionObjectCreate;
95 d->extraData.singletonTypeData->extMetaObject =
type.extensionMetaObject;
104 data->registerType(
d);
107 d->version =
type.version;
108 d->revision =
type.revision;
109 d->typeId =
type.typeId;
110 d->listId =
type.listId;
111 d->extraData.cppTypeData->allocationSize =
type.objectSize;
112 d->extraData.cppTypeData->userdata =
type.userdata;
113 d->extraData.cppTypeData->newFunc =
type.create;
114 d->extraData.cppTypeData->noCreationReason =
type.noCreationReason;
115 d->extraData.cppTypeData->createValueTypeFunc =
type.createValueType;
116 d->baseMetaObject =
type.metaObject;
117 d->extraData.cppTypeData->attachedPropertiesFunc =
type.attachedPropertiesFunction;
118 d->extraData.cppTypeData->attachedPropertiesType =
type.attachedPropertiesMetaObject;
119 d->extraData.cppTypeData->parserStatusCast =
type.parserStatusCast;
120 d->extraData.cppTypeData->propertyValueSourceCast =
type.valueSourceCast;
121 d->extraData.cppTypeData->propertyValueInterceptorCast =
type.valueInterceptorCast;
125 d->extraData.cppTypeData->extFunc =
type.extensionObjectCreate;
127 d->extraData.cppTypeData->registerEnumClassesUnscoped =
true;
128 d->extraData.cppTypeData->registerEnumsFromRelatedTypes =
true;
134 if (
type.extensionMetaObject)
135 d->extraData.cppTypeData->extMetaObject =
type.extensionMetaObject;
138 if (
d->baseMetaObject) {
139 auto indexOfUnscoped =
d->baseMetaObject->indexOfClassInfo(
"RegisterEnumClassesUnscoped");
140 if (indexOfUnscoped != -1
141 &&
qstrcmp(
d->baseMetaObject->classInfo(indexOfUnscoped).value(),
"false") == 0) {
142 d->extraData.cppTypeData->registerEnumClassesUnscoped =
false;
145 auto indexOfRelated =
d->baseMetaObject->indexOfClassInfo(
"RegisterEnumsFromRelatedTypes");
146 if (indexOfRelated != -1
147 &&
qstrcmp(
d->baseMetaObject->classInfo(indexOfRelated).value(),
"false") == 0) {
148 d->extraData.cppTypeData->registerEnumsFromRelatedTypes =
false;
167 priv->typeId = ptr_type;
168 priv->listId = lst_type;
175 data->registerType(
d);
177 d->version =
type.version;
190 data->registerType(
d);
193 d->version =
type.version;
197 d->extraData.singletonTypeData->singletonInstanceInfo->url =
normalized;
212 for (
int ii =
mo->classInfoOffset(); ii <
mo->classInfoCount(); ++ii) {
225 for (
int ii =
mo->methodOffset(); ii <
mo->methodCount(); ++ii) {
247 for (
int ii =
mo->propertyOffset(); ii <
mo->propertyCount(); ++ii) {
262 for (
int ii =
mo->enumeratorOffset(); ii <
mo->enumeratorCount(); ++ii) {
277 if (
data->moduleTypeRegistrationFunctions.contains(uri))
280 data->moduleTypeRegistrationFunctions.insert(uri, registerFunction);
290 if (!
data->moduleTypeRegistrationFunctions.contains(uri))
293 data->moduleTypeRegistrationFunctions.remove(uri);
299 return data->registerModuleTypes(uri);
307 data->uriToModule.clear();
309 data->idToType.clear();
310 data->nameToType.clear();
311 data->urlToType.clear();
312 data->typePropertyCaches.clear();
313 data->urlToNonFileImportType.clear();
314 data->metaObjectToType.clear();
315 data->undeletableTypes.clear();
316 data->propertyCaches.clear();
317 data->inlineComponentTypes.clear();
321 emptyComposites.
swap(
data->compositeTypes);
335 qFatal(
"qmlRegisterType(): Cannot mix incompatible QML versions.");
341 return data->parentFunctions.size() - 1;
352 if (
type.structVersion > 1)
353 qFatal(
"qmlRegisterType(): Cannot mix incompatible QML versions.");
363 data->interfaces.insert(
type.typeId.id());
401 "Invalid QML %1 name \"%2\"; "
402 "value type names should begin with a lowercase letter")
410 for (
int ii = 0; ii < typeNameLen; ++ii) {
425 "Cannot install %1 '%2' into protected module '%3' version '%4'"));
426 data->recordTypeRegFailure(failure
442 return data->addTypeModule(std::make_unique<QQmlTypeModule>(uri, version.
majorVersion()));
450 if (!
type->elementName.isEmpty())
453 if (
type->baseMetaObject)
454 data->metaObjectToType.insert(
type->baseMetaObject,
type);
457 if (
type->listId.isValid())
460 if (
type->typeId.isValid())
467 if (!
type->module.isEmpty()) {
479 qFatal(
"qmlRegisterType(): Cannot mix incompatible QML versions.");
497 if (
type.structVersion > 1)
498 qFatal(
"qmlRegisterType(): Cannot mix incompatible QML versions.");
517 if (
type.structVersion > 1)
518 qFatal(
"qmlRegisterType(): Cannot mix incompatible QML versions.");
524 bool fileImport =
false;
525 if (*(
type.uri) ==
'\0')
543 if (
type.structVersion > 1)
544 qFatal(
"qmlRegisterType(): Cannot mix incompatible QML versions.");
550 bool fileImport =
false;
551 if (*(
type.uri) ==
'\0')
574 data->setTypeRegistrationFailures(failures);
579 data->setTypeRegistrationFailures(
nullptr);
629 priv->version = version;
633 priv->extraData.singletonTypeData->singletonInstanceInfo->url =
url;
634 priv->extraData.singletonTypeData->singletonInstanceInfo->typeName =
typeName;
636 priv->extraData.compositeTypeData =
url;
649 error.setDescription(failures.join(u
'\n'));
652 qWarning(
"%s", failures.join(u
'\n').toLatin1().constData());
664 bool urlExists =
true;
666 if (found ==
data->urlToType.end()) {
668 if (found ==
data->urlToNonFileImportType.end())
673 const auto composite =
data->compositeTypes.constFind(found.value()->typeId.iface());
674 if (composite ==
data->compositeTypes.constEnd() || composite.value() == compilationUnit)
681 if (!urlExists &&
type.isValid())
692 priv->extraData.inlineComponentTypeData =
url;
715 const auto jt =
data->compositeTypes.constFind(
it->typeId().iface());
716 if (jt ==
data->compositeTypes.constEnd() || *jt == compilationUnit)
727 if (
data.isValid()) {
735 data->compositeTypes.erase(
it);
748 qFatal(
"qmlRegisterType(): Cannot mix incompatible QML versions.");
759 qFatal(
"qmlRegisterSequenceContainer(): Cannot mix incompatible QML versions.");
789 bool weakProtectAllVersions)
794 if (!weakProtectAllVersions) {
803 const auto range = std::equal_range(
804 data->uriToModule.begin(),
data->uriToModule.end(), uri,
805 std::less<ModuleUri>());
834 const auto unrevisioned =
data->moduleImports.equal_range(
836 for (
auto it = unrevisioned.second;
it != unrevisioned.first;)
840 const auto revisioned =
data->moduleImports.equal_range(
842 for (
auto it = revisioned.second;
it != revisioned.first;)
848 const auto begin =
data->moduleImports.begin();
849 auto it = unrevisioned.first;
854 if (latestVersion.
uri != uri)
859 }
while (
it !=
begin && (--
it).key() == latestVersion);
893 data->undeletableTypes.insert(dtype);
913 if (!typeNamespace.
isEmpty() && typeNamespace != uri) {
918 error.setDescription(
919 QStringLiteral(
"Module namespace '%1' does not match import URI '%2'")
920 .
arg(typeNamespace, uri));
930 if (!typeNamespace.
isEmpty()) {
937 "for type registration")
938 .
arg(typeNamespace));
946 QStringLiteral(
"Module '%1' does not contain a module identifier directive - "
947 "it cannot be protected from external registrations.").
arg(uri));
950 if (instance && !qobject_cast<QQmlEngineExtensionInterface *>(instance)) {
957 "QQmlEngineExtensionInterface").
arg(typeNamespace));
963#if QT_DEPRECATED_SINCE(6, 3)
964 if (
auto *plugin = qobject_cast<QQmlExtensionPlugin *>(instance)) {
966 QQmlExtensionPluginPrivate::get(plugin)->baseUrl
974 const char *moduleId = bytes.
constData();
975 iface->registerTypes(moduleId);
978 if (failures.isEmpty() && !
data->registerModuleTypes(uri))
981 if (!failures.isEmpty()) {
983 for (
const QString &failure : std::as_const(failures)) {
985 error.setDescription(failure);
1018 if (
ret.isValid() &&
ret.sourceUrl() ==
url)
1023 if (
ret.isValid() &&
ret.sourceUrl() ==
url)
1039 auto upper = std::upper_bound(
data->uriToModule.begin(),
data->uriToModule.end(), uri,
1040 std::less<ModuleUri>());
1041 if (upper ==
data->uriToModule.begin())
1044 const auto module = (--upper)->
get();
1045 return (module->module() == uri)
1081 if (tm->minimumMinorVersion() <= version.
minorVersion()
1082 && tm->maximumMinorVersion() >= version.
minorVersion()) {
1095 return data->findTypeModule(uri, version);
1097 auto range = std::equal_range(
data->uriToModule.begin(),
data->uriToModule.end(),
1098 uri, std::less<ModuleUri>());
1106 return data->parentFunctions;
1112 if (
ok) *
ok =
false;
1118 return *(
QObject *
const *)
v.constData();
1127 const auto iface = metaType.
iface();
1138 if (
type &&
type->listId == metaType)
1150 return type.attachedPropertiesFunction(
engine);
1155 int idx =
metaObject->indexOfClassInfo(
"DefaultProperty");
1181 int idx =
metaObject->indexOfClassInfo(
"DefaultMethod");
1211 return data->interfaces.contains(
type.id());
1218 return (
type.isInterface() &&
type.typeId() == metaType) ?
type.interfaceIId() :
nullptr;
1262 if (module.
isEmpty() ||
t.availableInVersion(module, version))
1293 if (module.
isEmpty() ||
t.availableInVersion(module, version))
1343 if (!
type.isValid() && includeNonFileImports)
1387 return data->propertyCache(
type, version);
1398 if (
auto composite =
data->findPropertyCacheInCompositeTypes(metaType))
1413 if (
auto composite =
data->findPropertyCacheInCompositeTypes(metaType))
1417 return (
type &&
type->typeId == metaType)
1430 if (
auto composite =
data->findPropertyCacheInCompositeTypes(metaType))
1434 if (
type &&
type->typeId == metaType) {
1436 return data->propertyCache(
mo,
type->version);
1456 return (
type &&
type->typeId == metaType)
1471 if (
auto composite =
data->findPropertyCacheInCompositeTypes(metaType))
1475 if (!typePriv || typePriv->
typeId != metaType)
1479 if (
type.containsRevisionedAttributes()) {
1482 return data->propertyCache(
type, version);
1503 for (
auto & module :
data->uriToModule)
1505 data->clearPropertyCachesForVersion(typeIndex);
1507 data->undeletableTypes.remove(
type);
1516 data->metaObjectToType.insert(metaobject,
type);
1521 for (
auto it =
data->inlineComponentTypes.
begin(),
end =
data->inlineComponentTypes.end();
1527 if (icPriv && icPriv->
count() > 1)
1538 if (!
data.isValid())
1541 bool deletedAtLeastOneType;
1543 deletedAtLeastOneType =
false;
1548 deletedAtLeastOneType =
true;
1560 for (
auto &module :
data->uriToModule)
1563 data->clearPropertyCachesForVersion(
d->index);
1569 }
while (deletedAtLeastOneType);
1571 bool deletedAtLeastOneCache;
1573 deletedAtLeastOneCache =
false;
1575 while (
it !=
data->propertyCaches.
end()) {
1576 if ((*it)->count() == 1) {
1578 deletedAtLeastOneCache =
true;
1583 }
while (deletedAtLeastOneCache);
1598 names +=
t.qmlTypeName();
1636 for (
const auto t : std::as_const(
data->nameToType)) {
1638 if (
type.isSingleton())
1646 quint32 numTypedFunctions = 0;
1650 ++numTypedFunctions;
1663 for (
const auto lookup : std::as_const(
data->lookupCachedQmlUnit)) {
1667 qCDebug(DBG_DISK_CACHE) <<
"Error loading pre-compiled file " << uri <<
":" <<
error;
1675 <<
"Error loading pre-compiled file " << uri
1676 <<
": compilation unit contains functions not compiled to native code.";
1697 data->lookupCachedQmlUnit.prepend(handler);
1703 data->lookupCachedQmlUnit.removeAll(handler);
1717 if (
type.isValid()) {
1720 if (lastSlash != -1)
1734 if (
type.isValid()) {
1737 if (lastSlash != -1)
1753 mo =
mo->d.superdata;
1766 clone(builder, extMetaObject, superdataBaseMetaObject, baseMetaObject,
1771 metaObjects.
constLast().metaObject->d.superdata = mmo;
1772 else if (lastMetaObject)
1775 metaObjects <<
data;
1788 createProxyMetaObject(
1789 t,
t->baseMetaObject,
t->extraData.cppTypeData->extMetaObject,
1790 t->extraData.cppTypeData->extFunc);
1792 createProxyMetaObject(
1793 t,
t->baseMetaObject,
t->extraData.singletonTypeData->extMetaObject,
1794 t->extraData.singletonTypeData->extFunc);
1807 case QMetaType::QStringList:
1808 case QMetaType::QObjectStar:
1809 case QMetaType::VoidStar:
1810 case QMetaType::Nullptr:
1812 case QMetaType::QLocale:
1813 case QMetaType::QImage:
1814 case QMetaType::QPixmap:
1831 switch (metaType.
id()) {
1832 case QMetaType::QPoint:
1833 return &QQmlPointValueType::staticMetaObject;
1834 case QMetaType::QPointF:
1835 return &QQmlPointFValueType::staticMetaObject;
1836 case QMetaType::QSize:
1837 return &QQmlSizeValueType::staticMetaObject;
1838 case QMetaType::QSizeF:
1839 return &QQmlSizeFValueType::staticMetaObject;
1840 case QMetaType::QRect:
1841 return &QQmlRectValueType::staticMetaObject;
1842 case QMetaType::QRectF:
1843 return &QQmlRectFValueType::staticMetaObject;
1844#if QT_CONFIG(easingcurve)
1845 case QMetaType::QEasingCurve:
1846 return &QQmlEasingValueType::staticMetaObject;
1877 return *
data->metaTypeToValueType.insert(
type.id(),
nullptr);
1883 return data->findPropertyCacheInCompositeTypes(
t);
1895 data->compositeTypes.insert(iface, compilationUnit);
1898 doInsert(compilationUnit->qmlType.typeId().iface());
1899 for (
auto &&inlineData: compilationUnit->inlineComponentData)
1900 doInsert(inlineData.qmlType.typeId().iface());
1914 data->compositeTypes.erase(
it);
1917 doRemove(compilationUnit->qmlType.typeId().iface());
1918 for (
auto &&inlineData: compilationUnit->inlineComponentData)
1919 doRemove(inlineData.qmlType.typeId().iface());
1937 doCheck(compilationUnit->qmlType.typeId().iface());
1938 for (
auto &&inlineData: compilationUnit->inlineComponentData)
1939 doCheck(inlineData.qmlType.typeId().iface());
1948 return data->compositeTypes.value(
type.iface());
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
static QString translate(const char *context, const char *key, const char *disambiguation=nullptr, int n=-1)
\threadsafe
\inmodule QtCore\reentrant
void swap(QHash &other) noexcept
int indexOf(const QChar &, int from=0) const
const QChar * constData() const
bool isEmpty() const noexcept
const T & constLast() const noexcept
void prepend(rvalue_ref t)
void append(parameter_type t)
const_iterator ConstIterator
static QObjectPrivate * get(QObject *o)
The QQmlCustomParser class allows you to add new arbitrary types to QML.
The QQmlError class encapsulates a QML error.
static QUrl urlFromLocalFileOrQrcOrUrl(const QString &)
static QUrl normalize(const QUrl &unNormalizedUrl)
LockLevel lockLevel() const
QQmlType type(const QHashedStringRef &name, QTypeRevision version) const
void addMinorVersion(quint8 minorVersion)
void add(QQmlTypePrivate *)
const QMetaObject * baseMetaObject
@ SequentialContainerType
const QMetaObject * metaObject() const
const_iterator cend() const noexcept
const_iterator constEnd() const noexcept
iterator erase(const_iterator i)
const_iterator constFind(const T &value) const
const_iterator cbegin() const noexcept
iterator insert(const T &value)
\macro QT_RESTRICTED_CAST_FROM_ASCII
const QChar * constData() const
Returns a pointer to the data stored in the QString.
qsizetype size() const
Returns the number of characters in this string.
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QString arg(qlonglong a, int fieldwidth=0, int base=10, QChar fillChar=u' ') const
static QString fromRawData(const QChar *, qsizetype size)
Constructs a QString that uses the first size Unicode characters in the array unicode.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
static QString static QString qsizetype indexOf(QChar c, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
QByteArray toUtf8() const &
static constexpr QTypeRevision fromVersion(Major majorVersion, Minor minorVersion)
Produces a QTypeRevision from the given majorVersion and minorVersion, both of which need to be a val...
constexpr bool hasMinorVersion() const
Returns true if the minor version is known, otherwise false.
constexpr bool hasMajorVersion() const
Returns true if the major version is known, otherwise false.
constexpr quint8 minorVersion() const
Returns the minor version encoded in the revision.
constexpr quint8 majorVersion() const
Returns the major version encoded in the revision.
QString fragment(ComponentFormattingOptions options=PrettyDecoded) const
Returns the fragment of the URL.
static bool verifyHeader(const CompiledData::Unit *unit, QDateTime expectedSourceTimeStamp, QString *errorString)
QSet< QString >::iterator it
const CachedQmlUnit *(* QmlUnitCacheLookupFunction)(const QUrl &url)
AutoParentResult(* AutoParentFunction)(QObject *object, QObject *parent)
Combined button and popup list for selecting options.
Q_CORE_EXPORT int qstrcmp(const char *str1, const char *str2)
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction function
DBusConnection const char DBusError * error
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char * method
static QDBusError::ErrorType get(const char *name)
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
#define Q_LOGGING_CATEGORY(name,...)
#define qCWarning(category,...)
#define qCDebug(category,...)
#define Q_DECLARE_LOGGING_CATEGORY(name)
static ControlElement< T > * ptr(QWidget *widget)
GLsizei const GLfloat * v
[13]
GLsizei GLenum GLenum * types
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint GLenum GLboolean normalized
GLsizei const GLchar *const * string
[0]
static qreal dot(const QPointF &a, const QPointF &b)
int qmlTypeId(const char *uri, int versionMajor, int versionMinor, const char *qmlName)
QQmlPrivate::QQmlAttachedPropertiesFunc< QObject > QQmlAttachedPropertiesFunc
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
static QLatin1StringView typeStr(QShaderDescription::VariableType t)
#define qPrintable(string)
QLatin1StringView QLatin1String
#define QStringLiteral(str)
const char className[16]
[1]
QFileInfo info(fileName)
[8]
QUrl url("example.com")
[constructor-url-reference]
obj metaObject() -> className()
ModuleUri(const std::unique_ptr< QQmlTypeModule > &module)
ModuleUri(const QString &string)
\inmodule QtCore \reentrant
const AOTCompiledFunction * aotCompiledFunctions
const QV4::CompiledData::Unit * qmlData
QmlUnitCacheLookupFunction lookupCachedQmlUnit
QMetaSequence metaSequence
static QByteArray createClassNameTypeByUrl(const QUrl &url)
static QByteArray createClassNameForInlineComponent(const QUrl &baseUrl, const QString &name)
quint32_le functionTableSize