|
2 | 2 |
|
3 | 3 | from collections import defaultdict
|
4 | 4 | from importlib import resources
|
5 |
| -from typing import TYPE_CHECKING |
| 5 | +from typing import TYPE_CHECKING, cast |
6 | 6 |
|
7 | 7 | from qgis.core import QgsApplication
|
8 | 8 | from qgis.gui import QgsDoubleSpinBox, QgsFileWidget, QgsSpinBox
|
|
20 | 20 | )
|
21 | 21 |
|
22 | 22 | from arho_feature_template.core.plan_regulation_config import PlanRegulationConfig, Unit, ValueType
|
| 23 | +from arho_feature_template.utils.misc_utils import get_additional_information_name |
23 | 24 |
|
24 | 25 | if TYPE_CHECKING:
|
25 | 26 | from numbers import Number
|
|
28 | 29 |
|
29 | 30 | from arho_feature_template.core.plan_regulation_group_config import PlanRegulationDefinition
|
30 | 31 |
|
31 |
| -ui_path = resources.files(__package__) / "new_plan_regulation_widget.ui" |
| 32 | +ui_path = resources.files(__package__) / "plan_regulation_widget.ui" |
32 | 33 | FormClass, _ = uic.loadUiType(ui_path)
|
33 | 34 |
|
34 | 35 |
|
|
41 | 42 | TEXT_VALUE_FIELD = "text_value"
|
42 | 43 | REGULATION_TYPE_ADDITIONAL_INFORMATION_ID = "regulation_type_additional_information_id"
|
43 | 44 |
|
| 45 | +# TO BE REPLACED |
| 46 | +ADDITIONAL_INFORMATION_TYPES_WITH_INPUT = ["kayttotarkoituskohdistus"] |
| 47 | + |
44 | 48 |
|
45 | 49 | class PlanRegulationWidget(QWidget, FormClass): # type: ignore
|
46 | 50 | """A widget representation of a plan regulation."""
|
@@ -73,7 +77,18 @@ def __init__(self, config: PlanRegulationConfig, parent=None):
|
73 | 77 | self.init_buttons()
|
74 | 78 |
|
75 | 79 | 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 |
77 | 92 |
|
78 | 93 | def init_value_fields(self):
|
79 | 94 | layout = QHBoxLayout()
|
@@ -186,10 +201,14 @@ def add_versioned_text_input(self, layout: QHBoxLayout):
|
186 | 201 | layout.addWidget(text_widget)
|
187 | 202 | self.form_layout.addRow("Kieliversioitu teksti", layout)
|
188 | 203 |
|
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) |
191 | 208 | 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 |
193 | 212 |
|
194 | 213 | def add_regulation_number(self):
|
195 | 214 | if not self.regulation_number_added:
|
|
0 commit comments