diff --git a/arho_feature_template/gui/plan_attribure_form.py b/arho_feature_template/gui/plan_attribure_form.py
index b2f7a3a..7fdf960 100644
--- a/arho_feature_template/gui/plan_attribure_form.py
+++ b/arho_feature_template/gui/plan_attribure_form.py
@@ -1,20 +1,35 @@
from __future__ import annotations
+import os
from importlib import resources
+from pathlib import Path
from typing import TYPE_CHECKING
from qgis.PyQt import uic
-from qgis.PyQt.QtWidgets import QDialog, QDialogButtonBox
+from qgis.PyQt.QtCore import Qt
+from qgis.PyQt.QtWidgets import (
+ QComboBox,
+ QDialog,
+ QDialogButtonBox,
+ QLineEdit,
+ QSizePolicy,
+ QSpacerItem,
+ QTextEdit,
+ QTreeWidget,
+ QTreeWidgetItem,
+)
-from arho_feature_template.core.models import Plan
+from arho_feature_template.core.models import Plan, RegulationGroup, RegulationGroupLibrary
+from arho_feature_template.gui.plan_regulation_group_widget import RegulationGroupWidget
from arho_feature_template.project.layers.code_layers import (
LifeCycleStatusLayer,
OrganisationLayer,
PlanTypeLayer,
)
+from arho_feature_template.qgis_plugin_tools.tools.resources import resources_path
if TYPE_CHECKING:
- from qgis.PyQt.QtWidgets import QLineEdit, QTextEdit
+ from qgis.PyQt.QtWidgets import QComboBox, QLineEdit, QTextEdit, QTreeWidget, QWidget
from arho_feature_template.gui.code_combobox import CodeComboBox, HierarchicalCodeComboBox
@@ -33,6 +48,10 @@ class PlanAttributeForm(QDialog, FormClass): # type: ignore
producers_plan_identifier_line_edit: QLineEdit
matter_management_identifier_line_edit: QLineEdit
+ plan_regulation_group_scrollarea_contents: QWidget
+ plan_regulation_group_libraries_combobox: QComboBox
+ plan_regulation_groups_tree: QTreeWidget
+
button_box: QDialogButtonBox
def __init__(self, parent=None):
@@ -49,6 +68,11 @@ def __init__(self, parent=None):
self.plan_type_combo_box.currentIndexChanged.connect(self._check_required_fields)
self.lifecycle_status_combo_box.currentIndexChanged.connect(self._check_required_fields)
+ self.scroll_area_spacer = None
+ self.regulation_group_widgets: list[RegulationGroupWidget] = []
+ self.init_plan_regulation_group_libraries()
+ self.plan_regulation_groups_tree.itemDoubleClicked.connect(self.add_selected_plan_regulation_group)
+
self.button_box.button(QDialogButtonBox.Ok).setEnabled(False)
def _check_required_fields(self) -> None:
@@ -63,6 +87,55 @@ def _check_required_fields(self) -> None:
else:
ok_button.setEnabled(False)
+ # --- COPIED FROM TEMPLATE ATTRIBUTE FORM ---
+
+ def _add_spacer(self):
+ self.scroll_area_spacer = QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Expanding)
+ self.plan_regulation_group_scrollarea_contents.layout().addItem(self.scroll_area_spacer)
+
+ def _remove_spacer(self):
+ if self.scroll_area_spacer is not None:
+ self.plan_regulation_group_scrollarea_contents.layout().removeItem(self.scroll_area_spacer)
+ self.scroll_area_spacer = None
+
+ def add_selected_plan_regulation_group(self, item: QTreeWidgetItem, column: int):
+ if not item.parent():
+ return
+ regulation_group: RegulationGroup = item.data(column, Qt.UserRole)
+ self.add_plan_regulation_group(regulation_group)
+
+ def add_plan_regulation_group(self, regulation_group: RegulationGroup):
+ regulation_group_widget = RegulationGroupWidget(regulation_group, general_regulation=True)
+ regulation_group_widget.delete_signal.connect(self.remove_plan_regulation_group)
+ self._remove_spacer()
+ self.plan_regulation_group_scrollarea_contents.layout().addWidget(regulation_group_widget)
+ self.regulation_group_widgets.append(regulation_group_widget)
+ self._add_spacer()
+
+ def remove_plan_regulation_group(self, regulation_group_widget: RegulationGroupWidget):
+ self.plan_regulation_group_scrollarea_contents.layout().removeWidget(regulation_group_widget)
+ self.regulation_group_widgets.remove(regulation_group_widget)
+ regulation_group_widget.deleteLater()
+
+ def init_plan_regulation_group_libraries(self):
+ katja_asemakaava_path = Path(os.path.join(resources_path(), "katja_asemakaava.yaml"))
+ libraries = [RegulationGroupLibrary.from_config_file(katja_asemakaava_path)]
+ for library in libraries:
+ self.init_plan_regulation_group_library(library)
+
+ def init_plan_regulation_group_library(self, library: RegulationGroupLibrary):
+ self.plan_regulation_group_libraries_combobox.addItem(library.name)
+ for category in library.regulation_group_categories:
+ category_item = QTreeWidgetItem()
+ category_item.setText(0, category.name)
+ self.plan_regulation_groups_tree.addTopLevelItem(category_item)
+ for group_definition in category.regulation_groups:
+ regulation_group_item = QTreeWidgetItem(category_item)
+ regulation_group_item.setText(0, group_definition.name)
+ regulation_group_item.setData(0, Qt.UserRole, group_definition)
+
+ # ---
+
def get_plan_attributes(self) -> Plan:
return Plan(
id_=None,
@@ -75,5 +148,5 @@ def get_plan_attributes(self) -> Plan:
producers_plan_identifier=self.producers_plan_identifier_line_edit.text() or None,
matter_management_identifier=self.matter_management_identifier_line_edit.text() or None,
lifecycle_status_id=self.lifecycle_status_combo_box.value(),
- general_regulations=[],
+ general_regulations=[reg_group_widget.into_model() for reg_group_widget in self.regulation_group_widgets],
)
diff --git a/arho_feature_template/gui/plan_attribute_form.ui b/arho_feature_template/gui/plan_attribute_form.ui
index 70baa5d..0f65d24 100644
--- a/arho_feature_template/gui/plan_attribute_form.ui
+++ b/arho_feature_template/gui/plan_attribute_form.ui
@@ -9,8 +9,8 @@
0
0
- 535
- 343
+ 873
+ 662
@@ -34,16 +34,16 @@
- 0
+ 9
- 0
+ 9
- 0
+ 9
- 0
+ 9
-
@@ -61,19 +61,19 @@
0
0
- 505
- 264
+ 831
+ 562
- 0
+ 9
- 0
+ 9
- 0
+ 9
-
@@ -235,34 +235,115 @@
Yleismääräykset
-
-
- 0
-
-
- 0
-
-
- 0
-
-
- 0
-
+
-
-
-
- true
+
+
+ Yleismääräykset
-
-
-
- 0
- 0
- 505
- 264
-
-
-
+
+
-
+
+
-
+
+
+ Kaavamääräysryhmäkirjastot
+
+
+
+ -
+
+
+ -
+
+
+ false
+
+
+
+ 0
+ 0
+
+
+
+ Suodata kaavamääräysryhmiä
+
+
+ false
+
+
+ true
+
+
+
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ QFrame::StyledPanel
+
+
+ QFrame::Sunken
+
+
+ QAbstractItemView::NoEditTriggers
+
+
+ QAbstractItemView::NoDragDrop
+
+
+ false
+
+
+ false
+
+
+
+
+
+
+
+
+
+
+ -
+
+
-
+
+
+ Valitut yleismääräysryhmät
+
+
+
+ -
+
+
+ true
+
+
+
+
+ 0
+ 0
+ 541
+ 493
+
+
+
+
+
+
+
+
+
@@ -289,12 +370,17 @@
1
- HierarchicalCodeComboBox
+ QgsFilterLineEdit
+ QLineEdit
+
+
+
+ CodeComboBox
QComboBox
arho_feature_template.gui.code_combobox
- CodeComboBox
+ HierarchicalCodeComboBox
QComboBox
arho_feature_template.gui.code_combobox
diff --git a/arho_feature_template/gui/plan_regulation_group_widget.py b/arho_feature_template/gui/plan_regulation_group_widget.py
index 5ebdeec..ab6f750 100644
--- a/arho_feature_template/gui/plan_regulation_group_widget.py
+++ b/arho_feature_template/gui/plan_regulation_group_widget.py
@@ -26,7 +26,11 @@ class RegulationGroupWidget(QWidget, FormClass): # type: ignore
delete_signal = pyqtSignal(QWidget)
- def __init__(self, regulation_group_data: RegulationGroup):
+ def __init__(
+ self,
+ regulation_group_data: RegulationGroup,
+ general_regulation: bool = False, # noqa: FBT001, FBT002
+ ):
super().__init__()
self.setupUi(self)
@@ -34,6 +38,7 @@ def __init__(self, regulation_group_data: RegulationGroup):
self.frame: QFrame
self.name: QLineEdit
self.short_name: QLineEdit
+ self.short_name_label: QLabel
self.del_btn: QPushButton
self.type_of_regulation_group_label: QLabel
self.type_of_regulation_group: CodeComboBox
@@ -42,13 +47,25 @@ def __init__(self, regulation_group_data: RegulationGroup):
# by the plan feature directly (and hidden from user)
# INIT
+ self.is_general_regulation = general_regulation
self.regulation_group_data = regulation_group_data
self.regulation_widgets: list[RegulationWidget] = [
self.add_regulation_widget(regulation) for regulation in self.regulation_group_data.regulations
]
# If regulation group type code is defined, delete selection for user
+ if self.is_general_regulation:
+ regulation_group_data.type_code_id = PlanRegulationGroupTypeLayer.get_id_of_regulation_type(
+ "generalRegulations"
+ )
+ # Remove short name row
+ self.regulation_group_details_layout.removeWidget(self.short_name_label)
+ self.regulation_group_details_layout.removeWidget(self.short_name)
+ self.short_name_label.deleteLater()
+ self.short_name.deleteLater()
+
if regulation_group_data.type_code_id:
+ # Remove type of plan regulation group row
self.regulation_group_details_layout.removeWidget(self.type_of_regulation_group_label)
self.regulation_group_details_layout.removeWidget(self.type_of_regulation_group)
self.type_of_regulation_group_label.deleteLater()
@@ -79,7 +96,7 @@ def into_model(self) -> RegulationGroup:
if self.regulation_group_data.type_code_id
else self.type_of_regulation_group.value(),
name=self.name.text(),
- short_name=self.short_name.text(),
+ short_name=None if self.is_general_regulation else self.short_name.text(),
color_code=self.regulation_group_data.color_code,
regulations=[widget.into_model() for widget in self.regulation_widgets],
id_=self.regulation_group_data.id_,
diff --git a/arho_feature_template/gui/plan_regulation_group_widget.ui b/arho_feature_template/gui/plan_regulation_group_widget.ui
index 11f4ee8..9b50143 100644
--- a/arho_feature_template/gui/plan_regulation_group_widget.ui
+++ b/arho_feature_template/gui/plan_regulation_group_widget.ui
@@ -146,7 +146,7 @@
-
-
+
Lyhyt nimi