-
Notifications
You must be signed in to change notification settings - Fork 0
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
[Hahmotelma] Lisää käyttöliittymä kaavamääräysryhmien luomiselle #51
The head ref may contain hidden characters: "50-lis\u00E4\u00E4-templaateista-irrallinen-k\u00E4ytt\u00F6liittym\u00E4-kaavam\u00E4\u00E4r\u00E4yksien-lis\u00E4\u00E4miselle"
Changes from 4 commits
b2665ec
d57e641
68ccb06
fd14767
88d4840
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
from __future__ import annotations | ||
|
||
from importlib import resources | ||
from typing import TYPE_CHECKING | ||
|
||
from qgis.PyQt import uic | ||
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, 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.plan_regulations_view: QTreeWidget | ||
self.plan_regulations_scroll_area_contents: QWidget | ||
self.plan_regulations_layout: QBoxLayout | ||
|
||
# INIT | ||
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 delete_plan_regulation(self, plan_regulation_widget: NewPlanRegulationWidget): | ||
self.plan_regulations_layout.removeWidget(plan_regulation_widget) | ||
plan_regulation_widget.deleteLater() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>Dialog</class> | ||
<widget class="QDialog" name="Dialog"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>769</width> | ||
<height>535</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>Luo kaavamääräysryhmä</string> | ||
</property> | ||
<layout class="QVBoxLayout" name="verticalLayout_2"> | ||
<item> | ||
<widget class="QTabWidget" name="tabs"> | ||
<property name="currentIndex"> | ||
<number>0</number> | ||
</property> | ||
<widget class="QWidget" name="plan_regulation_group_info_tab"> | ||
<attribute name="title"> | ||
<string>Kaavamääräysryhmän tiedot</string> | ||
</attribute> | ||
<layout class="QVBoxLayout" name="verticalLayout_3"> | ||
<item> | ||
<widget class="QScrollArea" name="scrollArea"> | ||
<property name="widgetResizable"> | ||
<bool>true</bool> | ||
</property> | ||
<widget class="QWidget" name="scrollAreaWidgetContents"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>727</width> | ||
<height>435</height> | ||
</rect> | ||
</property> | ||
<layout class="QFormLayout" name="formLayout"> | ||
<item row="0" column="0"> | ||
<widget class="QLabel" name="label_2"> | ||
<property name="text"> | ||
<string>Kaavamääräyksen otsikko</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="0" column="1"> | ||
<widget class="QLineEdit" name="heading"/> | ||
</item> | ||
<item row="1" column="0"> | ||
<widget class="QLabel" name="label_3"> | ||
<property name="text"> | ||
<string>Kirjaintunnus</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="1" column="1"> | ||
<widget class="QLineEdit" name="code"/> | ||
</item> | ||
<item row="2" column="0"> | ||
<widget class="QLabel" name="label"> | ||
<property name="text"> | ||
<string>Ryhmänumero</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="2" column="1"> | ||
<widget class="QLineEdit" name="group_number"/> | ||
</item> | ||
<item row="3" column="0"> | ||
<widget class="QLabel" name="label_5"> | ||
<property name="text"> | ||
<string>Värikoodi</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="3" column="1"> | ||
<widget class="QLineEdit" name="color_code"/> | ||
</item> | ||
</layout> | ||
</widget> | ||
</widget> | ||
</item> | ||
</layout> | ||
</widget> | ||
<widget class="QWidget" name="plan_regulations_tab"> | ||
<attribute name="title"> | ||
<string>Kaavamääräykset</string> | ||
</attribute> | ||
<layout class="QHBoxLayout" name="horizontalLayout"> | ||
<item> | ||
<widget class="QTreeWidget" name="plan_regulations_view"> | ||
<property name="sizePolicy"> | ||
<sizepolicy hsizetype="Maximum" vsizetype="Expanding"> | ||
<horstretch>0</horstretch> | ||
<verstretch>0</verstretch> | ||
</sizepolicy> | ||
</property> | ||
<attribute name="headerVisible"> | ||
<bool>false</bool> | ||
</attribute> | ||
<column> | ||
<property name="text"> | ||
<string notr="true">1</string> | ||
</property> | ||
</column> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="QScrollArea" name="plan_regulations_scroll_area"> | ||
<property name="widgetResizable"> | ||
<bool>true</bool> | ||
</property> | ||
<widget class="QWidget" name="plan_regulations_scroll_area_contents"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>465</width> | ||
<height>435</height> | ||
</rect> | ||
</property> | ||
<layout class="QVBoxLayout" name="plan_regulations_layout"> | ||
<item> | ||
<spacer name="verticalSpacer"> | ||
<property name="orientation"> | ||
<enum>Qt::Vertical</enum> | ||
</property> | ||
<property name="sizeHint" stdset="0"> | ||
<size> | ||
<width>20</width> | ||
<height>574</height> | ||
</size> | ||
</property> | ||
</spacer> | ||
</item> | ||
</layout> | ||
</widget> | ||
</widget> | ||
</item> | ||
</layout> | ||
</widget> | ||
<widget class="QWidget" name="recommendations_tab"> | ||
<attribute name="title"> | ||
<string>Suositukset</string> | ||
</attribute> | ||
<layout class="QVBoxLayout" name="verticalLayout_4"> | ||
<item> | ||
<widget class="QScrollArea" name="scrollArea_2"> | ||
<property name="widgetResizable"> | ||
<bool>true</bool> | ||
</property> | ||
<widget class="QWidget" name="scrollAreaWidgetContents_2"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>727</width> | ||
<height>435</height> | ||
</rect> | ||
</property> | ||
</widget> | ||
</widget> | ||
</item> | ||
</layout> | ||
</widget> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="QDialogButtonBox" name="button_box"> | ||
<property name="standardButtons"> | ||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</widget> | ||
<resources/> | ||
<connections/> | ||
</ui> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
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 QComboBox, QFormLayout, QMenu, QTextEdit, QWidget | ||
|
||
if TYPE_CHECKING: | ||
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, regulation_type: str, parent=None): | ||
super().__init__(parent) | ||
self.setupUi(self) | ||
|
||
# TYPES | ||
self.plan_regulation_type: QLineEdit | ||
self.form_layout: QFormLayout | ||
|
||
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.widgets: dict[InputTypes, list[QWidget]] = {} | ||
self.plan_regulation_type.setText(regulation_type) | ||
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").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) | ||
|
||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Olisi kiva, jos oikean muotoinen arvo-kenttä tulisi automaattisesti näkyviin valitun määräyslajin perusteella. Uskoisin, että yhdelle määräyslajille arvot ovat aina samanmuotoisia. |
||
elif input_field_type == InputTypes.NUMERIC_VALUE: | ||
widget = QgsDoubleSpinBox() # Or QgsSpinBox? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Numeromuotoiselle kentälle pitäisi syöttää myös tekstimuotoinen yksikkö. |
||
self.form_layout.addRow("Numeerinen arvo", widget) | ||
elif input_field_type == InputTypes.CODE_VALUE: | ||
widget = QComboBox() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. koodistotunnuksen lisäksi pitäisi kyetä syöttämään itse arvo ja näille jokin otsikko. |
||
# TODO: widget.addItems() | ||
self.form_layout.addRow("Koodiarvo", widget) | ||
|
||
elif input_field_type == InputTypes.TEXT_INFO: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tietomallin mukaan lisätiedolla on aina "lisätiedon laji"-koodi, ja tämän lisäksi mahdollisesti jokin arvo. Maakuntakaavaprojektin tietokannassa nämä on rakennettu tällä hetkellä vähän eri tavalla. Siinä kaavamääräyksellä on esim merkittävyys kenttä, johon valitaan lisätiedon laji-koodistosta jokin merkittävyyshierarkian koodi. Näin voisi periaatteessa tehdä sillä oletuksella, että samalla kaavakohteella ei tule montaa saman tyypin lisätietoa. Näitä listätietojuttuja voitaisiin miettiä koko porukalla ja päättää miten me tämä toteutetaan. |
||
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jos kyseessä tekstiarvo, niin tietomallin mukaan pitäisi syöttää myös tekstin "syntaksi" (en oo kyllä ihan varma mitä se meinaa).