From c400b7765ff5204edf9243387f1928a770985382 Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Mon, 19 Aug 2019 17:16:39 +0200 Subject: qqml.h: add qmlRegisterAnonymousType This version behaves for the most part like qmlRegisterType(), but it adds a uri and major version, which qmlplugindump can use to put the tpyes into the correct plugins.qmltyes file. Change-Id: I50f620216439a3edc66ac740cb051c2fbb936e51 Reviewed-by: Ulf Hermann --- src/imports/testlib/main.cpp | 2 +- src/qml/doc/src/qmlfunctions.qdoc | 10 +++++++++ src/qml/qml/qqml.h | 10 +++++++-- src/qmlmodels/qqmlmodelsmodule.cpp | 6 +++--- src/quick/items/qquickitemsmodule.cpp | 40 +++++++++++++++++------------------ src/quick/util/qquickutilmodule.cpp | 4 ++-- 6 files changed, 44 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/imports/testlib/main.cpp b/src/imports/testlib/main.cpp index fbaf3bc4e2..33fe912692 100644 --- a/src/imports/testlib/main.cpp +++ b/src/imports/testlib/main.cpp @@ -150,7 +150,7 @@ public: qmlRegisterType(uri,1,0,"TestEvent"); qmlRegisterType(uri,1,2,"TestEvent"); qmlRegisterType(uri,1,0,"TestUtil"); - qmlRegisterType(); + qmlRegisterAnonymousType(uri); // Auto-increment the import to stay in sync with ALL future QtQuick minor versions from 5.11 onward qmlRegisterModule(uri, 1, QT_VERSION_MINOR); diff --git a/src/qml/doc/src/qmlfunctions.qdoc b/src/qml/doc/src/qmlfunctions.qdoc index 9c106558fd..c71d18418a 100644 --- a/src/qml/doc/src/qmlfunctions.qdoc +++ b/src/qml/doc/src/qmlfunctions.qdoc @@ -273,6 +273,16 @@ {Choosing the Correct Integration Method Between C++ and QML} */ +/*! + \fn int qmlRegisterAnonymousType(const char *uri, int versionMajor) + + This template function registers the C++ type in the QML system. Instances of this type cannot be created from the QML system. + + Use this function when the type will not be referenced by name. Use \a uri and \a versionMajor to indicate to which module the type belongs. + + \sa {Choosing the Correct Integration Method Between C++ and QML} +*/ + /*! \fn int qmlRegisterType() \relates QQmlEngine diff --git a/src/qml/qml/qqml.h b/src/qml/qml/qqml.h index bfd1c88b28..a93b012c70 100644 --- a/src/qml/qml/qqml.h +++ b/src/qml/qml/qqml.h @@ -102,7 +102,7 @@ class QQmlPropertyValueInterceptor; void Q_QML_EXPORT qmlClearTypeRegistrations(); template -int qmlRegisterType() +int qmlRegisterAnonymousType(const char *uri, int versionMajor=1) { QML_GETTYPENAMES @@ -115,7 +115,7 @@ int qmlRegisterType() nullptr, QString(), - nullptr, 0, 0, nullptr, &T::staticMetaObject, + uri, versionMajor, 0, nullptr, &T::staticMetaObject, QQmlPrivate::attachedPropertiesFunc(), QQmlPrivate::attachedPropertiesMetaObject(), @@ -133,6 +133,12 @@ int qmlRegisterType() return QQmlPrivate::qmlregister(QQmlPrivate::TypeRegistration, &type); } +template +QT_DEPRECATED_VERSION_X_5_14("Use qmlRegisterAnonymousType instead") int qmlRegisterType() +{ + return qmlRegisterAnonymousType(""); +} + int Q_QML_EXPORT qmlRegisterTypeNotAvailable(const char *uri, int versionMajor, int versionMinor, const char *qmlName, const QString& message); template diff --git a/src/qmlmodels/qqmlmodelsmodule.cpp b/src/qmlmodels/qqmlmodelsmodule.cpp index 2db5dd834f..d569d8e23c 100644 --- a/src/qmlmodels/qqmlmodelsmodule.cpp +++ b/src/qmlmodels/qqmlmodelsmodule.cpp @@ -69,7 +69,7 @@ void QQmlModelsModule::registerQmlTypes() // Don't add anything here. These are only for backwards compatibility. #if QT_CONFIG(qml_object_model) qmlRegisterType("QtQml", 2, 1, "Instantiator"); // Only available in >= 2.1 - qmlRegisterType(); + qmlRegisterAnonymousType("QtQml", 2); #endif } @@ -81,7 +81,7 @@ void QQmlModelsModule::registerQuickTypes() #if QT_CONFIG(qml_object_model) qmlRegisterType(uri, 2, 1, "Instantiator"); - qmlRegisterType(); + qmlRegisterAnonymousType(uri, 2); qmlRegisterType(uri, 2, 0, "VisualItemModel"); #endif #if QT_CONFIG(qml_list_model) @@ -114,7 +114,7 @@ void QQmlModelsModule::defineModule() qmlRegisterType(uri, 2, 1, "ObjectModel"); qmlRegisterType(uri, 2, 3, "ObjectModel"); qmlRegisterType(uri, 2, 14, "Instantiator"); - qmlRegisterType(); + qmlRegisterAnonymousType(uri, 2); #endif #if QT_CONFIG(itemmodel) qmlRegisterType(uri, 2, 2, "ItemSelectionModel"); diff --git a/src/quick/items/qquickitemsmodule.cpp b/src/quick/items/qquickitemsmodule.cpp index 33c4fae96d..d8ad104a6d 100644 --- a/src/quick/items/qquickitemsmodule.cpp +++ b/src/quick/items/qquickitemsmodule.cpp @@ -247,27 +247,27 @@ static void qt_quickitems_defineModule(const char *uri, int major, int minor) qmlRegisterType(uri,major,minor,"TextInput"); qmlRegisterType(uri,2,2,"TextInput"); qmlRegisterType(uri,2,4,"TextInput"); - qmlRegisterType(); + qmlRegisterAnonymousType(uri, major); #if QT_CONFIG(quick_shadereffect) - qmlRegisterType(); -#endif - qmlRegisterType(); - qmlRegisterType(); - qmlRegisterType(); - qmlRegisterType(); - qmlRegisterType(); - qmlRegisterType(); + qmlRegisterAnonymousType(uri, major); +#endif + qmlRegisterAnonymousType(uri, major); + qmlRegisterAnonymousType(uri, major); + qmlRegisterAnonymousType(uri, major); + qmlRegisterAnonymousType(uri, major); + qmlRegisterAnonymousType(uri, major); + qmlRegisterAnonymousType(uri, major); #if QT_CONFIG(quick_path) - qmlRegisterType(); - qmlRegisterType(); + qmlRegisterAnonymousType(uri, major); + qmlRegisterAnonymousType(uri, major); #endif - qmlRegisterType(); - qmlRegisterType(); - qmlRegisterType(); - qmlRegisterType(); + qmlRegisterAnonymousType(uri, major); + qmlRegisterAnonymousType(uri, major); + qmlRegisterAnonymousType(uri, major); + qmlRegisterAnonymousType(uri, major); qRegisterMetaType("QQuickAnchorLine"); - qmlRegisterType(); + qmlRegisterAnonymousType(uri, major); qmlRegisterUncreatableType(uri,major,minor,"KeyNavigation",QQuickKeyNavigationAttached::tr("KeyNavigation is only available via attached properties")); @@ -279,7 +279,7 @@ static void qt_quickitems_defineModule(const char *uri, int major, int minor) qmlRegisterType(uri,major,minor,"PinchArea"); qmlRegisterType(uri,major,minor,"Pinch"); - qmlRegisterType(); + qmlRegisterAnonymousType(uri, major); #if QT_CONFIG(quick_shadereffect) qmlRegisterType("QtQuick", 2, 0, "ShaderEffectSource"); @@ -302,7 +302,7 @@ static void qt_quickitems_defineModule(const char *uri, int major, int minor) qmlRegisterType(uri, major, minor,"ParentChange"); qmlRegisterType(uri, major, minor,"AnchorChanges"); - qmlRegisterType(); + qmlRegisterAnonymousType(uri, major); qmlRegisterType(uri, major, minor,"AnchorAnimation"); qmlRegisterType(uri, major, minor,"ParentAnimation"); #if QT_CONFIG(quick_path) @@ -312,8 +312,8 @@ static void qt_quickitems_defineModule(const char *uri, int major, int minor) #if QT_CONFIG(quick_draganddrop) qmlRegisterType("QtQuick", 2, 0, "DropArea"); - qmlRegisterType(); - qmlRegisterType(); + qmlRegisterAnonymousType(uri, 2); + qmlRegisterAnonymousType(uri, 2); qmlRegisterUncreatableType("QtQuick", 2, 0, "Drag", QQuickDragAttached::tr("Drag is only available via attached properties")); #endif diff --git a/src/quick/util/qquickutilmodule.cpp b/src/quick/util/qquickutilmodule.cpp index d222a0c0be..7c8134ba6f 100644 --- a/src/quick/util/qquickutilmodule.cpp +++ b/src/quick/util/qquickutilmodule.cpp @@ -99,7 +99,7 @@ void QQuickUtilModule::defineModule() qmlRegisterType("QtQuick",2,0,"Vector3dAnimation"); #if QT_CONFIG(validator) - qmlRegisterType(); + qmlRegisterAnonymousType("QtQuick", 2); qmlRegisterType("QtQuick",2,0,"IntValidator"); qmlRegisterType("QtQuick",2,0,"DoubleValidator"); qmlRegisterType("QtQuick",2,0,"RegExpValidator"); @@ -117,7 +117,7 @@ void QQuickUtilModule::defineModule() #if QT_CONFIG(quick_shadereffect) && QT_CONFIG(opengl) qmlRegisterType("QtQuick", 2, 2, "UniformAnimator"); #endif - qmlRegisterType(); + qmlRegisterAnonymousType("QtQuick", 2); qmlRegisterCustomType("QtQuick",2,0,"PropertyChanges", new QQuickPropertyChangesParser); -- cgit v1.2.3