Skip to content

Commit ae876a8

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 2361884 commit ae876a8

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))
@@ -69,6 +73,12 @@ def from_model(self, regulation_group: RegulationGroup):
6973
for proposition in regulation_group.propositions:
7074
self.add_proposition_widget(proposition)
7175

76+
if regulation_group.id_:
77+
# Remove existing indicators if reinitializing
78+
self.unset_existing_regulation_group_style()
79+
# Set indicators that the regulation group exists in the plan already
80+
self.set_existing_regulation_group_style()
81+
7282
def add_regulation_widget(self, regulation: Regulation) -> RegulationWidget:
7383
widget = RegulationWidget(regulation=regulation, parent=self.frame)
7484
widget.delete_signal.connect(self.delete_regulation_widget)
@@ -93,6 +103,44 @@ def delete_proposition_widget(self, proposition_widget: RegulationWidget):
93103
self.proposition_widgets.remove(proposition_widget)
94104
proposition_widget.deleteLater()
95105

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