1
1
from __future__ import annotations
2
2
3
3
from importlib import resources
4
- from typing import TYPE_CHECKING
4
+ from typing import TYPE_CHECKING , cast
5
5
6
6
from qgis .core import QgsApplication
7
7
from qgis .PyQt import uic
8
8
from qgis .PyQt .QtCore import pyqtSignal
9
9
from qgis .PyQt .QtGui import QIcon , QPixmap
10
10
from qgis .PyQt .QtWidgets import QHBoxLayout , QLabel , QSizePolicy , QWidget
11
11
12
- from arho_feature_template .core .models import Proposition , Regulation , RegulationGroup
12
+ from arho_feature_template .core .models import PlanFeature , 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
@@ -29,7 +29,7 @@ class RegulationGroupWidget(QWidget, FormClass): # type: ignore
29
29
open_as_form_signal = pyqtSignal (QWidget )
30
30
delete_signal = pyqtSignal (QWidget )
31
31
32
- def __init__ (self , regulation_group : RegulationGroup , layer_name : str ):
32
+ def __init__ (self , regulation_group : RegulationGroup , plan_feature : PlanFeature ):
33
33
super ().__init__ ()
34
34
self .setupUi (self )
35
35
@@ -49,8 +49,10 @@ def __init__(self, regulation_group: RegulationGroup, layer_name: str):
49
49
self .link_label_icon : QLabel | None = None
50
50
self .link_label_text : QLabel | None = None
51
51
52
+ self .plan_feature = plan_feature
53
+ self .layer_name = cast (str , plan_feature .layer_name )
52
54
self .from_model (regulation_group )
53
- self .regulation_group .type_code_id = PlanRegulationGroupTypeLayer .get_id_by_feature_layer_name (layer_name )
55
+ self .regulation_group .type_code_id = PlanRegulationGroupTypeLayer .get_id_by_feature_layer_name (self . layer_name )
54
56
55
57
self .edit_btn .setIcon (QIcon (resources_path ("icons" , "settings.svg" )))
56
58
self .edit_btn .clicked .connect (lambda : self .open_as_form_signal .emit (self ))
@@ -73,11 +75,18 @@ def from_model(self, regulation_group: RegulationGroup):
73
75
for proposition in regulation_group .propositions :
74
76
self .add_proposition_widget (proposition )
75
77
78
+ # Remove existing indicators if reinitializing
79
+ self .unset_existing_regulation_group_style ()
80
+
76
81
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 ()
82
+ other_linked_features_count = len (
83
+ RegulationGroupAssociationLayer .get_associations_for_regulation_group_exclude_feature (
84
+ cast (str , regulation_group .id_ ), cast (str , self .plan_feature .id_ ), self .layer_name
85
+ )
86
+ )
87
+ if other_linked_features_count > 0 :
88
+ # Set indicators that regulation group exists in the plan already and is assigned for other features
89
+ self .set_existing_regulation_group_style (other_linked_features_count )
81
90
82
91
def add_regulation_widget (self , regulation : Regulation ) -> RegulationWidget :
83
92
widget = RegulationWidget (regulation = regulation , parent = self .frame )
@@ -103,7 +112,7 @@ def delete_proposition_widget(self, proposition_widget: RegulationWidget):
103
112
self .proposition_widgets .remove (proposition_widget )
104
113
proposition_widget .deleteLater ()
105
114
106
- def set_existing_regulation_group_style (self ):
115
+ def set_existing_regulation_group_style (self , other_linked_features_count : int ):
107
116
tooltip = (
108
117
"Kaavamääräysryhmä on tallennettu kaavaan. Ryhmän tietojen muokkaaminen vaikuttaa muihin "
109
118
"kaavakohteisiin, joille ryhmä on lisätty."
@@ -118,10 +127,10 @@ def set_existing_regulation_group_style(self):
118
127
119
128
self .link_label_text = QLabel ()
120
129
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_ ))
130
+ self . link_label_text . setText (
131
+ f"Kaavamääräysryhmä on käytössä myös { other_linked_features_count } toisella kaavakohteella"
123
132
)
124
- self .link_label_text .setText ( f"Kaavamääräysryhmä on käytössä { feat_count } kaavakohteella" )
133
+ self .link_label_text .setWordWrap ( True )
125
134
self .link_label_text .setStyleSheet ("#text_label { color: #4b8db2; }" )
126
135
self .link_label_text .setToolTip (tooltip )
127
136
layout .addWidget (self .link_label_text )
0 commit comments