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

Näytä "Maankäytön kohde" kaavakohdetyyppi vain maakuntakaavoille #201

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
2 changes: 2 additions & 0 deletions arho_feature_template/core/plan_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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):
Expand Down
14 changes: 11 additions & 3 deletions arho_feature_template/gui/components/new_feature_grid_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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))
Expand Down Expand Up @@ -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)
15 changes: 15 additions & 0 deletions arho_feature_template/gui/docks/new_feature_dock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Selvisi, että myös yleiskaavoissa maankäytön kohteille on tarvetta.

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
Expand Down
12 changes: 10 additions & 2 deletions arho_feature_template/project/layers/plan_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down
Loading