Skip to content

Commit 051805c

Browse files
committed
add type of verbal plan regulation
- add type_of_verbal_plan_regulation_id to Regulation model - update RegulationLayer to use type_of_verbal_plan_regulation_id - add widget for type of verbal plan regulation in regulation widget when regulation type is "Sanallinen määräys" - add category_only_codes to all existing AbstractCodeLayer - use category_only_codes information from AbstractCodeLayer when populating HierarchicalCodeComboBox
1 parent 2f0b8d2 commit 051805c

File tree

5 files changed

+43
-12
lines changed

5 files changed

+43
-12
lines changed

arho_feature_template/core/models.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,9 @@ class Regulation:
255255
files: list[str] = field(default_factory=list)
256256
theme: str | None = None
257257
topic_tag: str | None = None
258+
verbal_regulation_type_id: str | None = None
258259
regulation_group_id_: int | None = None
259260
id_: int | None = None
260-
# value_string: str | None
261-
# value_number: Number | None
262-
# value_number_pair: tuple[Number, Number] | None
263261

264262

265263
@dataclass

arho_feature_template/gui/components/code_combobox.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ def populate_from_code_layer(self, layer_type: type[AbstractCodeLayer]) -> None:
8282
item = QTreeWidgetItem()
8383
items[code_feature["id"]] = item
8484

85-
text = code_feature["name"][LANGUAGE]
86-
item.setText(0, text)
87-
description = code_feature["description"][LANGUAGE]
88-
item.setToolTip(0, description)
85+
item.setText(0, code_feature["name"][LANGUAGE])
86+
item.setToolTip(0, code_feature["description"][LANGUAGE])
8987
item.setData(0, Qt.UserRole, code_feature["id"])
9088

89+
if code_feature["value"] in layer_type.category_only_codes:
90+
item.setFlags(item.flags() & ~Qt.ItemIsSelectable)
91+
9192
if code_feature["level"] == 1:
9293
self.tree_widget.addTopLevelItem(item)
93-
item.setFlags(item.flags() & ~Qt.ItemIsSelectable)
9494
else:
9595
parent = items[code_feature["parent_id"]]
9696
parent.addChild(item)

arho_feature_template/gui/components/plan_regulation_widget.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
)
1818

1919
from arho_feature_template.core.models import Regulation, ValueType
20+
from arho_feature_template.gui.components.code_combobox import HierarchicalCodeComboBox
2021
from arho_feature_template.gui.components.plan_regulation_input_widgets import (
2122
DecimalInputWidget,
2223
IntegerInputWidget,
2324
IntegerRangeInputWidget,
2425
MultilineTextInputWidget,
2526
SinglelineTextInputWidget,
2627
)
27-
from arho_feature_template.project.layers.code_layers import AdditionalInformationTypeLayer
28+
from arho_feature_template.project.layers.code_layers import AdditionalInformationTypeLayer, VerbalRegulationType
2829
from arho_feature_template.utils.misc_utils import LANGUAGE, get_layer_by_name, iface
2930

3031
if TYPE_CHECKING:
@@ -67,6 +68,7 @@ def __init__(self, regulation: Regulation, parent=None):
6768
self.file_widgets: list[QgsFileWidget] = []
6869
self.theme_widget: SinglelineTextInputWidget | None = None
6970
self.topic_tag_widget: SinglelineTextInputWidget | None = None
71+
self.type_of_verbal_regulation_widget: HierarchicalCodeComboBox | None = None
7072

7173
self.expanded = True
7274
self.plan_regulation_name.setText(self.config.name)
@@ -83,6 +85,12 @@ def _init_widgets(self):
8385
value_type = self.config.value_type
8486
if value_type:
8587
self._add_value_input(value_type, self.config.unit, self.regulation.value)
88+
if self.config.regulation_code == "sanallinenMaarays":
89+
self.type_of_verbal_regulation_widget = HierarchicalCodeComboBox()
90+
self.type_of_verbal_regulation_widget.populate_from_code_layer(VerbalRegulationType)
91+
self._add_widgets(QLabel("Sanallisen määräyksen laji"), self.type_of_verbal_regulation_widget)
92+
if self.regulation.verbal_regulation_type_id is not None:
93+
self.type_of_verbal_regulation_widget.set_value(self.regulation.verbal_regulation_type_id)
8694

8795
# Additional information
8896
if self.regulation.additional_information:
@@ -249,7 +257,6 @@ def _add_theme(self, theme_name: str):
249257
self.theme_widget = SinglelineTextInputWidget(theme_name, False)
250258
self._add_widgets(QLabel("Kaavoitusteema"), self.theme_widget)
251259

252-
# Or e.g. "into_regulation"
253260
def into_model(self) -> Regulation:
254261
return Regulation(
255262
config=self.config,
@@ -261,5 +268,8 @@ def into_model(self) -> Regulation:
261268
files=[file.filePath() for file in self.file_widgets],
262269
theme=self.theme_widget.get_value() if self.theme_widget else None,
263270
topic_tag=self.topic_tag_widget.get_value() if self.topic_tag_widget else None,
271+
verbal_regulation_type_id=self.type_of_verbal_regulation_widget.value()
272+
if self.type_of_verbal_regulation_widget
273+
else None,
264274
id_=self.regulation.id_,
265275
)

arho_feature_template/project/layers/code_layers.py

+23-1
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77
from arho_feature_template.utils.misc_utils import LANGUAGE
88

99

10-
class AbstractCodeLayer(AbstractLayer): ...
10+
class AbstractCodeLayer(AbstractLayer):
11+
category_only_codes: ClassVar[list[str]] = []
1112

1213

1314
class PlanTypeLayer(AbstractCodeLayer):
1415
name = "Kaavalaji"
1516

17+
category_only_codes: ClassVar[list[str]] = ["1", "2", "3"] # "Maakuntakaava", "Asemakaava", "Yleiskaava"
18+
1619

1720
class LifeCycleStatusLayer(AbstractCodeLayer):
1821
name = "Elinkaaren tila"
@@ -33,6 +36,15 @@ class PlanThemeLayer(AbstractCodeLayer):
3336
class AdditionalInformationTypeLayer(AbstractCodeLayer):
3437
name = "Lisätiedonlaji"
3538

39+
category_only_codes: ClassVar[list[str]] = [
40+
"tyyppi",
41+
"hairionTorjuntatarve",
42+
"merkittavyys",
43+
"eriTahojenTarpeisiinVaraaminen",
44+
"ymparistomuutoksenLaji",
45+
"rakentamisenOhjaus",
46+
]
47+
3648
@classmethod
3749
def get_additional_information_name(cls, info_type: str) -> str | None:
3850
attribute_value = cls.get_attribute_value_by_another_attribute_value("name", "value", info_type)
@@ -63,10 +75,20 @@ def get_id_by_feature_layer_name(cls, layer_name: str) -> str | None:
6375
class PlanRegulationTypeLayer(AbstractCodeLayer):
6476
name = "Kaavamääräyslaji"
6577

78+
# TODO: Implement. Currently, this is not used and information needed to construct plan regulation codes
79+
# is defined in a separate config file
80+
category_only_codes: ClassVar[list[str]] = []
81+
6682
@classmethod
6783
def get_regulation_type_by_id(cls, _id: str) -> str | None:
6884
attribute_value = cls.get_attribute_value_by_another_attribute_value("value", "id", _id)
6985
return cast(str, attribute_value) if attribute_value else attribute_value
7086

7187

88+
class VerbalRegulationType(AbstractCodeLayer):
89+
name = "Sanallisen määräyksen laji"
90+
91+
category_only_codes: ClassVar[list[str]] = ["maarayksenTyyppi"]
92+
93+
7294
code_layers = AbstractCodeLayer.__subclasses__()

arho_feature_template/project/layers/plan_layers.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,9 @@ def feature_from_model(cls, model: Regulation) -> QgsFeature:
318318
feature["text_value"] = {LANGUAGE: model.value if isinstance(model.value, str) else ""}
319319
feature["numeric_value"] = model.value if isinstance(model.value, Number) else NULL
320320
feature["name"] = {LANGUAGE: model.topic_tag if model.topic_tag else ""}
321+
feature["type_of_verbal_plan_regulation_id"] = model.verbal_regulation_type_id
321322
feature["id"] = model.id_ if model.id_ else feature["id"]
322323
# feature["plan_theme_id"]
323-
# feature["type_of_verbal_plan_regulation_id"]
324324

325325
return feature
326326

@@ -344,6 +344,7 @@ def model_from_feature(cls, feature: QgsFeature) -> Regulation:
344344
theme=None,
345345
topic_tag=None,
346346
regulation_group_id_=feature["plan_regulation_group_id"],
347+
verbal_regulation_type_id=feature["type_of_verbal_plan_regulation_id"],
347348
id_=feature["id"],
348349
)
349350

0 commit comments

Comments
 (0)