forked from qt-creator/qt-creator
QmlDesigner: Introduce origin flags
metaInfo.isProjectComponent() is signaling if a file component is directly part of the project. metaInfo.isInProjectModule() otherwise shows if a type is inside of the project as a qmldir module. Both cannot be true. If a type is not part of either it is a system type. Task-number: QDS-10251 Change-Id: Iae2270827a500ad6393e3751b3af276f9b030679 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io> Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io> Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -53,6 +53,8 @@ public:
|
||||
|
||||
TypeId id() const { return m_typeId; }
|
||||
bool isFileComponent() const;
|
||||
bool isProjectComponent() const;
|
||||
bool isInProjectModule() const;
|
||||
bool hasProperty(::Utils::SmallStringView propertyName) const;
|
||||
PropertyMetaInfos properties() const;
|
||||
PropertyMetaInfos localProperties() const;
|
||||
|
@@ -1426,6 +1426,24 @@ bool NodeMetaInfo::isFileComponent() const
|
||||
return isValid() && m_privateData->isFileComponent();
|
||||
}
|
||||
|
||||
bool NodeMetaInfo::isProjectComponent() const
|
||||
{
|
||||
if constexpr (useProjectStorage()) {
|
||||
return isValid() && bool(typeData().traits & Storage::TypeTraits::IsProjectComponent);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NodeMetaInfo::isInProjectModule() const
|
||||
{
|
||||
if constexpr (useProjectStorage()) {
|
||||
return isValid() && bool(typeData().traits & Storage::TypeTraits::IsInProjectModule);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NodeMetaInfo::hasProperty(Utils::SmallStringView propertyName) const
|
||||
{
|
||||
if constexpr (useProjectStorage())
|
||||
|
@@ -46,7 +46,9 @@ enum class TypeTraits : int {
|
||||
Value,
|
||||
Sequence,
|
||||
IsEnum = 1 << 8,
|
||||
IsFileComponent = 1 << 9
|
||||
IsFileComponent = 1 << 9,
|
||||
IsProjectComponent = 1 << 10,
|
||||
IsInProjectModule = 1 << 11
|
||||
};
|
||||
|
||||
constexpr TypeTraits operator|(TypeTraits first, TypeTraits second)
|
||||
|
@@ -155,6 +155,72 @@ TEST_F(NodeMetaInfo, component_is_file_component)
|
||||
ASSERT_TRUE(isFileComponent);
|
||||
}
|
||||
|
||||
TEST_F(NodeMetaInfo, is_project_component)
|
||||
{
|
||||
using QmlDesigner::Storage::TypeTraits;
|
||||
auto moduleId = projectStorageMock.createModule("/path/to/project");
|
||||
auto typeId = projectStorageMock.createType(moduleId, "Foo", TypeTraits::IsProjectComponent);
|
||||
QmlDesigner::NodeMetaInfo metaInfo{typeId, &projectStorageMock};
|
||||
|
||||
bool isProjectComponent = metaInfo.isProjectComponent();
|
||||
|
||||
ASSERT_TRUE(isProjectComponent);
|
||||
}
|
||||
|
||||
TEST_F(NodeMetaInfo, is_not_project_component)
|
||||
{
|
||||
using QmlDesigner::Storage::TypeTraits;
|
||||
auto moduleId = projectStorageMock.createModule("/path/to/project");
|
||||
auto typeId = projectStorageMock.createType(moduleId, "Foo", {});
|
||||
QmlDesigner::NodeMetaInfo metaInfo{typeId, &projectStorageMock};
|
||||
|
||||
bool isProjectComponent = metaInfo.isProjectComponent();
|
||||
|
||||
ASSERT_FALSE(isProjectComponent);
|
||||
}
|
||||
|
||||
TEST_F(NodeMetaInfo, invalid_is_not_project_component)
|
||||
{
|
||||
QmlDesigner::NodeMetaInfo metaInfo;
|
||||
|
||||
bool isProjectComponent = metaInfo.isProjectComponent();
|
||||
|
||||
ASSERT_FALSE(isProjectComponent);
|
||||
}
|
||||
|
||||
TEST_F(NodeMetaInfo, is_in_project_module)
|
||||
{
|
||||
using QmlDesigner::Storage::TypeTraits;
|
||||
auto moduleId = projectStorageMock.createModule("/path/to/project");
|
||||
auto typeId = projectStorageMock.createType(moduleId, "Foo", TypeTraits::IsInProjectModule);
|
||||
QmlDesigner::NodeMetaInfo metaInfo{typeId, &projectStorageMock};
|
||||
|
||||
bool isInProjectModule = metaInfo.isInProjectModule();
|
||||
|
||||
ASSERT_TRUE(isInProjectModule);
|
||||
}
|
||||
|
||||
TEST_F(NodeMetaInfo, is_not_in_project_module)
|
||||
{
|
||||
using QmlDesigner::Storage::TypeTraits;
|
||||
auto moduleId = projectStorageMock.createModule("/path/to/project");
|
||||
auto typeId = projectStorageMock.createType(moduleId, "Foo", {});
|
||||
QmlDesigner::NodeMetaInfo metaInfo{typeId, &projectStorageMock};
|
||||
|
||||
bool isInProjectModule = metaInfo.isInProjectModule();
|
||||
|
||||
ASSERT_FALSE(isInProjectModule);
|
||||
}
|
||||
|
||||
TEST_F(NodeMetaInfo, invalid_is_not_in_project_module)
|
||||
{
|
||||
QmlDesigner::NodeMetaInfo metaInfo;
|
||||
|
||||
bool isInProjectModule = metaInfo.isInProjectModule();
|
||||
|
||||
ASSERT_FALSE(isInProjectModule);
|
||||
}
|
||||
|
||||
TEST_F(NodeMetaInfo, has_property)
|
||||
{
|
||||
auto node = model.createModelNode("Item");
|
||||
|
Reference in New Issue
Block a user