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 ))
@@ -67,6 +71,12 @@ def from_model(self, regulation_group: RegulationGroup):
67
71
self .regulation_widgets = [self .add_regulation_widget (reg ) for reg in regulation_group .regulations ]
68
72
self .proposition_widgets = [self .add_proposition_widget (prop ) for prop in regulation_group .propositions ]
69
73
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
+
70
80
def add_regulation_widget (self , regulation : Regulation ) -> RegulationWidget :
71
81
widget = RegulationWidget (regulation = regulation , parent = self .frame )
72
82
widget .delete_signal .connect (self .delete_regulation_widget )
@@ -89,6 +99,44 @@ def delete_proposition_widget(self, proposition_widget: RegulationWidget):
89
99
self .proposition_widgets .remove (proposition_widget )
90
100
proposition_widget .deleteLater ()
91
101
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
+
92
140
def into_model (self ) -> RegulationGroup :
93
141
return RegulationGroup (
94
142
type_code_id = self .regulation_group .type_code_id ,
0 commit comments