Skip to content

Commit a29dcc3

Browse files
committed
include "Maankäytön kohde" feature type only for regional plan types
1 parent f657c3a commit a29dcc3

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

arho_feature_template/core/plan_manager.py

+1
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ def set_active_plan(self, plan_id: str | None):
355355
if previously_in_edit_mode:
356356
plan_layer.startEditing()
357357

358+
self.new_feature_dock.set_plan(plan_id)
358359
self.update_active_plan_regulation_group_library()
359360

360361
def load_land_use_plan(self):

arho_feature_template/gui/components/new_feature_grid_widget.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from qgis.PyQt.QtGui import QPalette
55
from qgis.PyQt.QtWidgets import QListWidget, QListWidgetItem, QPushButton
66

7-
FEATURE_TYPES = ["Aluevaraus", "Osa-alue", "Viiva", "Maankäytön\nkohde", "Muu piste"]
7+
FEATURE_TYPES = ["Aluevaraus", "Osa-alue", "Viiva", "Maankäytön kohde", "Muu piste"]
88
FEATURE_TYPE_TO_LAYER_NAME = {
99
"Viiva": "Viivat",
1010
"Osa-alue": "Osa-alue",
@@ -31,7 +31,15 @@ def __init__(self):
3131
self.setHorizontalScrollMode(self.ScrollPerPixel)
3232
self.setVerticalScrollMode(self.ScrollPerPixel)
3333

34-
self.buttons = {feature_type: FeatureButton(feature_type) for feature_type in FEATURE_TYPES}
34+
self.initialize_buttons()
35+
36+
def initialize_buttons(self, exclude: list | None = None):
37+
self.clear()
38+
39+
exclude = exclude if exclude else []
40+
self.buttons = {
41+
feature_type: FeatureButton(feature_type) for feature_type in FEATURE_TYPES if feature_type not in exclude
42+
}
3543
for btn in self.buttons.values():
3644
self.add_button(btn)
3745
btn.clicked.connect(lambda _, button=btn: self.handle_button_click(button))
@@ -72,6 +80,6 @@ def clear_selections(self, exclude: FeatureButton | None = None):
7280
class FeatureButton(QPushButton):
7381
def __init__(self, text: str):
7482
super().__init__()
75-
self.setText(text)
83+
self.setText(text.replace(" ", "\n"))
7684
self.setFixedSize(FEATURE_BUTTON_WIDTH, FEATURE_BUTTON_HEIGHT)
7785
self.setCheckable(True)

arho_feature_template/gui/docks/new_feature_dock.py

+8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from qgis.PyQt.QtWidgets import QListWidget, QListWidgetItem
1010

1111
from arho_feature_template.gui.components.new_feature_grid_widget import NewFeatureGridWidget
12+
from arho_feature_template.project.layers.plan_layers import PlanLayer
1213

1314
if TYPE_CHECKING:
1415
from qgis.gui import QgsFilterLineEdit
@@ -58,6 +59,13 @@ def initialize_feature_template_libraries(self, feature_template_libraries: list
5859
self.library_selection.addItems([library.name for library in self.feature_template_libraries])
5960
self.set_active_feature_template_library(0)
6061

62+
def set_plan(self, plan_id: str):
63+
regional_plan_type_names = ["Kokonaismaakuntakaava", "Vaihemaakuntakaava"]
64+
if PlanLayer.get_plan_type_name(plan_id) not in regional_plan_type_names:
65+
self.new_feature_grid.initialize_buttons(exclude=["Maankäytön kohde"])
66+
else:
67+
self.new_feature_grid.initialize_buttons()
68+
6169
def on_active_feature_type_changed(self, feature_name: str, layer_name: str):
6270
self.active_feature_type = feature_name if feature_name else None
6371
self.active_feature_layer = layer_name if layer_name else None

arho_feature_template/project/layers/plan_layers.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from abc import abstractmethod
55
from string import Template
66
from textwrap import dedent
7-
from typing import Any, ClassVar, Generator
7+
from typing import Any, ClassVar, Generator, cast
88

99
from qgis.core import QgsFeature, QgsVectorLayerUtils
1010

@@ -23,7 +23,7 @@
2323
)
2424
from arho_feature_template.exceptions import FeatureNotFoundError, LayerEditableError, LayerNotFoundError
2525
from arho_feature_template.project.layers import AbstractLayer
26-
from arho_feature_template.project.layers.code_layers import PlanRegulationTypeLayer
26+
from arho_feature_template.project.layers.code_layers import PlanRegulationTypeLayer, PlanTypeLayer
2727
from arho_feature_template.utils.misc_utils import (
2828
deserialize_localized_text,
2929
get_active_plan_id,
@@ -139,6 +139,14 @@ def get_plan_name(cls, plan_id: str) -> str:
139139

140140
return name or "Nimetön"
141141

142+
@classmethod
143+
def get_plan_type_name(cls, plan_id: str) -> str | None:
144+
type_id = cls.get_attribute_value_by_another_attribute_value("plan_type_id", "id", plan_id)
145+
if type_id is None:
146+
return None
147+
attribute_value = PlanTypeLayer.get_attribute_value_by_another_attribute_value("name", "id", cast(str, type_id))
148+
return deserialize_localized_text(attribute_value)
149+
142150

143151
class PlanFeatureLayer(AbstractPlanLayer):
144152
@classmethod

0 commit comments

Comments
 (0)