forked from qt-creator/qt-creator
QmlDesigner: Add singleton support to the QmlTypesParser
Task-number: QDS-13602 Change-Id: Ie3506ffe36ba232dcd3fa888cc29064bdb44f872 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -132,6 +132,7 @@ struct TypeTraits
|
||||
, isEnum{false}
|
||||
, isFileComponent{false}
|
||||
, usesCustomParser{false}
|
||||
, isSingleton{false}
|
||||
, dummy{0U}
|
||||
, canBeContainer{FlagIs::False}
|
||||
, forceClip{FlagIs::False}
|
||||
@@ -204,7 +205,8 @@ struct TypeTraits
|
||||
unsigned int isEnum : 1;
|
||||
unsigned int isFileComponent : 1;
|
||||
unsigned int usesCustomParser : 1;
|
||||
unsigned int dummy : 25;
|
||||
unsigned int isSingleton : 1;
|
||||
unsigned int dummy : 24;
|
||||
};
|
||||
|
||||
unsigned int type;
|
||||
|
@@ -118,13 +118,18 @@ Storage::TypeTraits createAccessTypeTraits(QQmlJSScope::AccessSemantics accessSe
|
||||
return Storage::TypeTraitsKind::None;
|
||||
}
|
||||
|
||||
Storage::TypeTraits createTypeTraits(QQmlJSScope::AccessSemantics accessSematics, bool hasCustomParser)
|
||||
Storage::TypeTraits createTypeTraits(QQmlJSScope::AccessSemantics accessSematics,
|
||||
bool hasCustomParser,
|
||||
bool isSingleton)
|
||||
{
|
||||
auto typeTrait = createAccessTypeTraits(accessSematics);
|
||||
|
||||
if (hasCustomParser)
|
||||
typeTrait.usesCustomParser = true;
|
||||
|
||||
if (isSingleton)
|
||||
typeTrait.isSingleton = true;
|
||||
|
||||
return typeTrait;
|
||||
}
|
||||
|
||||
@@ -451,7 +456,9 @@ void addType(Storage::Synchronization::Types &types,
|
||||
Utils::SmallStringView{typeName},
|
||||
Storage::Synchronization::ImportedType{TypeNameString{component.baseTypeName()}},
|
||||
Storage::Synchronization::ImportedType{TypeNameString{component.extensionTypeName()}},
|
||||
createTypeTraits(component.accessSemantics(), component.hasCustomParser()),
|
||||
createTypeTraits(component.accessSemantics(),
|
||||
component.hasCustomParser(),
|
||||
component.isSingleton()),
|
||||
sourceId,
|
||||
createExports(exports, typeName, storage, cppModuleId),
|
||||
createProperties(component.ownProperties(), enumerationTypes, componentNameWithoutNamespace),
|
||||
|
@@ -70,6 +70,13 @@ MATCHER_P(UsesCustomParser,
|
||||
return traits.usesCustomParser == value;
|
||||
}
|
||||
|
||||
MATCHER_P(IsSingleton, value, std::string(negation ? "isn't singleton " : "is singleton "))
|
||||
{
|
||||
const Storage::TypeTraits &traits = arg;
|
||||
|
||||
return traits.isSingleton == value;
|
||||
}
|
||||
|
||||
template<typename Matcher>
|
||||
auto IsTypeTrait(const Matcher &matcher)
|
||||
{
|
||||
@@ -878,4 +885,39 @@ TEST_F(QmlTypesParser, skip_template_item)
|
||||
qmltypesFileSourceId)));
|
||||
}
|
||||
|
||||
TEST_F(QmlTypesParser, is_singleton)
|
||||
{
|
||||
QString source{R"(import QtQuick.tooling 1.2
|
||||
Module{
|
||||
Component { name: "QObject"
|
||||
isSingleton: true}})"};
|
||||
|
||||
parser.parse(source, imports, types, directoryInfo);
|
||||
|
||||
ASSERT_THAT(types, ElementsAre(IsTypeTrait(IsSingleton(true))));
|
||||
}
|
||||
|
||||
TEST_F(QmlTypesParser, is_not_singleton)
|
||||
{
|
||||
QString source{R"(import QtQuick.tooling 1.2
|
||||
Module{
|
||||
Component { name: "QObject"
|
||||
isSingleton: false}})"};
|
||||
|
||||
parser.parse(source, imports, types, directoryInfo);
|
||||
|
||||
ASSERT_THAT(types, ElementsAre(IsTypeTrait(IsSingleton(false))));
|
||||
}
|
||||
|
||||
TEST_F(QmlTypesParser, is_by_default_not_singleton)
|
||||
{
|
||||
QString source{R"(import QtQuick.tooling 1.2
|
||||
Module{
|
||||
Component { name: "QObject"}})"};
|
||||
|
||||
parser.parse(source, imports, types, directoryInfo);
|
||||
|
||||
ASSERT_THAT(types, ElementsAre(IsTypeTrait(IsSingleton(false))));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
Reference in New Issue
Block a user