3
3
from importlib import resources
4
4
from typing import TYPE_CHECKING
5
5
6
- from qgis .core import QgsApplication , QgsFeature
7
6
from qgis .gui import QgsSpinBox
8
7
from qgis .PyQt import uic
9
8
from qgis .PyQt .QtWidgets import (
10
9
QDialog ,
11
10
QDialogButtonBox ,
12
11
QLineEdit ,
13
- QPushButton ,
14
12
QScrollArea ,
15
13
QSizePolicy ,
16
14
QSpacerItem ,
17
15
QTreeWidget ,
16
+ QTreeWidgetItem ,
18
17
)
19
18
20
19
from arho_feature_template .gui .plan_regulation_group_widget import PlanRegulationGroupWidget
21
20
22
21
if TYPE_CHECKING :
22
+ from qgis .core import QgsFeature
23
23
from qgis .PyQt .QtWidgets import QWidget
24
24
25
25
from arho_feature_template .core .template_library_config import Feature , FeatureTemplate
@@ -39,65 +39,61 @@ def __init__(self, feature_template_config: FeatureTemplate):
39
39
self .feature_name : QLineEdit
40
40
self .feature_description : QLineEdit
41
41
self .feature_underground : QLineEdit
42
- self .feature_vertical_boundaries : QLineEdit
43
42
self .plan_regulation_group_scrollarea : QScrollArea
44
43
self .plan_regulation_group_scrollarea_contents : QWidget
45
44
self .plan_regulation_groups_tree : QTreeWidget
46
- self .add_plan_regulation_group_btn : QPushButton
47
45
self .button_box : QDialogButtonBox
48
46
49
47
# SIGNALS
50
48
self .button_box .accepted .connect (self ._on_ok_clicked )
51
- self .add_plan_regulation_group_btn . clicked .connect (self ._on_add_plan_regulation_group_clicked )
49
+ self .plan_regulation_groups_tree . itemDoubleClicked .connect (self .add_selected_plan_regulation_group )
52
50
53
51
# INIT
54
52
self .attribute_widgets = {
55
53
"name" : self .feature_name ,
56
54
"description" : self .feature_description ,
57
55
"type_of_underground_id" : self .feature_underground ,
58
- # self.feature_vertical_boundaries
59
56
}
57
+ # TODO: The 'configs' could be a mapping where keys are plan regulation group names and
58
+ # values are the related configurations
59
+ self .configs : dict [str , Feature ] = {}
60
60
self .scroll_area_spacer = None
61
61
self .available_plan_regulation_group_configs : list [Feature ] = []
62
- self .add_plan_regulation_group_btn .setIcon (QgsApplication .getThemeIcon ("mActionAdd.svg" ))
63
62
64
63
self .setWindowTitle (feature_template_config .name )
65
64
self .init_feature_attributes_from_template (feature_template_config )
66
65
self .init_plan_regulation_groups_from_template (feature_template_config )
67
66
self .init_plan_regulation_group_library ()
68
67
69
- def add_spacer (self ):
68
+ def _add_spacer (self ):
70
69
self .scroll_area_spacer = QSpacerItem (0 , 0 , QSizePolicy .Expanding , QSizePolicy .Expanding )
71
70
self .plan_regulation_group_scrollarea_contents .layout ().addItem (self .scroll_area_spacer )
72
71
73
- def remove_spacer (self ):
72
+ def _remove_spacer (self ):
74
73
if self .scroll_area_spacer is not None :
75
74
self .plan_regulation_group_scrollarea_contents .layout ().removeItem (self .scroll_area_spacer )
76
75
self .scroll_area_spacer = None
77
76
77
+ def add_selected_plan_regulation_group (self , item : QTreeWidgetItem , column : int ):
78
+ if not item .parent ():
79
+ return
80
+ config = self .configs .get (item .text (column ))
81
+ if not config :
82
+ print (f"Could not find plan regulation group configuration for { item .text (column )} " ) # noqa: T201
83
+ return
84
+ self .add_plan_regulation_group (config )
85
+
78
86
def add_plan_regulation_group (self , feature_config : Feature ):
79
87
new_plan_regulation_group = PlanRegulationGroupWidget (feature_config )
80
88
new_plan_regulation_group .delete_signal .connect (self .remove_plan_regulation_group )
81
- self .remove_spacer ()
89
+ self ._remove_spacer ()
82
90
self .plan_regulation_group_scrollarea_contents .layout ().addWidget (new_plan_regulation_group )
83
- self .add_spacer ()
91
+ self ._add_spacer ()
84
92
85
93
def remove_plan_regulation_group (self , plan_regulation_group_widget : PlanRegulationGroupWidget ):
86
94
self .plan_regulation_group_scrollarea_contents .layout ().removeWidget (plan_regulation_group_widget )
87
95
plan_regulation_group_widget .deleteLater ()
88
96
89
- def _on_add_plan_regulation_group_clicked (self ):
90
- selected = self .plan_regulation_groups_tree .selectedItems ()
91
- if len (selected ) == 0 :
92
- # Nothing selected
93
- return
94
- if len (selected ) > 1 :
95
- # Too many selected, but should allow selecting only 1 item at a time
96
- return
97
- selected_plan_regulation_group = selected [0 ]
98
- print (f"Trying to add plan regulation group { selected_plan_regulation_group .text (0 )} " ) # noqa: T201
99
- # self.add_plan_regulation_group() # TODO: Implement
100
-
101
97
def init_plan_regulation_group_library (self ):
102
98
# Now plan regulation group tree widget/view is just static placeholder for demo
103
99
pass
0 commit comments