Skip to content

Commit 1b4b689

Browse files
Mtk112LKajan
authored andcommitted
List templates without sub_group directly under group
1 parent d20f9ad commit 1b4b689

File tree

1 file changed

+38
-25
lines changed

1 file changed

+38
-25
lines changed

arho_feature_template/core/feature_template_library.py

+38-25
Original file line numberDiff line numberDiff line change
@@ -133,24 +133,33 @@ def on_template_search_text_changed(self, search_text: str) -> None:
133133
group_visible = False
134134

135135
for child_row in range(group_item.rowCount()):
136-
geometry_item = group_item.child(child_row)
137-
geometry_visible = False
136+
child_item = group_item.child(child_row)
138137

139-
for template_row in range(geometry_item.rowCount()):
140-
template_item = geometry_item.child(template_row)
138+
if child_item.hasChildren():
139+
subgroup_visible = False
140+
141+
for template_row in range(child_item.rowCount()):
142+
template_item = child_item.child(template_row)
143+
matches = search_text in template_item.text().lower()
144+
template_item.setEnabled(matches)
145+
146+
if matches:
147+
subgroup_visible = True
148+
149+
child_item.setEnabled(subgroup_visible)
150+
group_visible = group_visible or subgroup_visible
151+
152+
index = self.template_model.indexFromItem(child_item)
153+
self.template_dock.template_list.setExpanded(index, subgroup_visible)
154+
155+
else:
156+
template_item = child_item
141157
matches = search_text in template_item.text().lower()
142158
template_item.setEnabled(matches)
143159

144160
if matches:
145-
geometry_visible = True
146-
147-
geometry_item.setEnabled(geometry_visible)
148-
group_visible = group_visible or geometry_visible
149-
150-
index = self.template_model.indexFromItem(geometry_item)
151-
self.template_dock.template_list.setExpanded(index, geometry_visible)
161+
group_visible = True
152162

153-
# Show or hide the group based on child matches
154163
group_item.setEnabled(group_visible)
155164

156165
index = self.template_model.indexFromItem(group_item)
@@ -198,29 +207,33 @@ def set_active_library(self, library_name: str) -> None:
198207
lambda: defaultdict(list)
199208
)
200209

210+
# Group templates by 'group' and 'sub_group'
201211
for template in self.library_configs[library_name].templates:
202-
group = getattr(template, "group", None)
203-
if not group:
204-
group = "Ryhmittelemättömät"
212+
group = getattr(template, "group", None) or "Ryhmittelemättömät"
205213
sub_group = getattr(template, "sub_group", None)
206-
if not sub_group:
207-
sub_group = "Tuntematon"
208-
grouped_templates[group][sub_group].append(template)
214+
if sub_group:
215+
grouped_templates[group][sub_group].append(template)
216+
else:
217+
grouped_templates[group][""].append(template)
209218

210-
# Build nested structure
211-
for group_name, geometry_dict in grouped_templates.items():
219+
for group_name, sub_group_dict in grouped_templates.items():
212220
group_item = QStandardItem(group_name)
213221
group_item.setEditable(False)
214222

215-
for geometry_name, templates in geometry_dict.items():
216-
geometry_item = QStandardItem(geometry_name)
217-
geometry_item.setEditable(False)
218-
group_item.appendRow(geometry_item)
223+
for sub_group_name, templates in sub_group_dict.items():
224+
if sub_group_name:
225+
sub_group_item = QStandardItem(sub_group_name)
226+
sub_group_item.setEditable(False)
227+
group_item.appendRow(sub_group_item)
228+
target_item = sub_group_item
229+
else:
230+
# If template has no sub_group set, list it directly under group
231+
target_item = group_item
219232

220233
for template in templates:
221234
template_item = TemplateItem(template)
222235
template_item.setEditable(False)
223-
geometry_item.appendRow(template_item)
236+
target_item.appendRow(template_item)
224237

225238
self.template_model.appendRow(group_item)
226239

0 commit comments

Comments
 (0)