QmlDesigner: Don't export enumerations as qml types

Qml types can be derived. So we have to use a different mechnanism because
otherwise we have to export a enumeration type for every derived class too.

Task-number: QDS-6182
Change-Id: Ib3ab3629328511e932f4d8cd360cbe3b01369d8f
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Marco Bubke
2022-02-14 11:36:07 +01:00
parent 6531a68f55
commit 04451df763
2 changed files with 26 additions and 30 deletions

View File

@@ -99,28 +99,34 @@ Storage::Version createVersion(QTypeRevision qmlVersion)
Storage::ExportedTypes createExports(const QList<QQmlJSScope::Export> &qmlExports,
Utils::SmallStringView interanalName,
QmlTypesParser::ProjectStorage &storage,
ModuleId cppModuleId,
Utils::SmallStringView typeNameAppendix = {})
ModuleId cppModuleId)
{
Storage::ExportedTypes exportedTypes;
exportedTypes.reserve(Utils::usize(qmlExports));
for (const QQmlJSScope::Export &qmlExport : qmlExports) {
Utils::SmallString exportedTypeName{qmlExport.type()};
if (!typeNameAppendix.empty()) {
exportedTypeName += ".";
exportedTypeName += typeNameAppendix;
}
exportedTypes.emplace_back(storage.moduleId(Utils::SmallString{qmlExport.package()}),
std::move(exportedTypeName),
createVersion(qmlExport.version()));
}
Utils::SmallString cppExportedTypeName{interanalName};
if (!typeNameAppendix.empty()) {
cppExportedTypeName += "::";
cppExportedTypeName += typeNameAppendix;
}
exportedTypes.emplace_back(cppModuleId, cppExportedTypeName);
return exportedTypes;
}
Storage::ExportedTypes createCppEnumerationExports(Utils::SmallStringView interanalName,
ModuleId cppModuleId,
Utils::SmallStringView enumeration)
{
Storage::ExportedTypes exportedTypes;
exportedTypes.reserve(1);
Utils::SmallString cppExportedTypeName{interanalName};
cppExportedTypeName += "::";
cppExportedTypeName += enumeration;
exportedTypes.emplace_back(cppModuleId, cppExportedTypeName);
@@ -283,12 +289,14 @@ EnumerationTypes addEnumerationTypes(Storage::Types &types,
for (const QQmlJSMetaEnum &qmlEnumeration : qmlEnumerations) {
Utils::SmallString enumerationName{qmlEnumeration.name()};
auto fullTypeName = Utils::SmallString::join({typeName, "::", enumerationName});
auto &type = types.emplace_back(
fullTypeName,
Storage::ImportedType{Utils::SmallString{}},
Storage::TypeAccessSemantics::Value | Storage::TypeAccessSemantics::IsEnum,
sourceId,
createExports(qmlExports, typeName, storage, cppModuleId, enumerationName));
auto &type = types.emplace_back(fullTypeName,
Storage::ImportedType{Utils::SmallString{}},
Storage::TypeAccessSemantics::Value
| Storage::TypeAccessSemantics::IsEnum,
sourceId,
createCppEnumerationExports(typeName,
cppModuleId,
enumerationName));
enumerationTypes.emplace_back(enumerationName, std::move(fullTypeName));
}

View File

@@ -428,13 +428,7 @@ TEST_F(QmlTypesParser, EnumerationIsExportedAsType)
Storage::TypeAccessSemantics::Value | Storage::TypeAccessSemantics::IsEnum,
qmltypesFileSourceId),
Field(&Storage::Type::exportedTypes,
UnorderedElementsAre(IsExportedType(qmlModuleId,
"QtObject.NamedColorSpace",
Storage::Version{1, 0}),
IsExportedType(qtQmlModuleId,
"QtObject.NamedColorSpace",
Storage::Version{2, 1}),
IsExportedType(qtQmlNativeModuleId,
UnorderedElementsAre(IsExportedType(qtQmlNativeModuleId,
"QObject::NamedColorSpace",
Storage::Version{})))),
AllOf(IsType("QObject::VerticalLayoutDirection",
@@ -442,13 +436,7 @@ TEST_F(QmlTypesParser, EnumerationIsExportedAsType)
Storage::TypeAccessSemantics::Value | Storage::TypeAccessSemantics::IsEnum,
qmltypesFileSourceId),
Field(&Storage::Type::exportedTypes,
UnorderedElementsAre(IsExportedType(qmlModuleId,
"QtObject.VerticalLayoutDirection",
Storage::Version{1, 0}),
IsExportedType(qtQmlModuleId,
"QtObject.VerticalLayoutDirection",
Storage::Version{2, 1}),
IsExportedType(qtQmlNativeModuleId,
UnorderedElementsAre(IsExportedType(qtQmlNativeModuleId,
"QObject::VerticalLayoutDirection",
Storage::Version{})))),
_));