1
1
from __future__ import annotations
2
2
3
+ from enum import Enum
3
4
from importlib import resources
4
5
from typing import TYPE_CHECKING
5
6
6
7
from qgis .core import QgsApplication
8
+ from qgis .gui import QgsDoubleSpinBox , QgsFileWidget , QgsSpinBox
7
9
from qgis .PyQt import uic
8
10
from qgis .PyQt .QtCore import pyqtSignal
9
- from qgis .PyQt .QtWidgets import QMenu , QWidget
11
+ from qgis .PyQt .QtWidgets import QComboBox , QFormLayout , QMenu , QTextEdit , QWidget
10
12
11
13
if TYPE_CHECKING :
12
- from qgis .PyQt .QtWidgets import QComboBox , QPushButton
14
+ from qgis .PyQt .QtWidgets import QLineEdit , QPushButton
13
15
14
16
ui_path = resources .files (__package__ ) / "new_plan_regulation_widget.ui"
15
17
FormClass , _ = uic .loadUiType (ui_path )
16
18
17
19
20
+ class InputTypes (Enum ):
21
+ TEXT_VALUE = 1
22
+ NUMERIC_VALUE = 2
23
+ CODE_VALUE = 3
24
+
25
+ TEXT_INFO = 4
26
+ NUMERIC_INFO = 5
27
+ CODE_INFO = 6
28
+
29
+ REGULATION_NUMBER = 7
30
+ RELATED_FILE = 8
31
+
32
+
18
33
class NewPlanRegulationWidget (QWidget , FormClass ): # type: ignore
19
34
"""A widget representation of a plan regulation."""
20
35
21
36
delete_signal = pyqtSignal (QWidget )
22
37
23
- def __init__ (self , parent = None ):
38
+ def __init__ (self , regulation_type : str , parent = None ):
24
39
super ().__init__ (parent )
25
40
self .setupUi (self )
26
41
27
42
# TYPES
28
- self .plan_regulation_type : QComboBox
43
+ self .plan_regulation_type : QLineEdit
44
+ self .form_layout : QFormLayout
29
45
30
46
self .add_input_btn : QPushButton
31
47
self .add_additional_information_btn : QPushButton
@@ -34,7 +50,8 @@ def __init__(self, parent=None):
34
50
self .del_btn : QPushButton
35
51
36
52
# INIT
37
- self .init_plan_regulation_types ()
53
+ self .widgets : dict [InputTypes , list [QWidget ]] = {}
54
+ self .plan_regulation_type .setText (regulation_type )
38
55
self .init_buttons ()
39
56
40
57
def request_delete (self ):
@@ -45,17 +62,53 @@ def init_buttons(self):
45
62
self .del_btn .clicked .connect (self .request_delete )
46
63
47
64
input_menu = QMenu ()
48
- input_menu .addAction ("Teksti" )
49
- input_menu .addAction ("Numeerinen" )
50
- input_menu .addAction ("Koodi" )
65
+ input_menu .addAction ("Teksti" ). triggered . connect ( lambda : self . add_input_field ( InputTypes . TEXT_VALUE ))
66
+ input_menu .addAction ("Numeerinen" ). triggered . connect ( lambda : self . add_input_field ( InputTypes . NUMERIC_VALUE ))
67
+ input_menu .addAction ("Koodi" ). triggered . connect ( lambda : self . add_input_field ( InputTypes . CODE_VALUE ))
51
68
self .add_input_btn .setMenu (input_menu )
52
69
53
- add_additional_information_menu = QMenu ()
54
- add_additional_information_menu .addAction ("Teksti" )
55
- add_additional_information_menu .addAction ("Numeerinen" )
56
- add_additional_information_menu .addAction ("Koodi" )
57
- self .add_additional_information_btn .setMenu (add_additional_information_menu )
58
-
59
- def init_plan_regulation_types (self ):
60
- # Get plan regulation type codes from DB
61
- pass
70
+ additional_info_menu = QMenu ()
71
+ additional_info_menu .addAction ("Teksti" ).triggered .connect (lambda : self .add_input_field (InputTypes .TEXT_INFO ))
72
+ additional_info_menu .addAction ("Numeerinen" ).triggered .connect (
73
+ lambda : self .add_input_field (InputTypes .NUMERIC_INFO )
74
+ )
75
+ additional_info_menu .addAction ("Koodi" ).triggered .connect (lambda : self .add_input_field (InputTypes .CODE_INFO ))
76
+ self .add_additional_information_btn .setMenu (additional_info_menu )
77
+
78
+ self .add_regulation_number_btn .clicked .connect (lambda : self .add_input_field (InputTypes .REGULATION_NUMBER ))
79
+ self .add_file_btn .clicked .connect (lambda : self .add_input_field (InputTypes .RELATED_FILE ))
80
+
81
+ def add_input_field (self , input_field_type : InputTypes ):
82
+ if input_field_type == InputTypes .TEXT_VALUE :
83
+ widget = QTextEdit ()
84
+ self .form_layout .addRow ("Tekstiarvo" , widget )
85
+ elif input_field_type == InputTypes .NUMERIC_VALUE :
86
+ widget = QgsDoubleSpinBox () # Or QgsSpinBox?
87
+ self .form_layout .addRow ("Numeerinen arvo" , widget )
88
+ elif input_field_type == InputTypes .CODE_VALUE :
89
+ widget = QComboBox ()
90
+ # TODO: widget.addItems()
91
+ self .form_layout .addRow ("Koodiarvo" , widget )
92
+
93
+ elif input_field_type == InputTypes .TEXT_INFO :
94
+ widget = QTextEdit ()
95
+ self .form_layout .addRow ("Lisätieto" , widget )
96
+ elif input_field_type == InputTypes .NUMERIC_INFO :
97
+ widget = QgsDoubleSpinBox ()
98
+ self .form_layout .addRow ("Lisätieto" , widget )
99
+ elif input_field_type == InputTypes .CODE_INFO :
100
+ widget = QComboBox ()
101
+ # TODO: widget.addItems()
102
+ self .form_layout .addRow ("Lisätieto" , widget )
103
+
104
+ elif input_field_type == InputTypes .REGULATION_NUMBER :
105
+ widget = QgsSpinBox ()
106
+ self .form_layout .addRow ("Määräysnumero" , widget )
107
+ elif input_field_type == InputTypes .RELATED_FILE :
108
+ widget = QgsFileWidget ()
109
+ self .form_layout .addRow ("Liiteasiakirja" , widget )
110
+
111
+ if self .widgets .get (input_field_type ) is None :
112
+ self .widgets [input_field_type ] = [widget ]
113
+ else :
114
+ self .widgets [input_field_type ].append (widget )
0 commit comments