6
6
from qgis .core import QgsApplication
7
7
from qgis .PyQt import uic
8
8
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
11
11
12
12
from arho_feature_template .core .models import Proposition , Regulation , RegulationGroup
13
13
from arho_feature_template .gui .components .plan_proposition_widget import PropositionWidget
14
14
from arho_feature_template .gui .components .plan_regulation_widget import RegulationWidget
15
15
from arho_feature_template .project .layers .code_layers import PlanRegulationGroupTypeLayer
16
+ from arho_feature_template .project .layers .plan_layers import RegulationGroupAssociationLayer
16
17
from arho_feature_template .qgis_plugin_tools .tools .resources import resources_path
17
18
18
19
if TYPE_CHECKING :
19
- from qgis .PyQt .QtWidgets import QFormLayout , QFrame , QLabel , QLineEdit , QPushButton
20
+ from qgis .PyQt .QtWidgets import QFormLayout , QFrame , QLineEdit , QPushButton
20
21
21
22
ui_path = resources .files (__package__ ) / "plan_regulation_group_widget.ui"
22
23
FormClass , _ = uic .loadUiType (ui_path )
@@ -42,11 +43,14 @@ def __init__(self, regulation_group: RegulationGroup, layer_name: str):
42
43
self .regulation_group_details_layout : QFormLayout
43
44
44
45
# INIT
46
+ self .frame .setObjectName ("frame" ) # Set unique name to avoid style cascading
45
47
self .regulation_widgets : list [RegulationWidget ] = []
46
48
self .proposition_widgets : list [PropositionWidget ] = []
49
+ self .link_label_icon : QLabel | None = None
50
+ self .link_label_text : QLabel | None = None
47
51
48
- regulation_group .type_code_id = PlanRegulationGroupTypeLayer .get_id_by_feature_layer_name (layer_name )
49
52
self .from_model (regulation_group )
53
+ self .regulation_group .type_code_id = PlanRegulationGroupTypeLayer .get_id_by_feature_layer_name (layer_name )
50
54
51
55
self .edit_btn .setIcon (QIcon (resources_path ("icons" , "settings.svg" )))
52
56
self .edit_btn .clicked .connect (lambda : self .open_as_form_signal .emit (self ))
@@ -69,6 +73,12 @@ def from_model(self, regulation_group: RegulationGroup):
69
73
for proposition in regulation_group .propositions :
70
74
self .add_proposition_widget (proposition )
71
75
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
+
72
82
def add_regulation_widget (self , regulation : Regulation ) -> RegulationWidget :
73
83
widget = RegulationWidget (regulation = regulation , parent = self .frame )
74
84
widget .delete_signal .connect (self .delete_regulation_widget )
@@ -93,6 +103,44 @@ def delete_proposition_widget(self, proposition_widget: RegulationWidget):
93
103
self .proposition_widgets .remove (proposition_widget )
94
104
proposition_widget .deleteLater ()
95
105
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
+
96
144
def into_model (self ) -> RegulationGroup :
97
145
return RegulationGroup (
98
146
type_code_id = self .regulation_group .type_code_id ,
0 commit comments