15
15
QScrollArea ,
16
16
QSizePolicy ,
17
17
QSpacerItem ,
18
+ QTextEdit ,
18
19
QTreeWidget ,
19
20
QTreeWidgetItem ,
20
21
)
21
22
22
- from arho_feature_template .core .models import RegulationGroup , RegulationGroupLibrary
23
+ from arho_feature_template .core .models import PlanFeature , RegulationGroup , RegulationGroupLibrary
23
24
from arho_feature_template .gui .plan_regulation_group_widget import RegulationGroupWidget
25
+ from arho_feature_template .project .layers .plan_layers import LandUseAreaLayer , PlanFeatureLayer
24
26
from arho_feature_template .qgis_plugin_tools .tools .resources import resources_path
25
27
26
28
if TYPE_CHECKING :
29
+ from qgis .core import QgsFeature
27
30
from qgis .PyQt .QtWidgets import QWidget
28
31
29
32
from arho_feature_template .core .template_library_config import FeatureTemplate
35
38
class TemplateAttributeForm (QDialog , FormClass ): # type: ignore
36
39
"""Parent class for feature template forms for adding and modifying feature attribute data."""
37
40
38
- def __init__ (self , feature_template_config : FeatureTemplate ):
41
+ def __init__ (
42
+ self ,
43
+ feature_template_config : FeatureTemplate ,
44
+ base_feature : QgsFeature ,
45
+ feature_layer_class : type [PlanFeatureLayer ] = LandUseAreaLayer , # NOTE: All are now saved to LandUseAreaLayer
46
+ ):
39
47
super ().__init__ ()
40
48
self .setupUi (self )
41
49
42
50
# TYPES
51
+ self .geom = base_feature .geometry ()
52
+ self .feature_layer_class = feature_layer_class
43
53
self .feature_name : QLineEdit
44
- self .feature_description : QLineEdit
45
- self .feature_underground : QLineEdit
54
+ self .feature_description : QTextEdit
55
+ self .feature_type_of_underground : QComboBox
46
56
self .plan_regulation_group_scrollarea : QScrollArea
47
57
self .plan_regulation_group_scrollarea_contents : QWidget
48
58
self .plan_regulation_group_libraries_combobox : QComboBox
49
59
self .plan_regulation_groups_tree : QTreeWidget
50
60
self .button_box : QDialogButtonBox
51
61
52
62
# INIT
63
+ self .regulation_group_widgets : list [RegulationGroupWidget ] = []
53
64
self .scroll_area_spacer = None
54
65
self .setWindowTitle (feature_template_config .name )
55
66
self .init_plan_regulation_group_libraries ()
@@ -73,15 +84,17 @@ def add_selected_plan_regulation_group(self, item: QTreeWidgetItem, column: int)
73
84
self .add_plan_regulation_group (regulation_group )
74
85
75
86
def add_plan_regulation_group (self , definition : RegulationGroup ):
76
- new_plan_regulation_group = RegulationGroupWidget (definition )
77
- new_plan_regulation_group .delete_signal .connect (self .remove_plan_regulation_group )
87
+ regulation_group_widget = RegulationGroupWidget (definition )
88
+ regulation_group_widget .delete_signal .connect (self .remove_plan_regulation_group )
78
89
self ._remove_spacer ()
79
- self .plan_regulation_group_scrollarea_contents .layout ().addWidget (new_plan_regulation_group )
90
+ self .plan_regulation_group_scrollarea_contents .layout ().addWidget (regulation_group_widget )
91
+ self .regulation_group_widgets .append (regulation_group_widget )
80
92
self ._add_spacer ()
81
93
82
- def remove_plan_regulation_group (self , plan_regulation_group_widget : RegulationGroupWidget ):
83
- self .plan_regulation_group_scrollarea_contents .layout ().removeWidget (plan_regulation_group_widget )
84
- plan_regulation_group_widget .deleteLater ()
94
+ def remove_plan_regulation_group (self , regulation_group_widget : RegulationGroupWidget ):
95
+ self .plan_regulation_group_scrollarea_contents .layout ().removeWidget (regulation_group_widget )
96
+ self .regulation_group_widgets .remove (regulation_group_widget )
97
+ regulation_group_widget .deleteLater ()
85
98
86
99
def init_plan_regulation_group_libraries (self ):
87
100
katja_asemakaava_path = Path (os .path .join (resources_path (), "katja_asemakaava.yaml" ))
@@ -100,5 +113,22 @@ def init_plan_regulation_group_library(self, library: RegulationGroupLibrary):
100
113
regulation_group_item .setText (0 , group_definition .name )
101
114
regulation_group_item .setData (0 , Qt .UserRole , group_definition )
102
115
116
+ def into_model (self ) -> PlanFeature :
117
+ return PlanFeature (
118
+ name = self .feature_name .text (),
119
+ type_of_underground = self .feature_type_of_underground .currentIndex (),
120
+ description = self .feature_description .toPlainText (),
121
+ geom = self .geom ,
122
+ feature_layer_class = self .feature_layer_class ,
123
+ id_ = None ,
124
+ )
125
+
103
126
def _on_ok_clicked (self ):
127
+ # Plan feature data
128
+ self .into_model ().save_data ()
129
+
130
+ # Regulation group data
131
+ for regulation_group_widget in self .regulation_group_widgets :
132
+ regulation_group_widget .into_model ().save_data ()
133
+
104
134
self .accept ()
0 commit comments