Skip to content

Commit 90a3f2f

Browse files
committed
redesign plan regulation widget buttons, add expand/hide button
1 parent 4a40b5a commit 90a3f2f

File tree

2 files changed

+181
-107
lines changed

2 files changed

+181
-107
lines changed

arho_feature_template/gui/plan_regulation_widget.py

+63-24
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
from collections import defaultdict
43
from importlib import resources
54
from typing import TYPE_CHECKING, cast
65

@@ -16,15 +15,14 @@
1615
QMenu,
1716
QSizePolicy,
1817
QTextEdit,
18+
QToolButton,
1919
QWidget,
2020
)
2121

2222
from arho_feature_template.core.plan_regulation_config import PlanRegulationConfig, Unit, ValueType
2323
from arho_feature_template.utils.misc_utils import get_additional_information_name
2424

2525
if TYPE_CHECKING:
26-
from numbers import Number
27-
2826
from qgis.PyQt.QtWidgets import QPushButton
2927

3028
from arho_feature_template.core.plan_regulation_group_config import PlanRegulationDefinition
@@ -56,21 +54,23 @@ def __init__(self, config: PlanRegulationConfig, parent=None):
5654
self.setupUi(self)
5755

5856
# TYPES
57+
# self.spacer_layout: QBoxLayout
5958
self.plan_regulation_name: QLineEdit
6059
self.form_layout: QFormLayout
6160

6261
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
6563
self.del_btn: QPushButton
64+
self.expand_hide_btn: QToolButton
65+
66+
self.code_label: QLabel
67+
self.code: QLineEdit
6668

6769
# INIT
6870
self.config = config
6971
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] = []
7474
self.plan_regulation_name.setText(config.name)
7575
self.plan_regulation_name.setReadOnly(True)
7676
self.init_value_fields()
@@ -157,31 +157,58 @@ def init_buttons(self):
157157
type_main_menu.addMenu(type_menu)
158158
type_main_menu.addMenu(signifigance_menu)
159159
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
166188

167189
def add_decimal_input(self, layout: QHBoxLayout, value_type: ValueType):
168190
value_widget = QgsDoubleSpinBox()
169-
label_text = "Desimaali"
191+
label = QLabel("Arvo")
170192
if value_type == ValueType.POSITIVE_DECIMAL:
171193
value_widget.setMinimum(0.0)
172-
label_text += " (positiivinen)"
194+
label.setToolTip("Tyyppi: desimaali (positiivinen)")
173195
else:
174196
value_widget.setMinimum(-9999.9)
197+
label.setToolTip("Tyyppi: desimaali")
175198
value_widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
176199
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))
178202

179203
def add_positive_integer_input(self, layout: QHBoxLayout):
180204
value_widget = QgsSpinBox()
181205
value_widget.setMinimum(0)
182206
value_widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
183207
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))
185212

186213
def add_positive_integer_range_input(self, layout: QHBoxLayout):
187214
min_widget = QgsSpinBox()
@@ -194,28 +221,40 @@ def add_positive_integer_range_input(self, layout: QHBoxLayout):
194221
dash_label.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Fixed)
195222
layout.addWidget(dash_label)
196223
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))
198228

199229
def add_versioned_text_input(self, layout: QHBoxLayout):
200230
text_widget = QTextEdit()
201231
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))
203236

204237
def add_additional_info(self, info_type: str) -> QHBoxLayout:
205238
layout = QHBoxLayout()
206239
info_name = get_additional_information_name(info_type)
207240
info_type_label = QLineEdit(info_name)
208241
info_type_label.setReadOnly(True)
209242
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))
211246
return layout
212247

213248
def add_regulation_number(self):
214249
if not self.regulation_number_added:
215250
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))
217254
self.regulation_number_added = True
218255

219256
def add_file(self):
220257
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

Comments
 (0)