From b2665ecf425663204534c77e1f457e7f6a6c97bb Mon Sep 17 00:00:00 2001 From: Niko Aarnio Date: Tue, 29 Oct 2024 13:16:09 +0200 Subject: [PATCH 1/5] feat: add alternative, not templated based UI for adding plan regulation groups (WIP) --- .../gui/create_plan_regulation_group_form.ui | 610 ++++++++++++++++++ 1 file changed, 610 insertions(+) create mode 100644 arho_feature_template/gui/create_plan_regulation_group_form.ui diff --git a/arho_feature_template/gui/create_plan_regulation_group_form.ui b/arho_feature_template/gui/create_plan_regulation_group_form.ui new file mode 100644 index 0000000..ee7b14a --- /dev/null +++ b/arho_feature_template/gui/create_plan_regulation_group_form.ui @@ -0,0 +1,610 @@ + + + Form + + + + 0 + 0 + 946 + 733 + + + + + 0 + 0 + + + + Lisää kaavamääräysryhmä + + + + + + + + Kaavamääräysryhmän otsikko + + + + + + + + + + Kaavamääräysryhmän tyyppi + + + + + + + + + + + + 0 + + + + Kaavamääräykset + + + + + + + + + 0 + 0 + + + + Valittavat kaavamääräykset + + + + + + + + 0 + 0 + + + + Suodata kaavamääräyksiä + + + true + + + true + + + + + + + + + + + 0 + 0 + + + + false + + + + 1 + + + + + Käyttötarkoitusalue + + + + Asumisen alue + + + + + Liikerakennusten alue + + + + + Toimitilojen alue + + + + + Vapaa-ajan asumisen alue + + + + + Urheilu- ja virkistyspalvelujen alue + + + + + + Sanallinen määräys + + + + Sanallinen määräys + + + + + Suunnittelumääräys + + + + + Toimenpiderajoitus + + + + + + Suureellinen määräys + + + + Autopaikkojen määrä asuntoja kohden + + + + + Korttelin numero + + + + + + Rakennusala + + + + + Rakennuspaikka + + + + + + + + + + Qt::Vertical + + + + + + + + + + + Lisätyt kaavamääräykset + + + + + + + true + + + + + 0 + 0 + 613 + 584 + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + Kaavamääräyslaji + + + + + + + Urheilu- ja virkistyspalvelujen alue + + + + + + + Lisätieto + + + + + + + + + Pääkäyttötarkoitus + + + + + + + + + + + arho_feature_template/resources/icons/settings.svgarho_feature_template/resources/icons/settings.svg + + + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + Kaavamääräyslaji + + + + + + + Palvelujen alue + + + + + + + Lisätieto + + + + + + + + + Pääkäyttötarkoitus + + + + + + + + + + + arho_feature_template/resources/icons/settings.svgarho_feature_template/resources/icons/settings.svg + + + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + Kaavamääräyslaji + + + + + + + Matkailupalvelujen alue + + + + + + + Lisätieto + + + + + + + + + Pääkäyttötarkoitus + + + + + + + + + + + arho_feature_template/resources/icons/settings.svgarho_feature_template/resources/icons/settings.svg + + + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + Kaavamääräyslaji + + + + + + + Sanallinen määräys + + + + + + + Sanallisen kaavamääräyksen laji + + + + + + + + Tontin käyttö + + + + + + + + Arvo + + + + + + + + + + 0 + 0 + + + + Alue varataan virkistys, matkailu- ja vapaa-ajan toiminnoille. Alueelle voidaan sijoittaa pääkäyttötarkoitusta palvelevia rakennuksia ja rakenteita, kuten pienimuotoisia majoituspalveluja, leirintäalueita, ryhmäpuutarhoja sekä muita virkistystä, matkailua, kokoontumistiloja tai lomailua palvelevia toimintoja ja elinkeinoja. + + + + + + + + + + 0 + 0 + + + + + + + + arho_feature_template/resources/icons/settings.svgarho_feature_template/resources/icons/settings.svg + + + + + + + ... + + + + + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + Kaavamääräyslaji + + + + + + + Toimenpiderajoitus + + + + + + + Sanallisen kaavamääräyksen laji + + + + + + + + Maisema + + + + + + + + Arvo + + + + + + + + + + 0 + 0 + + + + Rakentamisen määrä ja laatu on sovitettava maisemaan ja muuhun ympäristöön. Alueen maisemaa muuttava maarakennustyö, puiden kaataminen tai muu näihin verrattavissa oleva toimenpide luvanvaraista siten kuin MRL 128 § ̵:ssä on säädetty. + + + + + + + + + + 0 + 0 + + + + + + + + arho_feature_template/resources/icons/settings.svgarho_feature_template/resources/icons/settings.svg + + + + + + + ... + + + + + + + + + + + + + + + + + + + + + + + Suositukset + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + QgsFilterLineEdit + QLineEdit +
qgsfilterlineedit.h
+
+
+ + +
From d57e6414b08d2bfd9879601bd78242751e9acba6 Mon Sep 17 00:00:00 2001 From: Niko Aarnio Date: Tue, 29 Oct 2024 13:33:15 +0200 Subject: [PATCH 2/5] add fields to plan regulation group form --- .../gui/create_plan_regulation_group_form.ui | 62 ++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/arho_feature_template/gui/create_plan_regulation_group_form.ui b/arho_feature_template/gui/create_plan_regulation_group_form.ui index ee7b14a..3cc8105 100644 --- a/arho_feature_template/gui/create_plan_regulation_group_form.ui +++ b/arho_feature_template/gui/create_plan_regulation_group_form.ui @@ -25,7 +25,7 @@ - Kaavamääräysryhmän otsikko + Kaavamääräyksen otsikko @@ -42,6 +42,66 @@ + + + + Kirjaintunnus + + + + + + + + + + Värikoodi + + + + + + + + + + Ryhmän numero + + + + + + + + + + Kaavamääräysryhmän avain + + + + + + + + + + Maanalaisuus + + + + + + + + + + + + + Pystysuuntainen rajaus + + + From 68ccb06a10154f41f6c42481627716b93aef5a86 Mon Sep 17 00:00:00 2001 From: Niko Aarnio Date: Thu, 7 Nov 2024 17:14:37 +0200 Subject: [PATCH 3/5] add new draft version of plan regulation creation form --- .../gui/create_plan_regulation_group_form.ui | 670 ------------------ .../gui/new_plan_regulation_group_form.py | 44 ++ .../gui/new_plan_regulation_group_form.ui | 188 +++++ .../gui/new_plan_regulation_widget.py | 61 ++ .../gui/new_plan_regulation_widget.ui | 173 +++++ arho_feature_template/plugin.py | 13 + 6 files changed, 479 insertions(+), 670 deletions(-) delete mode 100644 arho_feature_template/gui/create_plan_regulation_group_form.ui create mode 100644 arho_feature_template/gui/new_plan_regulation_group_form.py create mode 100644 arho_feature_template/gui/new_plan_regulation_group_form.ui create mode 100644 arho_feature_template/gui/new_plan_regulation_widget.py create mode 100644 arho_feature_template/gui/new_plan_regulation_widget.ui diff --git a/arho_feature_template/gui/create_plan_regulation_group_form.ui b/arho_feature_template/gui/create_plan_regulation_group_form.ui deleted file mode 100644 index 3cc8105..0000000 --- a/arho_feature_template/gui/create_plan_regulation_group_form.ui +++ /dev/null @@ -1,670 +0,0 @@ - - - Form - - - - 0 - 0 - 946 - 733 - - - - - 0 - 0 - - - - Lisää kaavamääräysryhmä - - - - - - - - Kaavamääräyksen otsikko - - - - - - - - - - Kaavamääräysryhmän tyyppi - - - - - - - - - - Kirjaintunnus - - - - - - - - - - Värikoodi - - - - - - - - - - Ryhmän numero - - - - - - - - - - Kaavamääräysryhmän avain - - - - - - - - - - Maanalaisuus - - - - - - - - - - - - - Pystysuuntainen rajaus - - - - - - - - - 0 - - - - Kaavamääräykset - - - - - - - - - 0 - 0 - - - - Valittavat kaavamääräykset - - - - - - - - 0 - 0 - - - - Suodata kaavamääräyksiä - - - true - - - true - - - - - - - - - - - 0 - 0 - - - - false - - - - 1 - - - - - Käyttötarkoitusalue - - - - Asumisen alue - - - - - Liikerakennusten alue - - - - - Toimitilojen alue - - - - - Vapaa-ajan asumisen alue - - - - - Urheilu- ja virkistyspalvelujen alue - - - - - - Sanallinen määräys - - - - Sanallinen määräys - - - - - Suunnittelumääräys - - - - - Toimenpiderajoitus - - - - - - Suureellinen määräys - - - - Autopaikkojen määrä asuntoja kohden - - - - - Korttelin numero - - - - - - Rakennusala - - - - - Rakennuspaikka - - - - - - - - - - Qt::Vertical - - - - - - - - - - - Lisätyt kaavamääräykset - - - - - - - true - - - - - 0 - 0 - 613 - 584 - - - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - Kaavamääräyslaji - - - - - - - Urheilu- ja virkistyspalvelujen alue - - - - - - - Lisätieto - - - - - - - - - Pääkäyttötarkoitus - - - - - - - - - - - arho_feature_template/resources/icons/settings.svgarho_feature_template/resources/icons/settings.svg - - - - - - - - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - Kaavamääräyslaji - - - - - - - Palvelujen alue - - - - - - - Lisätieto - - - - - - - - - Pääkäyttötarkoitus - - - - - - - - - - - arho_feature_template/resources/icons/settings.svgarho_feature_template/resources/icons/settings.svg - - - - - - - - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - Kaavamääräyslaji - - - - - - - Matkailupalvelujen alue - - - - - - - Lisätieto - - - - - - - - - Pääkäyttötarkoitus - - - - - - - - - - - arho_feature_template/resources/icons/settings.svgarho_feature_template/resources/icons/settings.svg - - - - - - - - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - Kaavamääräyslaji - - - - - - - Sanallinen määräys - - - - - - - Sanallisen kaavamääräyksen laji - - - - - - - - Tontin käyttö - - - - - - - - Arvo - - - - - - - - - - 0 - 0 - - - - Alue varataan virkistys, matkailu- ja vapaa-ajan toiminnoille. Alueelle voidaan sijoittaa pääkäyttötarkoitusta palvelevia rakennuksia ja rakenteita, kuten pienimuotoisia majoituspalveluja, leirintäalueita, ryhmäpuutarhoja sekä muita virkistystä, matkailua, kokoontumistiloja tai lomailua palvelevia toimintoja ja elinkeinoja. - - - - - - - - - - 0 - 0 - - - - - - - - arho_feature_template/resources/icons/settings.svgarho_feature_template/resources/icons/settings.svg - - - - - - - ... - - - - - - - - - - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - Kaavamääräyslaji - - - - - - - Toimenpiderajoitus - - - - - - - Sanallisen kaavamääräyksen laji - - - - - - - - Maisema - - - - - - - - Arvo - - - - - - - - - - 0 - 0 - - - - Rakentamisen määrä ja laatu on sovitettava maisemaan ja muuhun ympäristöön. Alueen maisemaa muuttava maarakennustyö, puiden kaataminen tai muu näihin verrattavissa oleva toimenpide luvanvaraista siten kuin MRL 128 § ̵:ssä on säädetty. - - - - - - - - - - 0 - 0 - - - - - - - - arho_feature_template/resources/icons/settings.svgarho_feature_template/resources/icons/settings.svg - - - - - - - ... - - - - - - - - - - - - - - - - - - - - - - - Suositukset - - - - - - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - QgsFilterLineEdit - QLineEdit -
qgsfilterlineedit.h
-
-
- - -
diff --git a/arho_feature_template/gui/new_plan_regulation_group_form.py b/arho_feature_template/gui/new_plan_regulation_group_form.py new file mode 100644 index 0000000..9fe9de5 --- /dev/null +++ b/arho_feature_template/gui/new_plan_regulation_group_form.py @@ -0,0 +1,44 @@ +from __future__ import annotations + +from importlib import resources +from typing import TYPE_CHECKING + +from qgis.core import QgsApplication +from qgis.PyQt import uic +from qgis.PyQt.QtWidgets import QDialog + +from arho_feature_template.gui.new_plan_regulation_widget import NewPlanRegulationWidget + +if TYPE_CHECKING: + from qgis.PyQt.QtWidgets import QBoxLayout, QPushButton, QWidget + +ui_path = resources.files(__package__) / "new_plan_regulation_group_form.ui" +FormClass, _ = uic.loadUiType(ui_path) + + +class NewPlanRegulationGroupForm(QDialog, FormClass): # type: ignore + """Form to create a new plan regulation group.""" + + def __init__(self): + super().__init__() + self.setupUi(self) + + # TYPES + self.add_plan_regulation_btn: QPushButton + self.plan_regulations_scroll_area_contents: QWidget + self.plan_regulations_layout: QBoxLayout + + # INIT + self.add_plan_regulation_btn.clicked.connect(self.add_plan_regulation) + self.add_plan_regulation_btn.setIcon(QgsApplication.getThemeIcon("mActionAdd.svg")) + self.add_plan_regulation() + + def add_plan_regulation(self): + index = self.plan_regulations_layout.count() - 2 + new_plan_regulation_widget = NewPlanRegulationWidget(self.plan_regulations_scroll_area_contents) + new_plan_regulation_widget.delete_signal.connect(self.remove_plan_regulation_group) + self.plan_regulations_layout.insertWidget(index, new_plan_regulation_widget) + + def remove_plan_regulation_group(self, plan_regulation_widget: NewPlanRegulationWidget): + self.plan_regulations_layout.removeWidget(plan_regulation_widget) + plan_regulation_widget.deleteLater() diff --git a/arho_feature_template/gui/new_plan_regulation_group_form.ui b/arho_feature_template/gui/new_plan_regulation_group_form.ui new file mode 100644 index 0000000..35f0457 --- /dev/null +++ b/arho_feature_template/gui/new_plan_regulation_group_form.ui @@ -0,0 +1,188 @@ + + + Dialog + + + + 0 + 0 + 640 + 480 + + + + Luo kaavamääräysryhmä + + + + + + 0 + + + + Kaavamääräysryhmän tiedot + + + + + + true + + + + + 0 + 0 + 598 + 380 + + + + + + + Kaavamääräyksen otsikko + + + + + + + + + + Kirjaintunnus + + + + + + + + + + Ryhmänumero + + + + + + + + + + Värikoodi + + + + + + + + + + + + + + + Kaavamääräykset + + + + + + true + + + + + 0 + 0 + 598 + 380 + + + + + + + + + Lisää kaavamääräys + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Vertical + + + + 20 + 574 + + + + + + + + + + + + + Suositukset + + + + + + true + + + + + 0 + 0 + 598 + 380 + + + + + + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + diff --git a/arho_feature_template/gui/new_plan_regulation_widget.py b/arho_feature_template/gui/new_plan_regulation_widget.py new file mode 100644 index 0000000..4b60e1f --- /dev/null +++ b/arho_feature_template/gui/new_plan_regulation_widget.py @@ -0,0 +1,61 @@ +from __future__ import annotations + +from importlib import resources +from typing import TYPE_CHECKING + +from qgis.core import QgsApplication +from qgis.PyQt import uic +from qgis.PyQt.QtCore import pyqtSignal +from qgis.PyQt.QtWidgets import QMenu, QWidget + +if TYPE_CHECKING: + from qgis.PyQt.QtWidgets import QComboBox, QPushButton + +ui_path = resources.files(__package__) / "new_plan_regulation_widget.ui" +FormClass, _ = uic.loadUiType(ui_path) + + +class NewPlanRegulationWidget(QWidget, FormClass): # type: ignore + """A widget representation of a plan regulation.""" + + delete_signal = pyqtSignal(QWidget) + + def __init__(self, parent=None): + super().__init__(parent) + self.setupUi(self) + + # TYPES + self.plan_regulation_type: QComboBox + + self.add_input_btn: QPushButton + self.add_additional_information_btn: QPushButton + self.add_regulation_number_btn: QPushButton + self.add_file_btn: QPushButton + self.del_btn: QPushButton + + # INIT + self.init_plan_regulation_types() + self.init_buttons() + + def request_delete(self): + self.delete_signal.emit(self) + + def init_buttons(self): + self.del_btn.setIcon(QgsApplication.getThemeIcon("mActionDeleteSelected.svg")) + self.del_btn.clicked.connect(self.request_delete) + + input_menu = QMenu() + input_menu.addAction("Teksti") + input_menu.addAction("Numeerinen") + input_menu.addAction("Koodi") + self.add_input_btn.setMenu(input_menu) + + add_additional_information_menu = QMenu() + add_additional_information_menu.addAction("Teksti") + add_additional_information_menu.addAction("Numeerinen") + add_additional_information_menu.addAction("Koodi") + self.add_additional_information_btn.setMenu(add_additional_information_menu) + + def init_plan_regulation_types(self): + # Get plan regulation type codes from DB + pass diff --git a/arho_feature_template/gui/new_plan_regulation_widget.ui b/arho_feature_template/gui/new_plan_regulation_widget.ui new file mode 100644 index 0000000..0a85d91 --- /dev/null +++ b/arho_feature_template/gui/new_plan_regulation_widget.ui @@ -0,0 +1,173 @@ + + + Form + + + + 0 + 0 + 695 + 108 + + + + Form + + + + + + + + Kaavamääräyslaji + + + + + + + + + + Laji 1 + + + + + Laji 2 + + + + + Laji 3 + + + + + Laji 4 + + + + + + + + + 0 + 0 + + + + + 30 + 16777215 + + + + + + + + + + + + + + + + + Arvo + + + + + + + Lisätieto + + + + + + + Määräysnumero + + + + + + + Liiteasiakirja + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 40 + 20 + + + + + + + + + 0 + 20 + + + + Qt::Horizontal + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 40 + 20 + + + + + + + + + + + diff --git a/arho_feature_template/plugin.py b/arho_feature_template/plugin.py index 7079fd9..ad9488a 100644 --- a/arho_feature_template/plugin.py +++ b/arho_feature_template/plugin.py @@ -9,6 +9,7 @@ from arho_feature_template.core.feature_template_library import FeatureTemplater, TemplateGeometryDigitizeMapTool from arho_feature_template.core.plan_manager import PlanManager +from arho_feature_template.gui.new_plan_regulation_group_form import NewPlanRegulationGroupForm from arho_feature_template.qgis_plugin_tools.tools.custom_logging import setup_logger, teardown_logger from arho_feature_template.qgis_plugin_tools.tools.i18n import setup_translation from arho_feature_template.qgis_plugin_tools.tools.resources import plugin_name @@ -162,6 +163,14 @@ def initGui(self) -> None: # noqa N802 add_to_toolbar=True, ) + self.new_plan_regulation_group = self.add_action( + "", + text="Luo kaavamääräysryhmä", + triggered_callback=self.open_plan_regulation_group_form, + add_to_menu=True, + add_to_toolbar=True, + ) + def on_map_tool_changed(self, new_tool: QgsMapTool, old_tool: QgsMapTool) -> None: # noqa: ARG002 if not isinstance(new_tool, TemplateGeometryDigitizeMapTool): self.template_dock_action.setChecked(False) @@ -186,3 +195,7 @@ def dock_visibility_changed(self, visible: bool) -> None: # noqa: FBT001 def toggle_template_dock(self, show: bool) -> None: # noqa: FBT001 self.templater.template_dock.setUserVisible(show) + + def open_plan_regulation_group_form(self): + self.new_plan_regulation_group_dialog = NewPlanRegulationGroupForm() + self.new_plan_regulation_group_dialog.exec_() From fd14767f32b2ae7f36e00968e39126f72eb07088 Mon Sep 17 00:00:00 2001 From: Niko Aarnio Date: Fri, 8 Nov 2024 13:16:54 +0200 Subject: [PATCH 4/5] continued new plan regulation group form - changed plan regulation type selection from combobox to qtreewidget - create widgets when user presses buttons of a plan regulation --- .../gui/new_plan_regulation_group_form.py | 52 ++++++++--- .../gui/new_plan_regulation_group_form.ui | 60 ++++++------- .../gui/new_plan_regulation_widget.py | 87 +++++++++++++++---- .../gui/new_plan_regulation_widget.ui | 27 +----- 4 files changed, 139 insertions(+), 87 deletions(-) diff --git a/arho_feature_template/gui/new_plan_regulation_group_form.py b/arho_feature_template/gui/new_plan_regulation_group_form.py index 9fe9de5..fb2c223 100644 --- a/arho_feature_template/gui/new_plan_regulation_group_form.py +++ b/arho_feature_template/gui/new_plan_regulation_group_form.py @@ -3,14 +3,13 @@ from importlib import resources from typing import TYPE_CHECKING -from qgis.core import QgsApplication from qgis.PyQt import uic -from qgis.PyQt.QtWidgets import QDialog +from qgis.PyQt.QtWidgets import QDialog, QTreeWidget, QTreeWidgetItem from arho_feature_template.gui.new_plan_regulation_widget import NewPlanRegulationWidget if TYPE_CHECKING: - from qgis.PyQt.QtWidgets import QBoxLayout, QPushButton, QWidget + from qgis.PyQt.QtWidgets import QBoxLayout, QWidget ui_path = resources.files(__package__) / "new_plan_regulation_group_form.ui" FormClass, _ = uic.loadUiType(ui_path) @@ -24,21 +23,48 @@ def __init__(self): self.setupUi(self) # TYPES - self.add_plan_regulation_btn: QPushButton + self.plan_regulations_view: QTreeWidget self.plan_regulations_scroll_area_contents: QWidget self.plan_regulations_layout: QBoxLayout # INIT - self.add_plan_regulation_btn.clicked.connect(self.add_plan_regulation) - self.add_plan_regulation_btn.setIcon(QgsApplication.getThemeIcon("mActionAdd.svg")) - self.add_plan_regulation() - - def add_plan_regulation(self): - index = self.plan_regulations_layout.count() - 2 - new_plan_regulation_widget = NewPlanRegulationWidget(self.plan_regulations_scroll_area_contents) - new_plan_regulation_widget.delete_signal.connect(self.remove_plan_regulation_group) + self.initialize_plan_regulations() + self.plan_regulations_view.itemDoubleClicked.connect(self.add_selected_plan_regulation) + + def initialize_plan_regulations(self): + # NOTE: Replace the dummy plan regulation codes below with codes from DB + plan_regulation_codes = { + "category 1": ["regulation 1", "regulation 2"], + "category 2": ["regulation 3"], + "category 3": ["regulation 4", "regulation 5", "regulation 6"], + } + + # Initialize categories + for category_name, plan_regulations in plan_regulation_codes.items(): + category_item = QTreeWidgetItem() + category_item.setText(0, category_name) + self.plan_regulations_view.addTopLevelItem(category_item) + + # Initialize plan regulations under the categories + for plan_regulation_type in plan_regulations: + plan_regulation_item = QTreeWidgetItem(category_item) + plan_regulation_item.setText(0, plan_regulation_type) + self.plan_regulations_view.addTopLevelItem(plan_regulation_item) + + def add_selected_plan_regulation(self, item: QTreeWidgetItem, column: int): + # If user double clicked category, don't add plan regulation + if not item.parent(): + return + self.add_plan_regulation(item.text(column)) + + def add_plan_regulation(self, regulation_type: str): + new_plan_regulation_widget = NewPlanRegulationWidget( + regulation_type=regulation_type, parent=self.plan_regulations_scroll_area_contents + ) + new_plan_regulation_widget.delete_signal.connect(self.delete_plan_regulation) + index = self.plan_regulations_layout.count() - 1 self.plan_regulations_layout.insertWidget(index, new_plan_regulation_widget) - def remove_plan_regulation_group(self, plan_regulation_widget: NewPlanRegulationWidget): + def delete_plan_regulation(self, plan_regulation_widget: NewPlanRegulationWidget): self.plan_regulations_layout.removeWidget(plan_regulation_widget) plan_regulation_widget.deleteLater() diff --git a/arho_feature_template/gui/new_plan_regulation_group_form.ui b/arho_feature_template/gui/new_plan_regulation_group_form.ui index 35f0457..bfa6657 100644 --- a/arho_feature_template/gui/new_plan_regulation_group_form.ui +++ b/arho_feature_template/gui/new_plan_regulation_group_form.ui @@ -6,8 +6,8 @@ 0 0 - 640 - 480 + 769 + 535 @@ -34,8 +34,8 @@ 0 0 - 598 - 380 + 727 + 435 @@ -89,7 +89,25 @@ Kaavamääräykset - + + + + + + 0 + 0 + + + + false + + + + 1 + + + + @@ -100,35 +118,11 @@ 0 0 - 598 - 380 + 465 + 435 - - - - - - Lisää kaavamääräys - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - @@ -163,8 +157,8 @@ 0 0 - 598 - 380 + 727 + 435 diff --git a/arho_feature_template/gui/new_plan_regulation_widget.py b/arho_feature_template/gui/new_plan_regulation_widget.py index 4b60e1f..18955ae 100644 --- a/arho_feature_template/gui/new_plan_regulation_widget.py +++ b/arho_feature_template/gui/new_plan_regulation_widget.py @@ -1,31 +1,47 @@ from __future__ import annotations +from enum import Enum from importlib import resources from typing import TYPE_CHECKING from qgis.core import QgsApplication +from qgis.gui import QgsDoubleSpinBox, QgsFileWidget, QgsSpinBox from qgis.PyQt import uic from qgis.PyQt.QtCore import pyqtSignal -from qgis.PyQt.QtWidgets import QMenu, QWidget +from qgis.PyQt.QtWidgets import QComboBox, QFormLayout, QMenu, QTextEdit, QWidget if TYPE_CHECKING: - from qgis.PyQt.QtWidgets import QComboBox, QPushButton + from qgis.PyQt.QtWidgets import QLineEdit, QPushButton ui_path = resources.files(__package__) / "new_plan_regulation_widget.ui" FormClass, _ = uic.loadUiType(ui_path) +class InputTypes(Enum): + TEXT_VALUE = 1 + NUMERIC_VALUE = 2 + CODE_VALUE = 3 + + TEXT_INFO = 4 + NUMERIC_INFO = 5 + CODE_INFO = 6 + + REGULATION_NUMBER = 7 + RELATED_FILE = 8 + + class NewPlanRegulationWidget(QWidget, FormClass): # type: ignore """A widget representation of a plan regulation.""" delete_signal = pyqtSignal(QWidget) - def __init__(self, parent=None): + def __init__(self, regulation_type: str, parent=None): super().__init__(parent) self.setupUi(self) # TYPES - self.plan_regulation_type: QComboBox + self.plan_regulation_type: QLineEdit + self.form_layout: QFormLayout self.add_input_btn: QPushButton self.add_additional_information_btn: QPushButton @@ -34,7 +50,8 @@ def __init__(self, parent=None): self.del_btn: QPushButton # INIT - self.init_plan_regulation_types() + self.widgets: dict[InputTypes, list[QWidget]] = {} + self.plan_regulation_type.setText(regulation_type) self.init_buttons() def request_delete(self): @@ -45,17 +62,53 @@ def init_buttons(self): self.del_btn.clicked.connect(self.request_delete) input_menu = QMenu() - input_menu.addAction("Teksti") - input_menu.addAction("Numeerinen") - input_menu.addAction("Koodi") + input_menu.addAction("Teksti").triggered.connect(lambda: self.add_input_field(InputTypes.TEXT_VALUE)) + input_menu.addAction("Numeerinen").triggered.connect(lambda: self.add_input_field(InputTypes.NUMERIC_VALUE)) + input_menu.addAction("Koodi").triggered.connect(lambda: self.add_input_field(InputTypes.CODE_VALUE)) self.add_input_btn.setMenu(input_menu) - add_additional_information_menu = QMenu() - add_additional_information_menu.addAction("Teksti") - add_additional_information_menu.addAction("Numeerinen") - add_additional_information_menu.addAction("Koodi") - self.add_additional_information_btn.setMenu(add_additional_information_menu) - - def init_plan_regulation_types(self): - # Get plan regulation type codes from DB - pass + additional_info_menu = QMenu() + additional_info_menu.addAction("Teksti").triggered.connect(lambda: self.add_input_field(InputTypes.TEXT_INFO)) + additional_info_menu.addAction("Numeerinen").triggered.connect( + lambda: self.add_input_field(InputTypes.NUMERIC_INFO) + ) + additional_info_menu.addAction("Koodi").triggered.connect(lambda: self.add_input_field(InputTypes.CODE_INFO)) + self.add_additional_information_btn.setMenu(additional_info_menu) + + self.add_regulation_number_btn.clicked.connect(lambda: self.add_input_field(InputTypes.REGULATION_NUMBER)) + self.add_file_btn.clicked.connect(lambda: self.add_input_field(InputTypes.RELATED_FILE)) + + def add_input_field(self, input_field_type: InputTypes): + if input_field_type == InputTypes.TEXT_VALUE: + widget = QTextEdit() + self.form_layout.addRow("Tekstiarvo", widget) + elif input_field_type == InputTypes.NUMERIC_VALUE: + widget = QgsDoubleSpinBox() # Or QgsSpinBox? + self.form_layout.addRow("Numeerinen arvo", widget) + elif input_field_type == InputTypes.CODE_VALUE: + widget = QComboBox() + # TODO: widget.addItems() + self.form_layout.addRow("Koodiarvo", widget) + + elif input_field_type == InputTypes.TEXT_INFO: + widget = QTextEdit() + self.form_layout.addRow("Lisätieto", widget) + elif input_field_type == InputTypes.NUMERIC_INFO: + widget = QgsDoubleSpinBox() + self.form_layout.addRow("Lisätieto", widget) + elif input_field_type == InputTypes.CODE_INFO: + widget = QComboBox() + # TODO: widget.addItems() + self.form_layout.addRow("Lisätieto", widget) + + elif input_field_type == InputTypes.REGULATION_NUMBER: + widget = QgsSpinBox() + self.form_layout.addRow("Määräysnumero", widget) + elif input_field_type == InputTypes.RELATED_FILE: + widget = QgsFileWidget() + self.form_layout.addRow("Liiteasiakirja", widget) + + if self.widgets.get(input_field_type) is None: + self.widgets[input_field_type] = [widget] + else: + self.widgets[input_field_type].append(widget) diff --git a/arho_feature_template/gui/new_plan_regulation_widget.ui b/arho_feature_template/gui/new_plan_regulation_widget.ui index 0a85d91..95b91b2 100644 --- a/arho_feature_template/gui/new_plan_regulation_widget.ui +++ b/arho_feature_template/gui/new_plan_regulation_widget.ui @@ -6,7 +6,7 @@ 0 0 - 695 + 694 108 @@ -15,7 +15,7 @@ - + @@ -26,28 +26,7 @@ - - - - Laji 1 - - - - - Laji 2 - - - - - Laji 3 - - - - - Laji 4 - - - + From 88d48403fb55fa028db63d9c7a5fdcf2903c5a30 Mon Sep 17 00:00:00 2001 From: Niko Aarnio Date: Mon, 18 Nov 2024 11:02:59 +0200 Subject: [PATCH 5/5] add text inputs for numeric inputs (unit) and code input (value), connect dialog close/reject signal --- .../gui/new_plan_regulation_group_form.ui | 27 ++++++++-- .../gui/new_plan_regulation_widget.py | 54 +++++++++++-------- 2 files changed, 54 insertions(+), 27 deletions(-) diff --git a/arho_feature_template/gui/new_plan_regulation_group_form.ui b/arho_feature_template/gui/new_plan_regulation_group_form.ui index bfa6657..7fff8e6 100644 --- a/arho_feature_template/gui/new_plan_regulation_group_form.ui +++ b/arho_feature_template/gui/new_plan_regulation_group_form.ui @@ -118,8 +118,8 @@ 0 0 - 465 - 435 + 98 + 28 @@ -157,8 +157,8 @@ 0 0 - 727 - 435 + 98 + 28 @@ -178,5 +178,22 @@ - + + + button_box + rejected() + Dialog + reject() + + + 384 + 513 + + + 384 + 267 + + + + diff --git a/arho_feature_template/gui/new_plan_regulation_widget.py b/arho_feature_template/gui/new_plan_regulation_widget.py index 18955ae..74a8df8 100644 --- a/arho_feature_template/gui/new_plan_regulation_widget.py +++ b/arho_feature_template/gui/new_plan_regulation_widget.py @@ -8,10 +8,10 @@ from qgis.gui import QgsDoubleSpinBox, QgsFileWidget, QgsSpinBox from qgis.PyQt import uic from qgis.PyQt.QtCore import pyqtSignal -from qgis.PyQt.QtWidgets import QComboBox, QFormLayout, QMenu, QTextEdit, QWidget +from qgis.PyQt.QtWidgets import QComboBox, QFormLayout, QHBoxLayout, QLineEdit, QMenu, QSizePolicy, QTextEdit, QWidget if TYPE_CHECKING: - from qgis.PyQt.QtWidgets import QLineEdit, QPushButton + from qgis.PyQt.QtWidgets import QPushButton ui_path = resources.files(__package__) / "new_plan_regulation_widget.ui" FormClass, _ = uic.loadUiType(ui_path) @@ -80,35 +80,45 @@ def init_buttons(self): def add_input_field(self, input_field_type: InputTypes): if input_field_type == InputTypes.TEXT_VALUE: - widget = QTextEdit() - self.form_layout.addRow("Tekstiarvo", widget) + inputs = QTextEdit() + self.form_layout.addRow("Tekstiarvo", inputs) elif input_field_type == InputTypes.NUMERIC_VALUE: - widget = QgsDoubleSpinBox() # Or QgsSpinBox? - self.form_layout.addRow("Numeerinen arvo", widget) + value_widget = QgsDoubleSpinBox() # Or QgsSpinBox? + value_widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) + unit_widget = QLineEdit() + inputs = QHBoxLayout() + inputs.addWidget(value_widget) + inputs.addWidget(unit_widget) + self.form_layout.addRow("Numeerinen arvo", inputs) elif input_field_type == InputTypes.CODE_VALUE: - widget = QComboBox() - # TODO: widget.addItems() - self.form_layout.addRow("Koodiarvo", widget) + code_widget = QComboBox() + code_widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) + value_widget = QLineEdit() + inputs = QHBoxLayout() + inputs.addWidget(code_widget) + inputs.addWidget(value_widget) + # TODO: inputs.addItems() + self.form_layout.addRow("Koodiarvo", inputs) elif input_field_type == InputTypes.TEXT_INFO: - widget = QTextEdit() - self.form_layout.addRow("Lisätieto", widget) + inputs = QTextEdit() + self.form_layout.addRow("Lisätieto", inputs) elif input_field_type == InputTypes.NUMERIC_INFO: - widget = QgsDoubleSpinBox() - self.form_layout.addRow("Lisätieto", widget) + inputs = QgsDoubleSpinBox() + self.form_layout.addRow("Lisätieto", inputs) elif input_field_type == InputTypes.CODE_INFO: - widget = QComboBox() - # TODO: widget.addItems() - self.form_layout.addRow("Lisätieto", widget) + inputs = QComboBox() + # TODO: inputs.addItems() + self.form_layout.addRow("Lisätieto", inputs) elif input_field_type == InputTypes.REGULATION_NUMBER: - widget = QgsSpinBox() - self.form_layout.addRow("Määräysnumero", widget) + inputs = QgsSpinBox() + self.form_layout.addRow("Määräysnumero", inputs) elif input_field_type == InputTypes.RELATED_FILE: - widget = QgsFileWidget() - self.form_layout.addRow("Liiteasiakirja", widget) + inputs = QgsFileWidget() + self.form_layout.addRow("Liiteasiakirja", inputs) if self.widgets.get(input_field_type) is None: - self.widgets[input_field_type] = [widget] + self.widgets[input_field_type] = [inputs] else: - self.widgets[input_field_type].append(widget) + self.widgets[input_field_type].append(inputs)