qmljs: Handle qmlRegisterSingletonInstance

Parse qmlRegisterSingletonInstance to support types created this way in
QML.

Change-Id: I08440de52097faae5fd05ab32157279ee2ca2942
Reviewed-by: Kevin Funk <kevin.funk@kdab.com>
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@qt.io>
This commit is contained in:
Kevin Funk
2020-12-03 21:04:28 +01:00
committed by Fawzi Mohamed
parent e2668f4bbf
commit 34e20e641f

View File

@@ -79,6 +79,8 @@ public:
QmlRegisterType4, QmlRegisterType4,
// int qmlRegisterType(const QUrl & url, const char * uri, int versionMajor, int versionMinor, const char * qmlName) // int qmlRegisterType(const QUrl & url, const char * uri, int versionMajor, int versionMinor, const char * qmlName)
QmlRegisterType5, QmlRegisterType5,
// template<typename T> inline auto qmlRegisterSingletonInstance(const char *uri, int versionMajor, int versionMinor, const char *typeName, T *cppObject)
QmlRegisterSingletonInstance,
// template<typename T> int qmlRegisterSingletonType(const char * uri, int versionMajor, int versionMinor, const char * typeName, QObject *(* ) ( QQmlEngine *, QJSEngine * ) callback) // template<typename T> int qmlRegisterSingletonType(const char * uri, int versionMajor, int versionMinor, const char * typeName, QObject *(* ) ( QQmlEngine *, QJSEngine * ) callback)
QmlRegisterSingletonTypeCallback1, QmlRegisterSingletonTypeCallback1,
// int qmlRegisterSingletonType(const char * uri, int versionMajor, int versionMinor, const char * typeName, QJSValue(* ) ( QQmlEngine *, QJSEngine * ) callback) // int qmlRegisterSingletonType(const char * uri, int versionMajor, int versionMinor, const char * typeName, QJSValue(* ) ( QQmlEngine *, QJSEngine * ) callback)
@@ -156,6 +158,8 @@ protected:
const QByteArray callName(templateIdentifier->chars()); const QByteArray callName(templateIdentifier->chars());
if (callName == "qmlRegisterType") if (callName == "qmlRegisterType")
registrationFunction = QmlRegisterType4; registrationFunction = QmlRegisterType4;
else if (callName == "qmlRegisterSingletonInstance")
registrationFunction = QmlRegisterSingletonInstance;
else if (callName == "qmlRegisterSingletonType") else if (callName == "qmlRegisterSingletonType")
registrationFunction = QmlRegisterSingletonTypeCallback1; registrationFunction = QmlRegisterSingletonTypeCallback1;
else if (callName == "qmlRegisterUncreatableType") else if (callName == "qmlRegisterUncreatableType")
@@ -189,6 +193,8 @@ protected:
} }
if (fName == "qmlRegisterType") if (fName == "qmlRegisterType")
registrationFunction = QmlRegisterType5; registrationFunction = QmlRegisterType5;
else if (fName == "qmlRegisterSingletonInstance") // when called without explicit template parameter
registrationFunction = QmlRegisterSingletonInstance;
else if (fName == "qmlRegisterSingletonType") else if (fName == "qmlRegisterSingletonType")
registrationFunction = QmlRegisterSingletonTypeCallback2; registrationFunction = QmlRegisterSingletonTypeCallback2;
else if (fName == "qmlRegisterUncreatableMetaObject") else if (fName == "qmlRegisterUncreatableMetaObject")
@@ -214,6 +220,7 @@ protected:
case QmlRegisterType4: case QmlRegisterType4:
break; break;
case QmlRegisterType5: case QmlRegisterType5:
case QmlRegisterSingletonInstance:
case QmlRegisterSingletonTypeCallback1: case QmlRegisterSingletonTypeCallback1:
case QmlRegisterSingletonTypeCallback2: case QmlRegisterSingletonTypeCallback2:
case QmlRegisterSingletonTypeUrl: case QmlRegisterSingletonTypeUrl:
@@ -342,7 +349,8 @@ protected:
// build the descriptor // build the descriptor
ExportedQmlType exportedType; ExportedQmlType exportedType;
exportedType.isSingleton = registrationFunction == QmlRegisterSingletonTypeCallback1 exportedType.isSingleton = registrationFunction == QmlRegisterSingletonInstance
|| registrationFunction == QmlRegisterSingletonTypeCallback1
|| registrationFunction == QmlRegisterSingletonTypeCallback2 || registrationFunction == QmlRegisterSingletonTypeCallback2
|| registrationFunction == QmlRegisterSingletonTypeUrl; || registrationFunction == QmlRegisterSingletonTypeUrl;
exportedType.isCreatable = !exportedType.isSingleton exportedType.isCreatable = !exportedType.isSingleton
@@ -916,6 +924,7 @@ bool FindExportedCppTypes::maybeExportsTypes(const CPlusPlus::Document::Ptr &doc
if (!document->control()) if (!document->control())
return false; return false;
const QByteArray tokens[] = { const QByteArray tokens[] = {
"qmlRegisterSingletonInstance",
"qmlRegisterSingletonType", "qmlRegisterSingletonType",
"qmlRegisterType", "qmlRegisterType",
"qmlRegisterUncreatableType", "qmlRegisterUncreatableType",