Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanallisen määräyksen laji #125

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions arho_feature_template/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions arho_feature_template/gui/components/code_combobox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 12 additions & 2 deletions arho_feature_template/gui/components/plan_regulation_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
)

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,
IntegerRangeInputWidget,
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:
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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,
Expand All @@ -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_,
)
24 changes: 23 additions & 1 deletion arho_feature_template/project/layers/code_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down Expand Up @@ -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__()
3 changes: 2 additions & 1 deletion arho_feature_template/project/layers/plan_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"],
)

Expand Down
Loading