Skip to content

Commit d20f9ad

Browse files
Mtk112LKajan
authored andcommitted
Add sub_group.
1 parent f2c6db1 commit d20f9ad

File tree

4 files changed

+44
-16
lines changed

4 files changed

+44
-16
lines changed

arho_feature_template/core/feature_template_library.py

+34-16
Original file line numberDiff line numberDiff line change
@@ -133,22 +133,29 @@ 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-
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
140138

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)
143152

144153
# Show or hide the group based on child matches
145154
group_item.setEnabled(group_visible)
146155

147156
index = self.template_model.indexFromItem(group_item)
148157
self.template_dock.template_list.setExpanded(index, group_visible)
149158

150-
self.template_model.setItem(row, group_item)
151-
152159
def start_digitizing_for_layer(self, layer: QgsVectorLayer) -> None:
153160
self.digitize_map_tool.clean()
154161
self.digitize_map_tool.setLayer(layer)
@@ -187,22 +194,33 @@ def get_library_names(self) -> list[str]:
187194
def set_active_library(self, library_name: str) -> None:
188195
self.template_model.clear()
189196

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+
192201
for template in self.library_configs[library_name].templates:
193202
group = getattr(template, "group", None)
194203
if not group:
195204
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)
197209

198-
for group_name, templates in grouped_templates.items():
210+
# Build nested structure
211+
for group_name, geometry_dict in grouped_templates.items():
199212
group_item = QStandardItem(group_name)
200213
group_item.setEditable(False)
201214

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)
206224

207225
self.template_model.appendRow(group_item)
208226

arho_feature_template/core/template_library_config.py

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class TemplateLibraryMeta:
5454

5555
name: str
5656
group: str | None
57+
sub_group: str | None
5758
description: str | None
5859
version: str | None
5960

@@ -62,6 +63,7 @@ def from_dict(cls, data: dict) -> TemplateLibraryMeta:
6263
return cls(
6364
name=data["name"],
6465
group=data.get("group"),
66+
sub_group=data.get("sub_group"),
6567
description=data.get("description"),
6668
version=data.get("version"),
6769
)
@@ -73,6 +75,7 @@ class FeatureTemplate:
7375

7476
name: str
7577
group: str | None
78+
sub_group: str | None
7679
description: str | None
7780
feature: Feature
7881

@@ -81,6 +84,7 @@ def from_dict(cls, data: dict) -> FeatureTemplate:
8184
return cls(
8285
name=data["name"],
8386
group=data.get("group"),
87+
sub_group=data.get("sub_group"),
8488
description=data.get("description"),
8589
feature=Feature.from_dict(data["feature"]),
8690
)

arho_feature_template/resources/template_libraries/ryhmitelty-asemakaava-sample.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ meta:
55
templates:
66
- name: Simppeli kaavakohde
77
group: Osa-alue
8+
sub_group: Alue
89
description: Kaavakohde ilman kikkareita
910
feature:
1011
layer: land_use_area
@@ -15,6 +16,7 @@ templates:
1516

1617
- name: Asuin-, liike- ja toimistorakennusten alue
1718
group: Aluevaraus
19+
sub_group: Alue
1820
description: Alueella kuvataan ...
1921
feature:
2022
layer: land_use_area

arho_feature_template/resources/template_libraries/schema/template_library.schema.json

+4
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@
9494
"description": "The group of the template",
9595
"type": "string"
9696
},
97+
"sub_group": {
98+
"description": "The geometry type of the template",
99+
"type": "string"
100+
},
97101
"description": {
98102
"description": "The description of the template",
99103
"type": "string"

0 commit comments

Comments
 (0)