diff options
Diffstat (limited to 'src/qml/qml/qqmlmetatype.cpp')
-rw-r--r-- | src/qml/qml/qqmlmetatype.cpp | 74 |
1 files changed, 48 insertions, 26 deletions
diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp index 1a5affb0ad..c21247bb95 100644 --- a/src/qml/qml/qqmlmetatype.cpp +++ b/src/qml/qml/qqmlmetatype.cpp @@ -267,6 +267,23 @@ void QQmlMetaType::clone(QMetaObjectBuilder &builder, const QMetaObject *mo, } } +void QQmlMetaType::qmlInsertModuleRegistration(const QString &uri, int majorVersion, + void (*registerFunction)()) +{ + const QQmlMetaTypeData::VersionedUri versionedUri(uri, majorVersion); + QQmlMetaTypeDataPtr data; + if (data->moduleTypeRegistrationFunctions.contains(versionedUri)) + qFatal("Canot add multiple registrations for %s %d", qPrintable(uri), majorVersion); + else + data->moduleTypeRegistrationFunctions.insert(versionedUri, registerFunction); +} + +void QQmlMetaType::qmlRegisterModuleTypes(const QString &uri, int majorVersion) +{ + QQmlMetaTypeDataPtr data; + data->registerModuleTypes(QQmlMetaTypeData::VersionedUri(uri, majorVersion)); +} + void QQmlMetaType::clearTypeRegistrations() { //Only cleans global static, assumed no running engine @@ -633,17 +650,6 @@ bool QQmlMetaType::registerPluginTypes(QObject *instance, const QString &basePat const QString &uri, const QString &typeNamespace, int vmaj, QList<QQmlError> *errors) { - QQmlTypesExtensionInterface *iface = qobject_cast<QQmlTypesExtensionInterface *>(instance); - if (!iface) { - if (errors) { - QQmlError error; - error.setDescription(QStringLiteral("Module loaded for URI '%1' does not implement " - "QQmlTypesExtensionInterface").arg(typeNamespace)); - errors->prepend(error); - } - return false; - } - if (!typeNamespace.isEmpty() && typeNamespace != uri) { // This is an 'identified' module // The namespace for type registrations must match the URI for locating the module @@ -681,26 +687,42 @@ bool QQmlMetaType::registerPluginTypes(QObject *instance, const QString &basePat "it cannot be protected from external registrations.").arg(uri)); } - if (auto *plugin = qobject_cast<QQmlExtensionPlugin *>(instance)) { - // basepath should point to the directory of the module, not the plugin file itself: - QQmlExtensionPluginPrivate::get(plugin)->baseUrl - = QQmlImports::urlFromLocalFileOrQrcOrUrl(basePath); + if (!qobject_cast<QQmlEngineExtensionInterface *>(instance)) { + QQmlTypesExtensionInterface *iface = qobject_cast<QQmlTypesExtensionInterface *>(instance); + if (!iface) { + if (errors) { + QQmlError error; + // Also does not implement QQmlTypesExtensionInterface, but we want to discourage that. + error.setDescription(QStringLiteral("Module loaded for URI '%1' does not implement " + "QQmlEngineExtensionInterface").arg(typeNamespace)); + errors->prepend(error); + } + return false; + } + + if (auto *plugin = qobject_cast<QQmlExtensionPlugin *>(instance)) { + // basepath should point to the directory of the module, not the plugin file itself: + QQmlExtensionPluginPrivate::get(plugin)->baseUrl + = QQmlImports::urlFromLocalFileOrQrcOrUrl(basePath); + } + + const QByteArray bytes = uri.toUtf8(); + const char *moduleId = bytes.constData(); + iface->registerTypes(moduleId); } - const QByteArray bytes = uri.toUtf8(); - const char *moduleId = bytes.constData(); - iface->registerTypes(moduleId); - } + data->registerModuleTypes(QQmlMetaTypeData::VersionedUri(uri, vmaj)); - if (!failures.isEmpty()) { - if (errors) { - for (const QString &failure : qAsConst(failures)) { - QQmlError error; - error.setDescription(failure); - errors->prepend(error); + if (!failures.isEmpty()) { + if (errors) { + for (const QString &failure : qAsConst(failures)) { + QQmlError error; + error.setDescription(failure); + errors->prepend(error); + } } + return false; } - return false; } return true; |