From 02a777abe4d3146375b958dd8c2602aa83b3c1a8 Mon Sep 17 00:00:00 2001 From: Niko Aarnio Date: Mon, 24 Feb 2025 15:08:54 +0200 Subject: [PATCH 1/2] =?UTF-8?q?include=20"Maank=C3=A4yt=C3=B6n=20kohde"=20?= =?UTF-8?q?feature=20type=20only=20for=20regional=20plan=20types?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arho_feature_template/core/plan_manager.py | 1 + .../gui/components/new_feature_grid_widget.py | 14 +++++++++++--- .../gui/docks/new_feature_dock.py | 8 ++++++++ .../project/layers/plan_layers.py | 12 ++++++++++-- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/arho_feature_template/core/plan_manager.py b/arho_feature_template/core/plan_manager.py index 4b5a5cb..625d70f 100644 --- a/arho_feature_template/core/plan_manager.py +++ b/arho_feature_template/core/plan_manager.py @@ -362,6 +362,7 @@ def set_active_plan(self, plan_id: str | None): if previously_in_edit_mode: plan_layer.startEditing() + self.new_feature_dock.set_plan(plan_id) self.update_active_plan_regulation_group_library() def load_land_use_plan(self): diff --git a/arho_feature_template/gui/components/new_feature_grid_widget.py b/arho_feature_template/gui/components/new_feature_grid_widget.py index 7c0dac6..67f7e0f 100644 --- a/arho_feature_template/gui/components/new_feature_grid_widget.py +++ b/arho_feature_template/gui/components/new_feature_grid_widget.py @@ -4,7 +4,7 @@ from qgis.PyQt.QtGui import QPalette from qgis.PyQt.QtWidgets import QListWidget, QListWidgetItem, QPushButton -FEATURE_TYPES = ["Aluevaraus", "Osa-alue", "Viiva", "Maankäytön\nkohde", "Muu piste"] +FEATURE_TYPES = ["Aluevaraus", "Osa-alue", "Viiva", "Maankäytön kohde", "Muu piste"] FEATURE_TYPE_TO_LAYER_NAME = { "Viiva": "Viivat", "Osa-alue": "Osa-alue", @@ -31,7 +31,15 @@ def __init__(self): self.setHorizontalScrollMode(self.ScrollPerPixel) self.setVerticalScrollMode(self.ScrollPerPixel) - self.buttons = {feature_type: FeatureButton(feature_type) for feature_type in FEATURE_TYPES} + self.initialize_buttons() + + def initialize_buttons(self, exclude: list | None = None): + self.clear() + + exclude = exclude if exclude else [] + self.buttons = { + feature_type: FeatureButton(feature_type) for feature_type in FEATURE_TYPES if feature_type not in exclude + } for btn in self.buttons.values(): self.add_button(btn) btn.clicked.connect(lambda _, button=btn: self.handle_button_click(button)) @@ -72,6 +80,6 @@ def clear_selections(self, exclude: FeatureButton | None = None): class FeatureButton(QPushButton): def __init__(self, text: str): super().__init__() - self.setText(text) + self.setText(text.replace(" ", "\n")) self.setFixedSize(FEATURE_BUTTON_WIDTH, FEATURE_BUTTON_HEIGHT) self.setCheckable(True) diff --git a/arho_feature_template/gui/docks/new_feature_dock.py b/arho_feature_template/gui/docks/new_feature_dock.py index c5b1cda..86811f1 100644 --- a/arho_feature_template/gui/docks/new_feature_dock.py +++ b/arho_feature_template/gui/docks/new_feature_dock.py @@ -9,6 +9,7 @@ from qgis.PyQt.QtWidgets import QListWidget, QListWidgetItem from arho_feature_template.gui.components.new_feature_grid_widget import NewFeatureGridWidget +from arho_feature_template.project.layers.plan_layers import PlanLayer if TYPE_CHECKING: from qgis.gui import QgsFilterLineEdit @@ -58,6 +59,13 @@ def initialize_feature_template_libraries(self, feature_template_libraries: list self.library_selection.addItems([library.name for library in self.feature_template_libraries]) self.set_active_feature_template_library(0) + def set_plan(self, plan_id: str): + regional_plan_type_names = ["Kokonaismaakuntakaava", "Vaihemaakuntakaava"] + if PlanLayer.get_plan_type_name(plan_id) not in regional_plan_type_names: + self.new_feature_grid.initialize_buttons(exclude=["Maankäytön kohde"]) + else: + self.new_feature_grid.initialize_buttons() + def on_active_feature_type_changed(self, feature_name: str, layer_name: str): self.active_feature_type = feature_name if feature_name else None self.active_feature_layer = layer_name if layer_name else None diff --git a/arho_feature_template/project/layers/plan_layers.py b/arho_feature_template/project/layers/plan_layers.py index 124bd69..3441a84 100644 --- a/arho_feature_template/project/layers/plan_layers.py +++ b/arho_feature_template/project/layers/plan_layers.py @@ -4,7 +4,7 @@ from abc import abstractmethod from string import Template from textwrap import dedent -from typing import Any, ClassVar, Generator +from typing import Any, ClassVar, Generator, cast from qgis.core import QgsFeature, QgsVectorLayerUtils @@ -23,7 +23,7 @@ ) from arho_feature_template.exceptions import FeatureNotFoundError, LayerEditableError, LayerNotFoundError from arho_feature_template.project.layers import AbstractLayer -from arho_feature_template.project.layers.code_layers import PlanRegulationTypeLayer +from arho_feature_template.project.layers.code_layers import PlanRegulationTypeLayer, PlanTypeLayer from arho_feature_template.utils.misc_utils import ( deserialize_localized_text, get_active_plan_id, @@ -139,6 +139,14 @@ def get_plan_name(cls, plan_id: str) -> str: return name or "Nimetön" + @classmethod + def get_plan_type_name(cls, plan_id: str) -> str | None: + type_id = cls.get_attribute_value_by_another_attribute_value("plan_type_id", "id", plan_id) + if type_id is None: + return None + attribute_value = PlanTypeLayer.get_attribute_value_by_another_attribute_value("name", "id", cast(str, type_id)) + return deserialize_localized_text(attribute_value) + class PlanFeatureLayer(AbstractPlanLayer): @classmethod From 30f82f94876f55cc4336a88db75a389066caaa69 Mon Sep 17 00:00:00 2001 From: Niko Aarnio Date: Thu, 27 Feb 2025 09:33:16 +0200 Subject: [PATCH 2/2] =?UTF-8?q?include=20"Maank=C3=A4yt=C3=B6n=20kohde"=20?= =?UTF-8?q?feature=20type=20also=20for=20general=20plan=20types,=20update?= =?UTF-8?q?=20feature=20dock=20when=20plan=20is=20edited?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arho_feature_template/core/plan_manager.py | 1 + .../gui/components/new_feature_grid_widget.py | 2 +- arho_feature_template/gui/docks/new_feature_dock.py | 9 ++++++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/arho_feature_template/core/plan_manager.py b/arho_feature_template/core/plan_manager.py index 625d70f..3f9df8a 100644 --- a/arho_feature_template/core/plan_manager.py +++ b/arho_feature_template/core/plan_manager.py @@ -253,6 +253,7 @@ def edit_plan(self): feature = save_plan(attribute_form.model) if feature: self.update_active_plan_regulation_group_library() + self.new_feature_dock.set_plan(feature["id"]) # Update feature dock in case plan type changed def edit_lifecycles(self): plan_layer = PlanLayer.get_from_project() diff --git a/arho_feature_template/gui/components/new_feature_grid_widget.py b/arho_feature_template/gui/components/new_feature_grid_widget.py index 67f7e0f..655a84e 100644 --- a/arho_feature_template/gui/components/new_feature_grid_widget.py +++ b/arho_feature_template/gui/components/new_feature_grid_widget.py @@ -36,7 +36,7 @@ def __init__(self): def initialize_buttons(self, exclude: list | None = None): self.clear() - exclude = exclude if exclude else [] + exclude = exclude or [] self.buttons = { feature_type: FeatureButton(feature_type) for feature_type in FEATURE_TYPES if feature_type not in exclude } diff --git a/arho_feature_template/gui/docks/new_feature_dock.py b/arho_feature_template/gui/docks/new_feature_dock.py index 86811f1..4bea4f7 100644 --- a/arho_feature_template/gui/docks/new_feature_dock.py +++ b/arho_feature_template/gui/docks/new_feature_dock.py @@ -61,7 +61,14 @@ def initialize_feature_template_libraries(self, feature_template_libraries: list def set_plan(self, plan_id: str): regional_plan_type_names = ["Kokonaismaakuntakaava", "Vaihemaakuntakaava"] - if PlanLayer.get_plan_type_name(plan_id) not in regional_plan_type_names: + general_plan_type_names = [ + "Yleiskaava", + "Vaiheyleiskaava", + "Osayleiskaava", + "Kuntien yhteinen yleiskaava", + "Maanalainen yleiskaava", + ] + if PlanLayer.get_plan_type_name(plan_id) not in regional_plan_type_names + general_plan_type_names: self.new_feature_grid.initialize_buttons(exclude=["Maankäytön kohde"]) else: self.new_feature_grid.initialize_buttons()