forked from qt-creator/qt-creator
QmlDesigner: Add hints to hide node in navigator
For effects we want to explcitly hide certain items. Change-Id: I49748f851453c7c8d5001ca696d5a6b1b2969550 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -324,7 +324,10 @@ QList<ModelNode> NavigatorTreeModel::filteredList(const NodeListProperty &proper
|
||||
|
||||
if (filter) {
|
||||
list.append(::Utils::filtered(nameFilteredList, [](const ModelNode &arg) {
|
||||
const bool value = (QmlItemNode::isValidQmlItemNode(arg) || NodeHints::fromModelNode(arg).visibleInNavigator())
|
||||
const bool visibleInNavigator = NodeHints::fromModelNode(arg).visibleInNavigator();
|
||||
const bool hideInNavigator = NodeHints::fromModelNode(arg).hideInNavigator();
|
||||
const bool value = ((QmlItemNode::isValidQmlItemNode(arg) && !hideInNavigator)
|
||||
|| visibleInNavigator)
|
||||
&& arg.id() != Constants::MATERIAL_LIB_ID;
|
||||
return value;
|
||||
}));
|
||||
|
@@ -49,6 +49,7 @@ public:
|
||||
QStringList visibleNonDefaultProperties() const;
|
||||
bool takesOverRenderingOfChildren() const;
|
||||
bool visibleInNavigator() const;
|
||||
bool hideInNavigator() const;
|
||||
bool visibleInLibrary() const;
|
||||
QString forceNonDefaultProperty() const;
|
||||
QPair<QString, QVariant> setParentProperty() const;
|
||||
|
@@ -87,6 +87,7 @@ public:
|
||||
FlagIs isStackedContainer() const;
|
||||
FlagIs takesOverRenderingOfChildren() const;
|
||||
FlagIs visibleInNavigator() const;
|
||||
FlagIs hideInNavigator() const;
|
||||
FlagIs visibleInLibrary() const;
|
||||
|
||||
bool hasProperty(::Utils::SmallStringView propertyName) const;
|
||||
|
@@ -321,6 +321,19 @@ bool NodeHints::visibleInNavigator() const
|
||||
return evaluateBooleanExpression("visibleInNavigator", false);
|
||||
}
|
||||
|
||||
bool NodeHints::hideInNavigator() const
|
||||
{
|
||||
if (!isValid())
|
||||
return false;
|
||||
|
||||
auto flagIs = m_modelNode.metaInfo().hideInNavigator();
|
||||
|
||||
if (flagIs != FlagIs::Set)
|
||||
return convert(flagIs);
|
||||
|
||||
return evaluateBooleanExpression("hideInNavigator", false);
|
||||
}
|
||||
|
||||
bool NodeHints::visibleInLibrary() const
|
||||
{
|
||||
auto flagIs = m_metaInfo.visibleInLibrary();
|
||||
|
@@ -1780,6 +1780,18 @@ FlagIs NodeMetaInfo::visibleInNavigator() const
|
||||
return FlagIs::Set;
|
||||
}
|
||||
|
||||
FlagIs NodeMetaInfo::hideInNavigator() const
|
||||
{
|
||||
if constexpr (useProjectStorage()) {
|
||||
if (isValid())
|
||||
return typeData().traits.hideInNavigator;
|
||||
|
||||
return FlagIs::False;
|
||||
}
|
||||
|
||||
return FlagIs::Set;
|
||||
}
|
||||
|
||||
FlagIs NodeMetaInfo::visibleInLibrary() const
|
||||
{
|
||||
if constexpr (useProjectStorage()) {
|
||||
|
@@ -147,6 +147,7 @@ struct TypeTraits
|
||||
, takesOverRenderingOfChildren{FlagIs::False}
|
||||
, visibleInNavigator{FlagIs::False}
|
||||
, visibleInLibrary{FlagIs::False}
|
||||
, hideInNavigator{FlagIs::False}
|
||||
, dummy2{0U}
|
||||
{}
|
||||
|
||||
@@ -193,7 +194,8 @@ struct TypeTraits
|
||||
keyValue("is stacked container", typeTraits.isStackedContainer),
|
||||
keyValue("takes over rendering of children", typeTraits.takesOverRenderingOfChildren),
|
||||
keyValue("visible in navigator", typeTraits.visibleInNavigator),
|
||||
keyValue("visible in library", typeTraits.visibleInLibrary));
|
||||
keyValue("visible in library", typeTraits.visibleInLibrary),
|
||||
keyValue("hide in navigator", typeTraits.hideInNavigator));
|
||||
|
||||
convertToString(string, dict);
|
||||
}
|
||||
@@ -228,7 +230,8 @@ struct TypeTraits
|
||||
FlagIs takesOverRenderingOfChildren : 2;
|
||||
FlagIs visibleInNavigator : 2;
|
||||
FlagIs visibleInLibrary : 2;
|
||||
unsigned int dummy2 : 6;
|
||||
FlagIs hideInNavigator : 2;
|
||||
unsigned int dummy2 : 4;
|
||||
};
|
||||
|
||||
unsigned int annotation;
|
||||
|
@@ -400,6 +400,8 @@ void setTrait(QStringView name, FlagIs flag, Storage::TypeTraits &traits)
|
||||
traits.visibleInNavigator = flag;
|
||||
} else if (name == "visibleInLibrary"_L1) {
|
||||
traits.visibleInLibrary = flag;
|
||||
} else if (name == "hideInNavigator"_L1) {
|
||||
traits.hideInNavigator = flag;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -656,6 +656,9 @@ std::ostream &operator<<(std::ostream &out, TypeTraits traits)
|
||||
if (traits.visibleInLibrary != QmlDesigner::FlagIs::False)
|
||||
out << " | visibleInLibrary(" << traits.visibleInLibrary << ")";
|
||||
|
||||
if (traits.hideInNavigator != QmlDesigner::FlagIs::False)
|
||||
out << " | hideInNavigator(" << traits.hideInNavigator << ")";
|
||||
|
||||
return out << ")";
|
||||
}
|
||||
|
||||
|
@@ -3061,6 +3061,43 @@ TEST_F(NodeMetaInfo, invalid_is_not_visible_in_library)
|
||||
ASSERT_THAT(visibleInLibrary, FlagIs::False);
|
||||
}
|
||||
|
||||
TEST_F(NodeMetaInfo, object_is_not_hide_in_navigator)
|
||||
{
|
||||
auto hideInNavigator = objectMetaInfo.hideInNavigator();
|
||||
|
||||
ASSERT_THAT(hideInNavigator, FlagIs::False);
|
||||
}
|
||||
|
||||
TEST_F(NodeMetaInfo, default_is_not_hide_in_navigator)
|
||||
{
|
||||
auto hideInNavigator = QmlDesigner::NodeMetaInfo{}.hideInNavigator();
|
||||
|
||||
ASSERT_THAT(hideInNavigator, FlagIs::False);
|
||||
}
|
||||
|
||||
TEST_F(NodeMetaInfo, invalid_is_not_hide_in_navigator)
|
||||
{
|
||||
auto node = model.createModelNode("Foo");
|
||||
auto metaInfo = node.metaInfo();
|
||||
|
||||
auto hideInNavigator = metaInfo.hideInNavigator();
|
||||
|
||||
ASSERT_THAT(hideInNavigator, FlagIs::False);
|
||||
}
|
||||
|
||||
TEST_F(NodeMetaInfo, component_is_hide_in_navigator)
|
||||
{
|
||||
auto moduleId = projectStorageMock.createModule("/path/to/project", ModuleKind::PathLibrary);
|
||||
TypeTraits traits{TypeTraitsKind::Reference};
|
||||
traits.hideInNavigator = FlagIs::True;
|
||||
auto typeId = projectStorageMock.createType(moduleId, "Foo", traits);
|
||||
QmlDesigner::NodeMetaInfo metaInfo{typeId, &projectStorageMock};
|
||||
|
||||
auto hideInNavigator = metaInfo.hideInNavigator();
|
||||
|
||||
ASSERT_THAT(hideInNavigator, FlagIs::True);
|
||||
}
|
||||
|
||||
TEST_F(NodeMetaInfo, component_is_visible_in_library)
|
||||
{
|
||||
auto moduleId = projectStorageMock.createModule("/path/to/project", ModuleKind::PathLibrary);
|
||||
|
@@ -236,6 +236,35 @@ TEST_F(TypeAnnotationReader, parse_false_canBeDroppedInNavigator)
|
||||
IsEmpty())));
|
||||
}
|
||||
|
||||
TEST_F(TypeAnnotationReader, parse_true_hideInNavigator)
|
||||
{
|
||||
using QmlDesigner::FlagIs;
|
||||
auto content = QString{R"xy(
|
||||
MetaInfo {
|
||||
Type {
|
||||
name: "QtQuick.Controls.Frame"
|
||||
icon: "images/frame-icon16.png"
|
||||
|
||||
Hints {
|
||||
hideInNavigator: true
|
||||
}
|
||||
}
|
||||
})xy"};
|
||||
traits.hideInNavigator = FlagIs::True;
|
||||
|
||||
auto annotations = reader.parseTypeAnnotation(content, "/path", sourceId, directorySourceId);
|
||||
|
||||
ASSERT_THAT(annotations,
|
||||
ElementsAre(IsTypeAnnotation(sourceId,
|
||||
directorySourceId,
|
||||
"Frame",
|
||||
moduleId("QtQuick.Controls"),
|
||||
"/path/images/frame-icon16.png",
|
||||
traits,
|
||||
IsEmpty(),
|
||||
IsEmpty())));
|
||||
}
|
||||
|
||||
TEST_F(TypeAnnotationReader, parse_true_canBeDroppedInView3D)
|
||||
{
|
||||
using QmlDesigner::FlagIs;
|
||||
|
Reference in New Issue
Block a user