Skip to content

Commit 4bf485c

Browse files
committed
add codecombobox for type of underground in plan feature form
1 parent 38b316c commit 4bf485c

File tree

5 files changed

+22
-18
lines changed

5 files changed

+22
-18
lines changed

arho_feature_template/core/models.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def save_data(self):
320320
class PlanFeature:
321321
geom: QgsGeometry
322322
feature_layer_class: type[PlanFeatureLayer]
323-
type_of_underground: int
323+
type_of_underground_id: str
324324
name: str | None = None
325325
description: str | None = None
326326
plan_id: int | None = None

arho_feature_template/gui/template_attribute_form.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
from arho_feature_template.core.models import PlanFeature, RegulationGroup, RegulationGroupLibrary
2424
from arho_feature_template.gui.plan_regulation_group_widget import RegulationGroupWidget
25+
from arho_feature_template.project.layers.code_layers import UndergroundTypeLayer
2526
from arho_feature_template.project.layers.plan_layers import LandUseAreaLayer, PlanFeatureLayer
2627
from arho_feature_template.qgis_plugin_tools.tools.resources import resources_path
2728

@@ -30,6 +31,7 @@
3031
from qgis.PyQt.QtWidgets import QWidget
3132

3233
from arho_feature_template.core.template_library_config import FeatureTemplate
34+
from arho_feature_template.gui.code_combobox import CodeComboBox
3335

3436
ui_path = resources.files(__package__) / "template_attribute_form.ui"
3537
FormClass, _ = uic.loadUiType(ui_path)
@@ -52,14 +54,18 @@ def __init__(
5254
self.feature_layer_class = feature_layer_class
5355
self.feature_name: QLineEdit
5456
self.feature_description: QTextEdit
55-
self.feature_type_of_underground: QComboBox
57+
self.feature_type_of_underground: CodeComboBox
5658
self.plan_regulation_group_scrollarea: QScrollArea
5759
self.plan_regulation_group_scrollarea_contents: QWidget
5860
self.plan_regulation_group_libraries_combobox: QComboBox
5961
self.plan_regulation_groups_tree: QTreeWidget
6062
self.button_box: QDialogButtonBox
6163

6264
# INIT
65+
self.feature_type_of_underground.populate_from_code_layer(UndergroundTypeLayer)
66+
self.feature_type_of_underground.removeItem(0) # Remove NULL from combobox as underground data is required
67+
self.feature_type_of_underground.setCurrentIndex(1) # Set default to Maanpäällinen (index 1)
68+
6369
self.regulation_group_widgets: list[RegulationGroupWidget] = []
6470
self.scroll_area_spacer = None
6571
self.setWindowTitle(feature_template_config.name)
@@ -116,7 +122,7 @@ def init_plan_regulation_group_library(self, library: RegulationGroupLibrary):
116122
def into_model(self) -> PlanFeature:
117123
return PlanFeature(
118124
name=self.feature_name.text(),
119-
type_of_underground=self.feature_type_of_underground.currentIndex(),
125+
type_of_underground_id=self.feature_type_of_underground.value(),
120126
description=self.feature_description.toPlainText(),
121127
geom=self.geom,
122128
feature_layer_class=self.feature_layer_class,

arho_feature_template/gui/template_attribute_form.ui

+8-14
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<string>Kaavakohteen tiedot</string>
2121
</property>
2222
<property name="collapsed">
23-
<bool>true</bool>
23+
<bool>false</bool>
2424
</property>
2525
<layout class="QFormLayout" name="formLayout">
2626
<item row="0" column="0">
@@ -58,18 +58,7 @@
5858
</widget>
5959
</item>
6060
<item row="2" column="1">
61-
<widget class="QComboBox" name="feature_type_of_underground">
62-
<item>
63-
<property name="text">
64-
<string>Maanpäällinen</string>
65-
</property>
66-
</item>
67-
<item>
68-
<property name="text">
69-
<string>Maanalainen</string>
70-
</property>
71-
</item>
72-
</widget>
61+
<widget class="CodeComboBox" name="feature_type_of_underground"/>
7362
</item>
7463
</layout>
7564
</widget>
@@ -172,7 +161,7 @@
172161
<x>0</x>
173162
<y>0</y>
174163
<width>596</width>
175-
<height>600</height>
164+
<height>325</height>
176165
</rect>
177166
</property>
178167
<layout class="QVBoxLayout" name="verticalLayout_2"/>
@@ -205,6 +194,11 @@
205194
<extends>QLineEdit</extends>
206195
<header>qgsfilterlineedit.h</header>
207196
</customwidget>
197+
<customwidget>
198+
<class>CodeComboBox</class>
199+
<extends>QComboBox</extends>
200+
<header>arho_feature_template.gui.code_combobox</header>
201+
</customwidget>
208202
</customwidgets>
209203
<resources/>
210204
<connections>

arho_feature_template/project/layers/code_layers.py

+4
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,8 @@ class OrganisationLayer(AbstractCodeLayer):
1818
name = "Toimija"
1919

2020

21+
class UndergroundTypeLayer(AbstractCodeLayer):
22+
name = "Maanalaisuuden tyyppi"
23+
24+
2125
code_layers = AbstractCodeLayer.__subclasses__()

arho_feature_template/project/layers/plan_layers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def feature_from_model(cls, model: PlanFeature) -> QgsFeature:
8484

8585
feature = QgsVectorLayerUtils.createFeature(layer, model.geom)
8686
feature["name"] = {"fin": model.name if model.name else ""}
87-
feature["type_of_underground_id"] = "adbf1d95-ce21-40c2-ae83-a82c13591e78" # TODO: change
87+
feature["type_of_underground_id"] = model.type_of_underground_id
8888
feature["description"] = {"fin": model.description if model.description else ""}
8989
feature["plan_id"] = QgsExpressionContextUtils.projectScope(QgsProject.instance()).variable("active_plan_id")
9090

0 commit comments

Comments
 (0)