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
9
10
from qgis .PyQt .QtWidgets import QWidget
10
11
11
12
from arho_feature_template .core .models import Proposition , Regulation , RegulationGroup
12
13
from arho_feature_template .gui .components .plan_proposition_widget import PropositionWidget
13
14
from arho_feature_template .gui .components .plan_regulation_widget import RegulationWidget
14
15
from arho_feature_template .project .layers .code_layers import PlanRegulationGroupTypeLayer
16
+ from arho_feature_template .qgis_plugin_tools .tools .resources import resources_path
15
17
16
18
if TYPE_CHECKING :
17
19
from qgis .PyQt .QtWidgets import QFormLayout , QFrame , QLabel , QLineEdit , QPushButton
23
25
class RegulationGroupWidget (QWidget , FormClass ): # type: ignore
24
26
"""A widget representation of a plan regulation group."""
25
27
28
+ open_as_form_signal = pyqtSignal (QWidget )
26
29
delete_signal = pyqtSignal (QWidget )
27
30
28
- def __init__ (self , regulation_group_data : RegulationGroup , layer_name : str ):
31
+ def __init__ (self , regulation_group : RegulationGroup , layer_name : str ):
29
32
super ().__init__ ()
30
33
self .setupUi (self )
31
34
@@ -34,24 +37,36 @@ def __init__(self, regulation_group_data: RegulationGroup, layer_name: str):
34
37
self .name : QLineEdit
35
38
self .short_name : QLineEdit
36
39
self .short_name_label : QLabel
40
+ self .edit_btn : QPushButton
37
41
self .del_btn : QPushButton
38
42
self .regulation_group_details_layout : QFormLayout
39
43
40
44
# INIT
41
- self .regulation_group_data = regulation_group_data
42
- self .regulation_widgets : list [RegulationWidget ] = [
43
- self .add_regulation_widget (regulation ) for regulation in self .regulation_group_data .regulations
44
- ]
45
- self .proposition_widgets : list [PropositionWidget ] = [
46
- self .add_proposition_widget (proposition ) for proposition in self .regulation_group_data .propositions
47
- ]
48
-
49
- regulation_group_data .type_code_id = PlanRegulationGroupTypeLayer .get_id_by_feature_layer_name (layer_name )
50
- self .name .setText (self .regulation_group_data .name if self .regulation_group_data .name else "" )
51
- self .short_name .setText (self .regulation_group_data .short_name if self .regulation_group_data .short_name else "" )
45
+ self .regulation_widgets : list [RegulationWidget ] = []
46
+ self .proposition_widgets : list [PropositionWidget ] = []
47
+
48
+ regulation_group .type_code_id = PlanRegulationGroupTypeLayer .get_id_by_feature_layer_name (layer_name )
49
+ self .from_model (regulation_group )
50
+
51
+ self .edit_btn .setIcon (QIcon (resources_path ("icons" , "settings.svg" )))
52
+ self .edit_btn .clicked .connect (lambda : self .open_as_form_signal .emit (self ))
52
53
self .del_btn .setIcon (QgsApplication .getThemeIcon ("mActionDeleteSelected.svg" ))
53
54
self .del_btn .clicked .connect (lambda : self .delete_signal .emit (self ))
54
55
56
+ def from_model (self , regulation_group : RegulationGroup ):
57
+ self .regulation_group = regulation_group
58
+
59
+ self .name .setText (regulation_group .name if regulation_group .name else "" )
60
+ self .short_name .setText (regulation_group .short_name if regulation_group .short_name else "" )
61
+
62
+ # Remove existing child widgets if reinitializing
63
+ for widget in self .regulation_widgets :
64
+ self .delete_regulation_widget (widget )
65
+ for widget in self .proposition_widgets :
66
+ self .delete_proposition_widget (widget )
67
+ self .regulation_widgets = [self .add_regulation_widget (reg ) for reg in regulation_group .regulations ]
68
+ self .proposition_widgets = [self .add_proposition_widget (prop ) for prop in regulation_group .propositions ]
69
+
55
70
def add_regulation_widget (self , regulation : Regulation ) -> RegulationWidget :
56
71
widget = RegulationWidget (regulation = regulation , parent = self .frame )
57
72
widget .delete_signal .connect (self .delete_regulation_widget )
@@ -76,11 +91,11 @@ def delete_proposition_widget(self, proposition_widget: RegulationWidget):
76
91
77
92
def into_model (self ) -> RegulationGroup :
78
93
return RegulationGroup (
79
- type_code_id = self .regulation_group_data .type_code_id ,
94
+ type_code_id = self .regulation_group .type_code_id ,
80
95
name = self .name .text (),
81
96
short_name = None if not self .short_name .text () else self .short_name .text (),
82
- color_code = self .regulation_group_data .color_code ,
97
+ color_code = self .regulation_group .color_code ,
83
98
regulations = [widget .into_model () for widget in self .regulation_widgets ],
84
99
propositions = [widget .into_model () for widget in self .proposition_widgets ],
85
- id_ = self .regulation_group_data .id_ ,
100
+ id_ = self .regulation_group .id_ ,
86
101
)
0 commit comments