1
1
from __future__ import annotations
2
2
3
- from collections import defaultdict
4
3
from importlib import resources
5
4
from typing import TYPE_CHECKING , cast
6
5
16
15
QMenu ,
17
16
QSizePolicy ,
18
17
QTextEdit ,
18
+ QToolButton ,
19
19
QWidget ,
20
20
)
21
21
22
22
from arho_feature_template .core .plan_regulation_config import PlanRegulationConfig , Unit , ValueType
23
23
from arho_feature_template .utils .misc_utils import get_additional_information_name
24
24
25
25
if TYPE_CHECKING :
26
- from numbers import Number
27
-
28
26
from qgis .PyQt .QtWidgets import QPushButton
29
27
30
28
from arho_feature_template .core .plan_regulation_group_config import PlanRegulationDefinition
@@ -56,21 +54,23 @@ def __init__(self, config: PlanRegulationConfig, parent=None):
56
54
self .setupUi (self )
57
55
58
56
# TYPES
57
+ # self.spacer_layout: QBoxLayout
59
58
self .plan_regulation_name : QLineEdit
60
59
self .form_layout : QFormLayout
61
60
62
61
self .add_additional_information_btn : QPushButton
63
- self .add_regulation_number_btn : QPushButton
64
- self .add_file_btn : QPushButton
62
+ self .add_field_btn : QPushButton
65
63
self .del_btn : QPushButton
64
+ self .expand_hide_btn : QToolButton
65
+
66
+ self .code_label : QLabel
67
+ self .code : QLineEdit
66
68
67
69
# INIT
68
70
self .config = config
69
71
self .regulation_number_added = False
70
- # Key is related field name, value is 1) widget, 2) tuple of widget and default value
71
- # NOTE: Maybe this is not something needed? Instead, when user clicks Ok, write into a YAML
72
- # in a separate script?
73
- self .attribute_widgets : dict [str , QWidget | tuple [QWidget , str | Number ]] = defaultdict (dict )
72
+ self .expanded = True
73
+ self .widgets : list [tuple ] = []
74
74
self .plan_regulation_name .setText (config .name )
75
75
self .plan_regulation_name .setReadOnly (True )
76
76
self .init_value_fields ()
@@ -157,31 +157,58 @@ def init_buttons(self):
157
157
type_main_menu .addMenu (type_menu )
158
158
type_main_menu .addMenu (signifigance_menu )
159
159
self .add_additional_information_btn .setMenu (type_main_menu )
160
-
161
- # REGULATION NUMBER
162
- self .add_regulation_number_btn .clicked .connect (self .add_regulation_number )
163
-
164
- # ADD FILE
165
- self .add_file_btn .clicked .connect (self .add_file )
160
+ self .add_additional_information_btn .setIcon (QgsApplication .getThemeIcon ("mActionPropertiesWidget.svg" ))
161
+
162
+ # OTHER INFO / ADD FIELD
163
+ add_field_menu = QMenu (self )
164
+ add_field_menu .addAction ("Määräysnumero" ).triggered .connect (self .add_regulation_number )
165
+ add_field_menu .addAction ("Liiteasiakirja" ).triggered .connect (self .add_file )
166
+ self .add_field_btn .setMenu (add_field_menu )
167
+ self .add_field_btn .setIcon (QgsApplication .getThemeIcon ("mActionAdd.svg" ))
168
+
169
+ # EXPAND BTN
170
+ self .expand_hide_btn .clicked .connect (self ._on_expand_hide_btn_clicked )
171
+
172
+ def _on_expand_hide_btn_clicked (self ):
173
+ if self .expanded :
174
+ for label , widget in self .widgets :
175
+ self .form_layout .removeWidget (label )
176
+ label .hide ()
177
+ self .form_layout .removeWidget (widget )
178
+ widget .hide ()
179
+ self .expand_hide_btn .setArrowType (Qt .ArrowType .DownArrow )
180
+ self .expanded = False
181
+ else :
182
+ for label , widget in self .widgets :
183
+ label .show ()
184
+ widget .show ()
185
+ self .form_layout .addRow (label , widget )
186
+ self .expand_hide_btn .setArrowType (Qt .ArrowType .UpArrow )
187
+ self .expanded = True
166
188
167
189
def add_decimal_input (self , layout : QHBoxLayout , value_type : ValueType ):
168
190
value_widget = QgsDoubleSpinBox ()
169
- label_text = "Desimaali"
191
+ label = QLabel ( "Arvo" )
170
192
if value_type == ValueType .POSITIVE_DECIMAL :
171
193
value_widget .setMinimum (0.0 )
172
- label_text += " (positiivinen)"
194
+ label . setToolTip ( "Tyyppi: desimaali (positiivinen)")
173
195
else :
174
196
value_widget .setMinimum (- 9999.9 )
197
+ label .setToolTip ("Tyyppi: desimaali" )
175
198
value_widget .setSizePolicy (QSizePolicy .Expanding , QSizePolicy .Fixed )
176
199
layout .addWidget (value_widget )
177
- self .form_layout .addRow (label_text , layout )
200
+ self .form_layout .addRow (label , layout )
201
+ self .widgets .append ((label , value_widget ))
178
202
179
203
def add_positive_integer_input (self , layout : QHBoxLayout ):
180
204
value_widget = QgsSpinBox ()
181
205
value_widget .setMinimum (0 )
182
206
value_widget .setSizePolicy (QSizePolicy .Expanding , QSizePolicy .Fixed )
183
207
layout .addWidget (value_widget )
184
- self .form_layout .addRow ("Kokonaisluku (positiivinen)" , layout )
208
+ label = QLabel ("Arvo" )
209
+ label .setToolTip ("Tyyppi: kokonaisluku (positiivinen)" )
210
+ self .form_layout .addRow (label , layout )
211
+ self .widgets .append ((label , value_widget ))
185
212
186
213
def add_positive_integer_range_input (self , layout : QHBoxLayout ):
187
214
min_widget = QgsSpinBox ()
@@ -194,28 +221,40 @@ def add_positive_integer_range_input(self, layout: QHBoxLayout):
194
221
dash_label .setSizePolicy (QSizePolicy .Maximum , QSizePolicy .Fixed )
195
222
layout .addWidget (dash_label )
196
223
layout .addWidget (max_widget )
197
- self .form_layout .addRow ("Kokonaisluku arvoväli (positiivinen)" , layout )
224
+ label = QLabel ("Arvo" )
225
+ label .setToolTip ("Tyyppi: kokonaisluku arvoväli (positiivinen)" )
226
+ self .form_layout .addRow (label , layout )
227
+ self .widgets .append ((label , layout ))
198
228
199
229
def add_versioned_text_input (self , layout : QHBoxLayout ):
200
230
text_widget = QTextEdit ()
201
231
layout .addWidget (text_widget )
202
- self .form_layout .addRow ("Kieliversioitu teksti" , layout )
232
+ label = QLabel ("Arvo" )
233
+ label .setToolTip ("Tyyppi: kieliversioitu teksti" )
234
+ self .form_layout .addRow (label , layout )
235
+ self .widgets .append ((label , text_widget ))
203
236
204
237
def add_additional_info (self , info_type : str ) -> QHBoxLayout :
205
238
layout = QHBoxLayout ()
206
239
info_name = get_additional_information_name (info_type )
207
240
info_type_label = QLineEdit (info_name )
208
241
info_type_label .setReadOnly (True )
209
242
layout .addWidget (info_type_label )
210
- self .form_layout .addRow ("Lisätiedonlaji" , layout )
243
+ label = QLabel ("Lisätiedonlaji" )
244
+ self .form_layout .addRow (label , layout )
245
+ self .widgets .append ((label , info_type_label ))
211
246
return layout
212
247
213
248
def add_regulation_number (self ):
214
249
if not self .regulation_number_added :
215
250
number_widget = QgsSpinBox ()
216
- self .form_layout .addRow ("Määräysnumero" , number_widget )
251
+ label = QLabel ("Määräysnumero" )
252
+ self .form_layout .addRow (label , number_widget )
253
+ self .widgets .append ((label , number_widget ))
217
254
self .regulation_number_added = True
218
255
219
256
def add_file (self ):
220
257
file_input = QgsFileWidget ()
221
- self .form_layout .addRow ("Liiteasiakirja" , file_input )
258
+ label = QLabel ("Liiteasiakirja" )
259
+ self .form_layout .addRow (label , file_input )
260
+ self .widgets .append ((label , file_input ))
0 commit comments