Skip to content

Commit 2f55a4b

Browse files
committed
read additional information from given PlanRegulationDefinition in template form
1 parent 073911c commit 2f55a4b

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

arho_feature_template/gui/plan_regulation_widget.py

+24-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from collections import defaultdict
44
from importlib import resources
5-
from typing import TYPE_CHECKING
5+
from typing import TYPE_CHECKING, cast
66

77
from qgis.core import QgsApplication
88
from qgis.gui import QgsDoubleSpinBox, QgsFileWidget, QgsSpinBox
@@ -20,6 +20,7 @@
2020
)
2121

2222
from arho_feature_template.core.plan_regulation_config import PlanRegulationConfig, Unit, ValueType
23+
from arho_feature_template.core.utils import get_additional_information_name
2324

2425
if TYPE_CHECKING:
2526
from numbers import Number
@@ -41,6 +42,9 @@
4142
TEXT_VALUE_FIELD = "text_value"
4243
REGULATION_TYPE_ADDITIONAL_INFORMATION_ID = "regulation_type_additional_information_id"
4344

45+
# TO BE REPLACED
46+
ADDITIONAL_INFORMATION_TYPES_WITH_INPUT = ["kayttotarkoituskohdistus"]
47+
4448

4549
class PlanRegulationWidget(QWidget, FormClass): # type: ignore
4650
"""A widget representation of a plan regulation."""
@@ -73,7 +77,18 @@ def __init__(self, config: PlanRegulationConfig, parent=None):
7377
self.init_buttons()
7478

7579
def populate_from_definition(self, definition: PlanRegulationDefinition):
76-
pass
80+
# Additional information
81+
for info in definition.additional_information:
82+
info_type: str = cast("str", info["type"])
83+
layout = self.add_additional_info(info_type)
84+
if info_type in ADDITIONAL_INFORMATION_TYPES_WITH_INPUT:
85+
info_value_widget = QLineEdit()
86+
layout.addWidget(info_value_widget)
87+
value = info.get("value")
88+
if value:
89+
info_value_widget.setText(value)
90+
91+
# TODO: Other saved information from PlanRegulationDefinition
7792

7893
def init_value_fields(self):
7994
layout = QHBoxLayout()
@@ -186,10 +201,14 @@ def add_versioned_text_input(self, layout: QHBoxLayout):
186201
layout.addWidget(text_widget)
187202
self.form_layout.addRow("Kieliversioitu teksti", layout)
188203

189-
def add_additional_info(self, info_type):
190-
info_type_label = QLineEdit(info_type)
204+
def add_additional_info(self, info_type: str) -> QHBoxLayout:
205+
layout = QHBoxLayout()
206+
info_name = get_additional_information_name(info_type)
207+
info_type_label = QLineEdit(info_name)
191208
info_type_label.setReadOnly(True)
192-
self.form_layout.addRow("Lisätiedonlaji", info_type_label)
209+
layout.addWidget(info_type_label)
210+
self.form_layout.addRow("Lisätiedonlaji", layout)
211+
return layout
193212

194213
def add_regulation_number(self):
195214
if not self.regulation_number_added:

0 commit comments

Comments
 (0)