Skip to content

Commit d0e1479

Browse files
committed
Make entity items correctly advertise if they have children
This fixes a bug in DB Editor's Entity tree where the ND entities at deeper levels of the tree did not show up as expandable even though they had children. Re #3242
1 parent ee0353c commit d0e1479

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

spinetoolbox/spine_db_editor/mvcmodels/entity_tree_item.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,17 @@ def _handle_entity_group_items_removed(self, db_map_data):
345345
self._is_group = False
346346
self.parent_item.reposition_child(self.child_number())
347347

348+
def _polish_children(self, children):
349+
"""See base class."""
350+
db_map_entity_element_ids = {
351+
db_map: {el_id for ent in self.db_mngr.get_items(db_map, "entity") for el_id in ent["element_id_list"]}
352+
for db_map in self.db_maps
353+
}
354+
for child in children:
355+
child.set_has_children_initially(
356+
any(child.db_map_id(db_map) in db_map_entity_element_ids.get(db_map, ()) for db_map in child.db_maps)
357+
)
358+
348359
def tear_down(self):
349360
super().tear_down()
350361
self._entity_group_fetch_parent.set_obsolete(True)

tests/spine_db_editor/mvcmodels/test_entity_tree_models.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,39 @@ def test_superclass_name_displayed_after_subclass_name(self, db_editor, db_mngr,
2525
while len(model.root_item.children) != 2:
2626
QApplication.processEvents()
2727
assert [child.display_data for child in model.root_item.children] == ["Any", "Object (Any)"]
28+
29+
def test_entity_items_advertise_they_have_children(self, db_editor, db_mngr, db_map):
30+
with db_map:
31+
db_map.add_entity_class(name="A")
32+
db_map.add_entity(entity_class_name="A", name="a")
33+
db_map.add_entity_class(name="B")
34+
db_map.add_entity(entity_class_name="B", name="b")
35+
db_map.add_entity_class(dimension_name_list=["A", "B"])
36+
db_map.add_entity(entity_class_name="A__B", entity_byname=["a", "b"])
37+
db_map.add_entity_class(dimension_name_list=["A__B", "A__B"])
38+
db_map.add_entity(entity_class_name="A__B__A__B", entity_byname=["a", "b", "a", "b"])
39+
model = EntityTreeModel(db_editor, db_mngr, db_map)
40+
model.build_tree()
41+
model.root_item.fetch_more()
42+
while len(model.root_item.children) != 4:
43+
QApplication.processEvents()
44+
assert [child.display_data for child in model.root_item.children] == ["A", "B", "A__B", "A__B__A__B"]
45+
assert all(child.has_children() for child in model.root_item.children)
46+
class_a = model.root_item.children[0]
47+
class_a.fetch_more()
48+
while len(class_a.children) != 1:
49+
QApplication.processEvents()
50+
assert [entity_item.display_data for entity_item in class_a.children] == ["a"]
51+
assert all(entity_item.has_children() for entity_item in class_a.children)
52+
entity_a = class_a.children[0]
53+
entity_a.fetch_more()
54+
while len(entity_a.children) != 1:
55+
QApplication.processEvents()
56+
assert [entity_item.display_data for entity_item in entity_a.children] == ["٭ ǀ b"]
57+
assert all(entity_item.has_children() for entity_item in entity_a.children)
58+
relationship_a_b = entity_a.children[0]
59+
relationship_a_b.fetch_more()
60+
while len(relationship_a_b.children) != 1:
61+
QApplication.processEvents()
62+
assert [relationship.display_data for relationship in relationship_a_b.children] == ["٭ ǀ ٭ ǀ ٭ ǀ ٭"]
63+
assert all(not relationship.has_children() for relationship in relationship_a_b.children)

0 commit comments

Comments
 (0)