forked from qt-creator/qt-creator
QmlDesigner: Improve alias enumeration referencing in properties
If an alias enumeration is referenced in properties it should be fully qualified too. Task-number: QDS-6768 Change-Id: I9fa739b43315c761ae1d026eb6d3ddce386d7ddc Reviewed-by: Henning Gründl <henning.gruendl@qt.io>
This commit is contained in:
@@ -331,6 +331,16 @@ Storage::EnumerationDeclarations createEnumeration(const QHash<QString, QQmlJSMe
|
||||
return enumerationDeclarations;
|
||||
}
|
||||
|
||||
Utils::SmallString addEnumerationType(EnumerationTypes &enumerationTypes,
|
||||
Utils::SmallStringView typeName,
|
||||
Utils::SmallStringView enumerationName)
|
||||
{
|
||||
auto fullTypeName = Utils::SmallString::join({typeName, "::", enumerationName});
|
||||
enumerationTypes.emplace_back(enumerationName, std::move(fullTypeName));
|
||||
|
||||
return fullTypeName;
|
||||
}
|
||||
|
||||
void addEnumerationType(EnumerationTypes &enumerationTypes,
|
||||
Storage::Types &types,
|
||||
Utils::SmallStringView typeName,
|
||||
@@ -339,7 +349,7 @@ void addEnumerationType(EnumerationTypes &enumerationTypes,
|
||||
ModuleId cppModuleId,
|
||||
Utils::SmallStringView enumerationAlias)
|
||||
{
|
||||
auto fullTypeName = Utils::SmallString::join({typeName, "::", enumerationName});
|
||||
auto fullTypeName = addEnumerationType(enumerationTypes, typeName, enumerationName);
|
||||
types.emplace_back(fullTypeName,
|
||||
Storage::ImportedType{Utils::SmallString{}},
|
||||
Storage::TypeAccessSemantics::Value | Storage::TypeAccessSemantics::IsEnum,
|
||||
@@ -348,7 +358,9 @@ void addEnumerationType(EnumerationTypes &enumerationTypes,
|
||||
cppModuleId,
|
||||
enumerationName,
|
||||
enumerationAlias));
|
||||
enumerationTypes.emplace_back(enumerationName, std::move(fullTypeName));
|
||||
|
||||
if (!enumerationAlias.empty())
|
||||
addEnumerationType(enumerationTypes, typeName, enumerationAlias);
|
||||
}
|
||||
|
||||
QSet<QString> createEnumerationAliases(const QHash<QString, QQmlJSMetaEnum> &qmlEnumerations)
|
||||
|
@@ -632,4 +632,32 @@ TEST_F(QmlTypesParser, EnumerationIsReferencedByQualifiedName)
|
||||
Storage::PropertyDeclarationTraits::None)))));
|
||||
}
|
||||
|
||||
TEST_F(QmlTypesParser, AliasEnumerationIsReferencedByQualifiedName)
|
||||
{
|
||||
QString source{R"(import QtQuick.tooling 1.2
|
||||
Module{
|
||||
Component { name: "QObject"
|
||||
Property { name: "colorSpace"; type: "NamedColorSpaces" }
|
||||
Enum {
|
||||
name: "NamedColorSpace"
|
||||
alias: "NamedColorSpaces"
|
||||
values: [
|
||||
"Unknown",
|
||||
"SRgb",
|
||||
"AdobeRgb",
|
||||
"DisplayP3",
|
||||
]
|
||||
}
|
||||
}})"};
|
||||
|
||||
parser.parse(source, imports, types, projectData);
|
||||
|
||||
ASSERT_THAT(types,
|
||||
Contains(Field(&Storage::Type::propertyDeclarations,
|
||||
ElementsAre(IsPropertyDeclaration(
|
||||
"colorSpace",
|
||||
Storage::ImportedType{"QObject::NamedColorSpaces"},
|
||||
Storage::PropertyDeclarationTraits::None)))));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
Reference in New Issue
Block a user