diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2016-10-20 15:42:27 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2016-11-18 18:57:53 +0000 |
commit | c56cc0c6c229b01811cf41fe2ea02dc3194feaab (patch) | |
tree | b813baceae47205b20083da13600920b9c351962 /src/qml | |
parent | 0cbda65924ff5440bf283aa7a988f335bba4e660 (diff) |
Introduce qmlRegisterModule()
This is particularly useful for keeping the versions of related modules in
sync. For example, when QtQuick.Controls introduces new types or revisions
and bumps up the minor version, qmlRegisterModule() can be used to make the
same version available for QtQuick.Controls.Styles in case it doesn't have
new types or revisions to register.
[ChangeLog][QtQml] Introduced qmlRegisterModule() that can be used to
make a certain module version available, even if no types or revisions
are registered for that version.
Change-Id: I5ec457465cd778bb0adda55771d195f69cd4b31a
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml')
-rw-r--r-- | src/qml/doc/src/qmlfunctions.qdoc | 12 | ||||
-rw-r--r-- | src/qml/qml/qqml.h | 1 | ||||
-rw-r--r-- | src/qml/qml/qqmlmetatype.cpp | 36 | ||||
-rw-r--r-- | src/qml/qml/qqmlmetatype_p.h | 1 |
4 files changed, 43 insertions, 7 deletions
diff --git a/src/qml/doc/src/qmlfunctions.qdoc b/src/qml/doc/src/qmlfunctions.qdoc index 8b24d19891..a03c382ed5 100644 --- a/src/qml/doc/src/qmlfunctions.qdoc +++ b/src/qml/doc/src/qmlfunctions.qdoc @@ -544,3 +544,15 @@ in order to be found. */ +/*! + \since 5.9 + \fn void qmlRegisterModule(const char* uri, int versionMajor, int versionMinor); + \relates QQmlEngine + + This function registers a module in a particular \a uri with a version specified + in \a versionMajor and \a versionMinor. + + This can be used to make a certain module version available, even if no types + are registered for that version. This is particularly useful for keeping the + versions of related modules in sync. +*/ diff --git a/src/qml/qml/qqml.h b/src/qml/qml/qqml.h index 39764b8001..f0973338ea 100644 --- a/src/qml/qml/qqml.h +++ b/src/qml/qml/qqml.h @@ -526,6 +526,7 @@ QT_WARNING_POP //The C++ version of protected namespaces in qmldir Q_QML_EXPORT bool qmlProtectModule(const char* uri, int majVersion); +Q_QML_EXPORT void qmlRegisterModule(const char *uri, int versionMajor, int versionMinor); template<typename T> QObject *qmlAttachedPropertiesObject(const QObject *obj, bool create = true) diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp index 7b758566b7..6a1a90f031 100644 --- a/src/qml/qml/qqmlmetatype.cpp +++ b/src/qml/qml/qqmlmetatype.cpp @@ -1268,6 +1268,19 @@ bool checkRegistration(QQmlType::RegistrationType typeType, QQmlMetaTypeData *da } // NOTE: caller must hold a QMutexLocker on "data" +QQmlTypeModule *getTypeModule(const QHashedString &uri, int majorVersion, QQmlMetaTypeData *data) +{ + QQmlMetaTypeData::VersionedUri versionedUri(uri, majorVersion); + QQmlTypeModule *module = data->uriToModule.value(versionedUri); + if (!module) { + module = new QQmlTypeModule; + module->d->uri = versionedUri; + data->uriToModule.insert(versionedUri, module); + } + return module; +} + +// NOTE: caller must hold a QMutexLocker on "data" void addTypeToData(QQmlType* type, QQmlMetaTypeData *data) { if (!type->elementName().isEmpty()) @@ -1293,13 +1306,8 @@ void addTypeToData(QQmlType* type, QQmlMetaTypeData *data) if (!type->module().isEmpty()) { const QHashedString &mod = type->module(); - QQmlMetaTypeData::VersionedUri versionedUri(mod, type->majorVersion()); - QQmlTypeModule *module = data->uriToModule.value(versionedUri); - if (!module) { - module = new QQmlTypeModule; - module->d->uri = versionedUri; - data->uriToModule.insert(versionedUri, module); - } + QQmlTypeModule *module = getTypeModule(mod, type->majorVersion(), data); + Q_ASSERT(module); module->d->add(type); } } @@ -1442,6 +1450,20 @@ bool qmlProtectModule(const char *uri, int majVersion) return false; } +//From qqml.h +void qmlRegisterModule(const char *uri, int versionMajor, int versionMinor) +{ + QMutexLocker lock(metaTypeDataLock()); + QQmlMetaTypeData *data = metaTypeData(); + + QQmlTypeModule *module = getTypeModule(QString::fromUtf8(uri), versionMajor, data); + Q_ASSERT(module); + + QQmlTypeModulePrivate *p = QQmlTypeModulePrivate::get(module); + p->minMinorVersion = qMin(p->minMinorVersion, versionMinor); + p->maxMinorVersion = qMax(p->maxMinorVersion, versionMinor); +} + bool QQmlMetaType::namespaceContainsRegistrations(const QString &uri, int majorVersion) { const QQmlMetaTypeData *data = metaTypeData(); diff --git a/src/qml/qml/qqmlmetatype_p.h b/src/qml/qml/qqmlmetatype_p.h index cc0e0ad71e..2b615e645a 100644 --- a/src/qml/qml/qqmlmetatype_p.h +++ b/src/qml/qml/qqmlmetatype_p.h @@ -266,6 +266,7 @@ public: private: //Used by register functions and creates the QQmlTypeModule for them + friend QQmlTypeModule *getTypeModule(const QHashedString &uri, int majorVersion, QQmlMetaTypeData *data); friend void addTypeToData(QQmlType* type, QQmlMetaTypeData *data); friend struct QQmlMetaTypeData; friend Q_QML_EXPORT void qmlClearTypeRegistrations(); |