Skip to content

Commit baa880b

Browse files
committed
add different style and indicator labels for existing plan regulation groups
- add colored frame for regulation group widget when the group exists - add link icon and linked feature count to regulation group when the group exists
1 parent d504a46 commit baa880b

File tree

5 files changed

+55
-7
lines changed

5 files changed

+55
-7
lines changed

arho_feature_template/gui/components/plan_regulation_group_widget.py

+52-4
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@
66
from qgis.core import QgsApplication
77
from qgis.PyQt import uic
88
from qgis.PyQt.QtCore import pyqtSignal
9-
from qgis.PyQt.QtGui import QIcon
10-
from qgis.PyQt.QtWidgets import QWidget
9+
from qgis.PyQt.QtGui import QIcon, QPixmap
10+
from qgis.PyQt.QtWidgets import QHBoxLayout, QLabel, QSizePolicy, QWidget
1111

1212
from arho_feature_template.core.models import Proposition, Regulation, RegulationGroup
1313
from arho_feature_template.gui.components.plan_proposition_widget import PropositionWidget
1414
from arho_feature_template.gui.components.plan_regulation_widget import RegulationWidget
1515
from arho_feature_template.project.layers.code_layers import PlanRegulationGroupTypeLayer
16+
from arho_feature_template.project.layers.plan_layers import RegulationGroupAssociationLayer
1617
from arho_feature_template.qgis_plugin_tools.tools.resources import resources_path
1718

1819
if TYPE_CHECKING:
19-
from qgis.PyQt.QtWidgets import QFormLayout, QFrame, QLabel, QLineEdit, QPushButton
20+
from qgis.PyQt.QtWidgets import QFormLayout, QFrame, QLineEdit, QPushButton
2021

2122
ui_path = resources.files(__package__) / "plan_regulation_group_widget.ui"
2223
FormClass, _ = uic.loadUiType(ui_path)
@@ -42,11 +43,14 @@ def __init__(self, regulation_group: RegulationGroup, layer_name: str):
4243
self.regulation_group_details_layout: QFormLayout
4344

4445
# INIT
46+
self.frame.setObjectName("frame") # Set unique name to avoid style cascading
4547
self.regulation_widgets: list[RegulationWidget] = []
4648
self.proposition_widgets: list[PropositionWidget] = []
49+
self.link_label_icon: QLabel | None = None
50+
self.link_label_text: QLabel | None = None
4751

48-
regulation_group.type_code_id = PlanRegulationGroupTypeLayer.get_id_by_feature_layer_name(layer_name)
4952
self.from_model(regulation_group)
53+
self.regulation_group.type_code_id = PlanRegulationGroupTypeLayer.get_id_by_feature_layer_name(layer_name)
5054

5155
self.edit_btn.setIcon(QIcon(resources_path("icons", "settings.svg")))
5256
self.edit_btn.clicked.connect(lambda: self.open_as_form_signal.emit(self))
@@ -67,6 +71,12 @@ def from_model(self, regulation_group: RegulationGroup):
6771
self.regulation_widgets = [self.add_regulation_widget(reg) for reg in regulation_group.regulations]
6872
self.proposition_widgets = [self.add_proposition_widget(prop) for prop in regulation_group.propositions]
6973

74+
if regulation_group.id_:
75+
# Remove existing indicators if reinitializing
76+
self.unset_existing_regulation_group_style()
77+
# Set indicators that the regulation group exists in the plan already
78+
self.set_existing_regulation_group_style()
79+
7080
def add_regulation_widget(self, regulation: Regulation) -> RegulationWidget:
7181
widget = RegulationWidget(regulation=regulation, parent=self.frame)
7282
widget.delete_signal.connect(self.delete_regulation_widget)
@@ -89,6 +99,44 @@ def delete_proposition_widget(self, proposition_widget: RegulationWidget):
8999
self.proposition_widgets.remove(proposition_widget)
90100
proposition_widget.deleteLater()
91101

102+
def set_existing_regulation_group_style(self):
103+
tooltip = (
104+
"Kaavamääräysryhmä on tallennettu kaavaan. Ryhmän tietojen muokkaaminen vaikuttaa muihin "
105+
"kaavakohteisiin, joille ryhmä on lisätty."
106+
)
107+
layout = QHBoxLayout()
108+
109+
self.link_label_icon = QLabel()
110+
self.link_label_icon.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Fixed)
111+
self.link_label_icon.setPixmap(QPixmap(resources_path("icons", "linked_img_small.png")))
112+
self.link_label_icon.setToolTip(tooltip)
113+
layout.addWidget(self.link_label_icon)
114+
115+
self.link_label_text = QLabel()
116+
self.link_label_text.setObjectName("text_label") # Set unique name to avoid style cascading
117+
feat_count = len(
118+
list(RegulationGroupAssociationLayer.get_associations_for_regulation_group(self.regulation_group.id_))
119+
)
120+
self.link_label_text.setText(f"Kaavamääräysryhmä on käytössä {feat_count} kaavakohteella")
121+
self.link_label_text.setStyleSheet("#text_label { color: #4b8db2; }")
122+
self.link_label_text.setToolTip(tooltip)
123+
layout.addWidget(self.link_label_text)
124+
125+
self.frame.layout().insertLayout(1, layout)
126+
127+
self.setStyleSheet("#frame { border: 2px solid #4b8db2; }")
128+
129+
def unset_existing_regulation_group_style(self):
130+
if self.link_label_icon:
131+
self.link_label_icon.deleteLater()
132+
self.link_label_icon = None
133+
134+
if self.link_label_text:
135+
self.link_label_text.deleteLater()
136+
self.link_label_text = None
137+
138+
self.setStyleSheet("")
139+
92140
def into_model(self) -> RegulationGroup:
93141
return RegulationGroup(
94142
type_code_id=self.regulation_group.type_code_id,

arho_feature_template/gui/components/plan_regulation_group_widget.ui

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>420</width>
10-
<height>129</height>
9+
<width>467</width>
10+
<height>130</height>
1111
</rect>
1212
</property>
1313
<property name="sizePolicy">

arho_feature_template/project/layers/plan_layers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def feature_from_model(cls, model: Regulation) -> QgsFeature:
326326
feature["unit"] = model.config.unit
327327
feature["text_value"] = {LANGUAGE: model.value if isinstance(model.value, str) else ""}
328328
feature["numeric_value"] = model.value if isinstance(model.value, Number) else NULL
329-
feature["name"] = {LANGUAGE: model.topic_tag if model.topic_tag else ""}
329+
# feature["name"] = {LANGUAGE: model.topic_tag if model.topic_tag else ""}
330330
feature["type_of_verbal_plan_regulation_id"] = model.verbal_regulation_type_id
331331
feature["id"] = model.id_ if model.id_ else feature["id"]
332332
# feature["plan_theme_id"]
Loading
Loading

0 commit comments

Comments
 (0)