-
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
Merged
LKajan
merged 5 commits into
main
from
50-lisää-templaateista-irrallinen-käyttöliittymä-kaavamääräyksien-lisäämiselle
Nov 18, 2024
The head ref may contain hidden characters: "50-lis\u00E4\u00E4-templaateista-irrallinen-k\u00E4ytt\u00F6liittym\u00E4-kaavam\u00E4\u00E4r\u00E4yksien-lis\u00E4\u00E4miselle"
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b2665ec
feat: add alternative, not templated based UI for adding plan regulat…
nmaarnio d57e641
add fields to plan regulation group form
nmaarnio 68ccb06
add new draft version of plan regulation creation form
nmaarnio fd14767
continued new plan regulation group form
nmaarnio 88d4840
add text inputs for numeric inputs (unit) and code input (value), con…
nmaarnio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
arho_feature_template/gui/new_plan_regulation_group_form.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
199 changes: 199 additions & 0 deletions
199
arho_feature_template/gui/new_plan_regulation_group_form.ui
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
<?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>98</width> | ||
<height>28</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>98</width> | ||
<height>28</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> | ||
<connection> | ||
<sender>button_box</sender> | ||
<signal>rejected()</signal> | ||
<receiver>Dialog</receiver> | ||
<slot>reject()</slot> | ||
<hints> | ||
<hint type="sourcelabel"> | ||
<x>384</x> | ||
<y>513</y> | ||
</hint> | ||
<hint type="destinationlabel"> | ||
<x>384</x> | ||
<y>267</y> | ||
</hint> | ||
</hints> | ||
</connection> | ||
</connections> | ||
</ui> |
124 changes: 124 additions & 0 deletions
124
arho_feature_template/gui/new_plan_regulation_widget.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
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, QHBoxLayout, QLineEdit, QMenu, QSizePolicy, QTextEdit, QWidget | ||
|
||
if TYPE_CHECKING: | ||
from qgis.PyQt.QtWidgets import 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: | ||
inputs = QTextEdit() | ||
self.form_layout.addRow("Tekstiarvo", inputs) | ||
elif input_field_type == InputTypes.NUMERIC_VALUE: | ||
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: | ||
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: | ||
inputs = QTextEdit() | ||
self.form_layout.addRow("Lisätieto", inputs) | ||
elif input_field_type == InputTypes.NUMERIC_INFO: | ||
inputs = QgsDoubleSpinBox() | ||
self.form_layout.addRow("Lisätieto", inputs) | ||
elif input_field_type == InputTypes.CODE_INFO: | ||
inputs = QComboBox() | ||
# TODO: inputs.addItems() | ||
self.form_layout.addRow("Lisätieto", inputs) | ||
|
||
elif input_field_type == InputTypes.REGULATION_NUMBER: | ||
inputs = QgsSpinBox() | ||
self.form_layout.addRow("Määräysnumero", inputs) | ||
elif input_field_type == InputTypes.RELATED_FILE: | ||
inputs = QgsFileWidget() | ||
self.form_layout.addRow("Liiteasiakirja", inputs) | ||
|
||
if self.widgets.get(input_field_type) is None: | ||
self.widgets[input_field_type] = [inputs] | ||
else: | ||
self.widgets[input_field_type].append(inputs) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.