5
5
6
6
from qgis .PyQt import uic
7
7
from qgis .PyQt .QtCore import Qt
8
+ from qgis .PyQt .QtGui import QStandardItem , QStandardItemModel
8
9
from qgis .PyQt .QtWidgets import (
9
10
QComboBox ,
11
+ QDateEdit ,
10
12
QDialog ,
11
13
QDialogButtonBox ,
12
14
QLineEdit ,
15
+ QListView ,
16
+ QPushButton ,
13
17
QSizePolicy ,
14
18
QSpacerItem ,
15
19
QTextEdit ,
16
20
QTreeWidgetItem ,
17
21
)
18
22
19
- from arho_feature_template .core .models import Plan , RegulationGroup , RegulationGroupLibrary
23
+ from arho_feature_template .core .models import LifeCycle , Plan , RegulationGroup , RegulationGroupLibrary
20
24
from arho_feature_template .gui .components .plan_regulation_group_widget import RegulationGroupWidget
21
25
from arho_feature_template .gui .components .tree_with_search_widget import TreeWithSearchWidget
22
26
from arho_feature_template .project .layers .code_layers import (
@@ -40,7 +44,7 @@ class PlanAttributeForm(QDialog, FormClass): # type: ignore
40
44
organisation_combo_box : CodeComboBox
41
45
description_text_edit : QTextEdit
42
46
plan_type_combo_box : HierarchicalCodeComboBox
43
- lifecycle_status_combo_box : CodeComboBox
47
+ # lifecycle_status_combo_box: CodeComboBox
44
48
record_number_line_edit : QLineEdit
45
49
producers_plan_identifier_line_edit : QLineEdit
46
50
matter_management_identifier_line_edit : QLineEdit
@@ -49,6 +53,12 @@ class PlanAttributeForm(QDialog, FormClass): # type: ignore
49
53
plan_regulation_group_libraries_combobox : QComboBox
50
54
regulation_groups_tree_layout : QVBoxLayout
51
55
56
+ lifecycle_status_combo_box : CodeComboBox
57
+ lifecycle_start_date : QDateEdit
58
+ lifecycle_end_date : QDateEdit
59
+ add_lifecycle_button : QPushButton
60
+ lifecycle_list : QListView
61
+
52
62
button_box : QDialogButtonBox
53
63
54
64
def __init__ (self , plan : Plan , regulation_group_libraries : list [RegulationGroupLibrary ], parent = None ):
@@ -95,6 +105,10 @@ def __init__(self, plan: Plan, regulation_group_libraries: list[RegulationGroupL
95
105
for regulation_group in plan .general_regulations :
96
106
self .add_plan_regulation_group (regulation_group )
97
107
108
+ self .lifecycle_model = QStandardItemModel ()
109
+ self .lifecycle_list .setModel (self .lifecycle_model )
110
+ self .add_lifecycle_button .clicked .connect (self .save_lifecycle )
111
+
98
112
self .button_box .button (QDialogButtonBox .Ok ).setEnabled (False )
99
113
self .button_box .accepted .connect (self ._on_ok_clicked )
100
114
@@ -106,7 +120,8 @@ def _check_required_fields(self) -> None:
106
120
self .name_line_edit .text () != ""
107
121
and self .plan_type_combo_box .value () is not None
108
122
and self .organisation_combo_box .value () is not None
109
- and self .lifecycle_status_combo_box .value () is not None
123
+ # and self.lifecycle_status_combo_box.value() is not None
124
+ and self .lifecycle_model .rowCount () > 0
110
125
):
111
126
ok_button .setEnabled (True )
112
127
else :
@@ -153,6 +168,60 @@ def init_plan_regulation_group_library(self, library: RegulationGroupLibrary):
153
168
154
169
# ---
155
170
171
+ def save_lifecycle (self ):
172
+ # Get values from the widgets
173
+ status = self .lifecycle_status_combo_box .currentText () # Get the selected text from the combo box
174
+ start_date = self .lifecycle_start_date .date ().toString ("yyyy-MM-dd" ) # Format the QDate as a string
175
+ end_date = self .lifecycle_end_date .date ().toString ("yyyy-MM-dd" ) if self .lifecycle_end_date .date () else None
176
+
177
+ # Format the lifecycle entry
178
+ date_range = f"{ start_date } - { end_date } " if end_date else start_date
179
+ lifecycle_entry = f"{ status } | { date_range } "
180
+
181
+ # Add to the model
182
+ item = QStandardItem (lifecycle_entry )
183
+ self .lifecycle_model .appendRow (item )
184
+
185
+ # Optionally, check required fields again
186
+ self ._check_required_fields ()
187
+
188
+ def into_lifecycle_model (self ) -> list [LifeCycle ]:
189
+ print ("Calling into_lifecycle_model at plan_attribute_form.py" )
190
+ lifecycles = []
191
+
192
+ for row in range (self .lifecycle_model .rowCount ()):
193
+ item = self .lifecycle_model .item (row )
194
+ if item :
195
+ lifecycle_entry = item .text ()
196
+ parts = lifecycle_entry .split (" | " )
197
+ status = parts [0 ]
198
+ date_range = parts [1 ]
199
+ date_parts = date_range .split (" - " )
200
+ start_date = date_parts [0 ]
201
+ end_date = date_parts [1 ] if len (date_parts ) > 1 else None # End date is optional
202
+
203
+ print (f"Got status: { status } " )
204
+ print (f"Got status_id: { LifeCycleStatusLayer .get_id_by_value (status )} " )
205
+
206
+ # Add the lifecycle to the list
207
+ lifecycles .append (
208
+ LifeCycle (
209
+ status_id = LifeCycleStatusLayer .get_id_by_value (status ),
210
+ plan_id = "52aadc88-feb0-443b-a423-f5a50d0bb9fc" ,
211
+ land_use_are_id = None ,
212
+ other_area_id = None ,
213
+ line_id = None ,
214
+ land_use_point_id = None ,
215
+ other_point_id = None ,
216
+ starting_at = start_date ,
217
+ ending_at = end_date ,
218
+ plan_regulation_id = None ,
219
+ plan_proposition_id = None ,
220
+ )
221
+ )
222
+
223
+ return lifecycles
224
+
156
225
def into_model (self ) -> Plan :
157
226
return Plan (
158
227
id_ = self .plan .id_ ,
@@ -164,11 +233,13 @@ def into_model(self) -> Plan:
164
233
record_number = self .record_number_line_edit .text () or None ,
165
234
producers_plan_identifier = self .producers_plan_identifier_line_edit .text () or None ,
166
235
matter_management_identifier = self .matter_management_identifier_line_edit .text () or None ,
167
- lifecycle_status_id = self .lifecycle_status_combo_box .value (),
236
+ lifecycle_status_id = self .lifecycle_status_combo_box .value (), # Need to get the lifecycle with the latest lifecycle
237
+ # lifecycle=self.get_lifecycles(),
168
238
general_regulations = [reg_group_widget .into_model () for reg_group_widget in self .regulation_group_widgets ],
169
239
geom = self .plan .geom ,
170
240
)
171
241
172
242
def _on_ok_clicked (self ):
173
243
self .model = self .into_model ()
244
+ self .lifecycle_model = self .into_lifecycle_model ()
174
245
self .accept ()
0 commit comments