@@ -133,24 +133,33 @@ def on_template_search_text_changed(self, search_text: str) -> None:
133
133
group_visible = False
134
134
135
135
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 )
138
137
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
141
157
matches = search_text in template_item .text ().lower ()
142
158
template_item .setEnabled (matches )
143
159
144
160
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
152
162
153
- # Show or hide the group based on child matches
154
163
group_item .setEnabled (group_visible )
155
164
156
165
index = self .template_model .indexFromItem (group_item )
@@ -198,29 +207,33 @@ def set_active_library(self, library_name: str) -> None:
198
207
lambda : defaultdict (list )
199
208
)
200
209
210
+ # Group templates by 'group' and 'sub_group'
201
211
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"
205
213
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 )
209
218
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 ():
212
220
group_item = QStandardItem (group_name )
213
221
group_item .setEditable (False )
214
222
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
219
232
220
233
for template in templates :
221
234
template_item = TemplateItem (template )
222
235
template_item .setEditable (False )
223
- geometry_item .appendRow (template_item )
236
+ target_item .appendRow (template_item )
224
237
225
238
self .template_model .appendRow (group_item )
226
239
0 commit comments