From 0c2f8fa1ded2b9a1d7b86c5b3a4863cdd12726a3 Mon Sep 17 00:00:00 2001 From: Niko Aarnio Date: Wed, 22 Jan 2025 12:23:33 +0200 Subject: [PATCH] add type of verbal plan regulation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- arho_feature_template/core/models.py | 4 +--- .../gui/components/code_combobox.py | 10 ++++---- .../gui/components/plan_regulation_widget.py | 14 +++++++++-- .../project/layers/code_layers.py | 24 ++++++++++++++++++- .../project/layers/plan_layers.py | 3 ++- 5 files changed, 43 insertions(+), 12 deletions(-) diff --git a/arho_feature_template/core/models.py b/arho_feature_template/core/models.py index 024d2a5..6511c95 100644 --- a/arho_feature_template/core/models.py +++ b/arho_feature_template/core/models.py @@ -255,11 +255,9 @@ class Regulation: files: list[str] = field(default_factory=list) theme: str | None = None topic_tag: str | None = None + verbal_regulation_type_id: str | None = None regulation_group_id_: int | None = None id_: int | None = None - # value_string: str | None - # value_number: Number | None - # value_number_pair: tuple[Number, Number] | None @dataclass diff --git a/arho_feature_template/gui/components/code_combobox.py b/arho_feature_template/gui/components/code_combobox.py index d22257c..fc7b1a4 100644 --- a/arho_feature_template/gui/components/code_combobox.py +++ b/arho_feature_template/gui/components/code_combobox.py @@ -82,15 +82,15 @@ def populate_from_code_layer(self, layer_type: type[AbstractCodeLayer]) -> None: item = QTreeWidgetItem() items[code_feature["id"]] = item - text = code_feature["name"][LANGUAGE] - item.setText(0, text) - description = code_feature["description"][LANGUAGE] - item.setToolTip(0, description) + item.setText(0, code_feature["name"][LANGUAGE]) + item.setToolTip(0, code_feature["description"][LANGUAGE]) item.setData(0, Qt.UserRole, code_feature["id"]) + if code_feature["value"] in layer_type.category_only_codes: + item.setFlags(item.flags() & ~Qt.ItemIsSelectable) + if code_feature["level"] == 1: self.tree_widget.addTopLevelItem(item) - item.setFlags(item.flags() & ~Qt.ItemIsSelectable) else: parent = items[code_feature["parent_id"]] parent.addChild(item) diff --git a/arho_feature_template/gui/components/plan_regulation_widget.py b/arho_feature_template/gui/components/plan_regulation_widget.py index 53b565a..866ee73 100644 --- a/arho_feature_template/gui/components/plan_regulation_widget.py +++ b/arho_feature_template/gui/components/plan_regulation_widget.py @@ -17,6 +17,7 @@ ) from arho_feature_template.core.models import Regulation, ValueType +from arho_feature_template.gui.components.code_combobox import HierarchicalCodeComboBox from arho_feature_template.gui.components.plan_regulation_input_widgets import ( DecimalInputWidget, IntegerInputWidget, @@ -24,7 +25,7 @@ MultilineTextInputWidget, SinglelineTextInputWidget, ) -from arho_feature_template.project.layers.code_layers import AdditionalInformationTypeLayer +from arho_feature_template.project.layers.code_layers import AdditionalInformationTypeLayer, VerbalRegulationType from arho_feature_template.utils.misc_utils import LANGUAGE, get_layer_by_name, iface if TYPE_CHECKING: @@ -67,6 +68,7 @@ def __init__(self, regulation: Regulation, parent=None): self.file_widgets: list[QgsFileWidget] = [] self.theme_widget: SinglelineTextInputWidget | None = None self.topic_tag_widget: SinglelineTextInputWidget | None = None + self.type_of_verbal_regulation_widget: HierarchicalCodeComboBox | None = None self.expanded = True self.plan_regulation_name.setText(self.config.name) @@ -83,6 +85,12 @@ def _init_widgets(self): value_type = self.config.value_type if value_type: self._add_value_input(value_type, self.config.unit, self.regulation.value) + if self.config.regulation_code == "sanallinenMaarays": + self.type_of_verbal_regulation_widget = HierarchicalCodeComboBox() + self.type_of_verbal_regulation_widget.populate_from_code_layer(VerbalRegulationType) + self._add_widgets(QLabel("Sanallisen määräyksen laji"), self.type_of_verbal_regulation_widget) + if self.regulation.verbal_regulation_type_id is not None: + self.type_of_verbal_regulation_widget.set_value(self.regulation.verbal_regulation_type_id) # Additional information if self.regulation.additional_information: @@ -249,7 +257,6 @@ def _add_theme(self, theme_name: str): self.theme_widget = SinglelineTextInputWidget(theme_name, False) self._add_widgets(QLabel("Kaavoitusteema"), self.theme_widget) - # Or e.g. "into_regulation" def into_model(self) -> Regulation: return Regulation( config=self.config, @@ -261,5 +268,8 @@ def into_model(self) -> Regulation: files=[file.filePath() for file in self.file_widgets], theme=self.theme_widget.get_value() if self.theme_widget else None, topic_tag=self.topic_tag_widget.get_value() if self.topic_tag_widget else None, + verbal_regulation_type_id=self.type_of_verbal_regulation_widget.value() + if self.type_of_verbal_regulation_widget + else None, id_=self.regulation.id_, ) diff --git a/arho_feature_template/project/layers/code_layers.py b/arho_feature_template/project/layers/code_layers.py index 2478da3..e96c706 100644 --- a/arho_feature_template/project/layers/code_layers.py +++ b/arho_feature_template/project/layers/code_layers.py @@ -7,12 +7,15 @@ from arho_feature_template.utils.misc_utils import LANGUAGE -class AbstractCodeLayer(AbstractLayer): ... +class AbstractCodeLayer(AbstractLayer): + category_only_codes: ClassVar[list[str]] = [] class PlanTypeLayer(AbstractCodeLayer): name = "Kaavalaji" + category_only_codes: ClassVar[list[str]] = ["1", "2", "3"] # "Maakuntakaava", "Asemakaava", "Yleiskaava" + class LifeCycleStatusLayer(AbstractCodeLayer): name = "Elinkaaren tila" @@ -33,6 +36,15 @@ class PlanThemeLayer(AbstractCodeLayer): class AdditionalInformationTypeLayer(AbstractCodeLayer): name = "Lisätiedonlaji" + category_only_codes: ClassVar[list[str]] = [ + "tyyppi", + "hairionTorjuntatarve", + "merkittavyys", + "eriTahojenTarpeisiinVaraaminen", + "ymparistomuutoksenLaji", + "rakentamisenOhjaus", + ] + @classmethod def get_additional_information_name(cls, info_type: str) -> str | None: 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: class PlanRegulationTypeLayer(AbstractCodeLayer): name = "Kaavamääräyslaji" + # TODO: Implement. Currently, this is not used and information needed to construct plan regulation codes + # is defined in a separate config file + category_only_codes: ClassVar[list[str]] = [] + @classmethod def get_regulation_type_by_id(cls, _id: str) -> str | None: attribute_value = cls.get_attribute_value_by_another_attribute_value("value", "id", _id) return cast(str, attribute_value) if attribute_value else attribute_value +class VerbalRegulationType(AbstractCodeLayer): + name = "Sanallisen määräyksen laji" + + category_only_codes: ClassVar[list[str]] = ["maarayksenTyyppi"] + + code_layers = AbstractCodeLayer.__subclasses__() diff --git a/arho_feature_template/project/layers/plan_layers.py b/arho_feature_template/project/layers/plan_layers.py index 50df721..fff22f8 100644 --- a/arho_feature_template/project/layers/plan_layers.py +++ b/arho_feature_template/project/layers/plan_layers.py @@ -318,9 +318,9 @@ def feature_from_model(cls, model: Regulation) -> QgsFeature: feature["text_value"] = {LANGUAGE: model.value if isinstance(model.value, str) else ""} feature["numeric_value"] = model.value if isinstance(model.value, Number) else NULL feature["name"] = {LANGUAGE: model.topic_tag if model.topic_tag else ""} + feature["type_of_verbal_plan_regulation_id"] = model.verbal_regulation_type_id feature["id"] = model.id_ if model.id_ else feature["id"] # feature["plan_theme_id"] - # feature["type_of_verbal_plan_regulation_id"] return feature @@ -344,6 +344,7 @@ def model_from_feature(cls, feature: QgsFeature) -> Regulation: theme=None, topic_tag=None, regulation_group_id_=feature["plan_regulation_group_id"], + verbal_regulation_type_id=feature["type_of_verbal_plan_regulation_id"], id_=feature["id"], )