Skip to content

Commit 16d43d1

Browse files
committed
add RequiredFieldLabel widget for creating marked labels in code
1 parent a38e7bd commit 16d43d1

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

arho_feature_template/gui/components/additional_information_widget.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
)
1616

1717
from arho_feature_template.core.models import AdditionalInformation
18+
from arho_feature_template.gui.components.required_field_label import RequiredFieldLabel
1819
from arho_feature_template.gui.components.value_input_widgets import (
1920
ValueWidgetManager,
2021
)
@@ -72,7 +73,7 @@ def __init__(self, additional_information: AdditionalInformation, parent=None):
7273
if self.value_widget_manager.value_widget is not None
7374
else QLabel("Syötekenttää tälle tyypille ei ole vielä toteutettu")
7475
)
75-
self._add_widget(QLabel("Arvo"), widget)
76+
self._add_widget(RequiredFieldLabel("Arvo"), widget)
7677

7778
def _add_widget(self, label: QLabel, widget: QWidget):
7879
self.form_layout.addRow(label, widget)

arho_feature_template/gui/components/plan_regulation_widget.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
)
1717
from arho_feature_template.gui.components.additional_information_widget import AdditionalInformationWidget
1818
from arho_feature_template.gui.components.code_combobox import HierarchicalCodeComboBox
19+
from arho_feature_template.gui.components.required_field_label import RequiredFieldLabel
1920
from arho_feature_template.gui.components.value_input_widgets import (
2021
IntegerInputWidget,
2122
SinglelineTextInputWidget,
@@ -84,12 +85,12 @@ def __init__(self, regulation: Regulation, parent=None):
8485
def _init_widgets(self):
8586
# Value input
8687
if self.config.default_value:
87-
self._add_widget(QLabel("Arvo"), self.value_widget_manager.value_widget)
88+
self._add_widget(RequiredFieldLabel("Arvo"), self.value_widget_manager.value_widget)
8889

8990
if self.config.regulation_code == "sanallinenMaarays":
9091
self.type_of_verbal_regulation_widget = HierarchicalCodeComboBox()
9192
self.type_of_verbal_regulation_widget.populate_from_code_layer(VerbalRegulationType)
92-
self._add_widget(QLabel("Sanallisen määräyksen laji"), self.type_of_verbal_regulation_widget)
93+
self._add_widget(RequiredFieldLabel("Sanallisen määräyksen laji"), self.type_of_verbal_regulation_widget)
9394
if self.regulation.verbal_regulation_type_id is not None:
9495
self.type_of_verbal_regulation_widget.set_value(self.regulation.verbal_regulation_type_id)
9596

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from __future__ import annotations
2+
3+
from qgis.PyQt.QtWidgets import QLabel, QWidget
4+
5+
6+
class RequiredFieldLabel(QLabel):
7+
"""QLabel that prefixes the text with a red asterisk."""
8+
9+
def __init__(self, text: str, parent: QWidget | None = None):
10+
super().__init__(self._prefix(text), parent)
11+
12+
def setText(self, text: str): # noqa: N802
13+
return super().setText(self._prefix(text))
14+
15+
@staticmethod
16+
def _prefix(text: str) -> str:
17+
return f'<span style="color: red;">* </span>{text}'

0 commit comments

Comments
 (0)