@@ -133,22 +133,29 @@ 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
- template_item = group_item .child (child_row )
137
- matches = search_text in template_item .text ().lower ()
138
- template_item .setEnabled (matches )
139
- group_item .setChild (child_row , template_item )
136
+ geometry_item = group_item .child (child_row )
137
+ geometry_visible = False
140
138
141
- if matches :
142
- group_visible = True
139
+ for template_row in range (geometry_item .rowCount ()):
140
+ template_item = geometry_item .child (template_row )
141
+ matches = search_text in template_item .text ().lower ()
142
+ template_item .setEnabled (matches )
143
+
144
+ 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 )
143
152
144
153
# Show or hide the group based on child matches
145
154
group_item .setEnabled (group_visible )
146
155
147
156
index = self .template_model .indexFromItem (group_item )
148
157
self .template_dock .template_list .setExpanded (index , group_visible )
149
158
150
- self .template_model .setItem (row , group_item )
151
-
152
159
def start_digitizing_for_layer (self , layer : QgsVectorLayer ) -> None :
153
160
self .digitize_map_tool .clean ()
154
161
self .digitize_map_tool .setLayer (layer )
@@ -187,22 +194,33 @@ def get_library_names(self) -> list[str]:
187
194
def set_active_library (self , library_name : str ) -> None :
188
195
self .template_model .clear ()
189
196
190
- # Group templates by their 'group' attribute, defaulting to "Ryhmittelemättömät" for ungrouped templates
191
- grouped_templates = defaultdict (list )
197
+ grouped_templates : defaultdict [str , defaultdict [str , list [FeatureTemplate ]]] = defaultdict (
198
+ lambda : defaultdict (list )
199
+ )
200
+
192
201
for template in self .library_configs [library_name ].templates :
193
202
group = getattr (template , "group" , None )
194
203
if not group :
195
204
group = "Ryhmittelemättömät"
196
- grouped_templates [group ].append (template )
205
+ sub_group = getattr (template , "sub_group" , None )
206
+ if not sub_group :
207
+ sub_group = "Tuntematon"
208
+ grouped_templates [group ][sub_group ].append (template )
197
209
198
- for group_name , templates in grouped_templates .items ():
210
+ # Build nested structure
211
+ for group_name , geometry_dict in grouped_templates .items ():
199
212
group_item = QStandardItem (group_name )
200
213
group_item .setEditable (False )
201
214
202
- for template in templates :
203
- template_item = TemplateItem (template )
204
- template_item .setEditable (False )
205
- group_item .appendRow (template_item )
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 )
219
+
220
+ for template in templates :
221
+ template_item = TemplateItem (template )
222
+ template_item .setEditable (False )
223
+ geometry_item .appendRow (template_item )
206
224
207
225
self .template_model .appendRow (group_item )
208
226
0 commit comments