diff --git a/arho_feature_template/core/plan_manager.py b/arho_feature_template/core/plan_manager.py index 4b5a5cb..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() @@ -362,6 +363,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..655a84e 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 or [] + 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..4bea4f7 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,20 @@ 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"] + 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() + 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