1
1
from __future__ import annotations
2
2
3
- from collections import defaultdict
4
3
from importlib import resources
5
4
from typing import TYPE_CHECKING
6
5
7
6
from qgis .core import QgsApplication
8
7
from qgis .PyQt import uic
9
8
from qgis .PyQt .QtCore import pyqtSignal
10
- from qgis .PyQt .QtGui import QFont , QIcon
11
- from qgis .PyQt .QtWidgets import QLabel , QLineEdit , QWidget
9
+ from qgis .PyQt .QtWidgets import QWidget
12
10
13
- from arho_feature_template .qgis_plugin_tools . tools . resources import plugin_path
11
+ from arho_feature_template .gui . plan_regulation_widget import PlanRegulationWidget
14
12
15
13
if TYPE_CHECKING :
16
- from qgis .gui import QgsCollapsibleGroupBox
17
- from qgis .PyQt .QtWidgets import QGridLayout , QPushButton
14
+ from qgis .PyQt .QtWidgets import QFrame , QLineEdit , QPushButton
18
15
19
16
from arho_feature_template .core .template_library_config import Feature
20
17
@@ -32,84 +29,36 @@ def __init__(self, feature: Feature):
32
29
self .setupUi (self )
33
30
34
31
# TYPES
32
+ self .frame : QFrame
35
33
self .heading : QLineEdit
36
- self .conf_btn : QPushButton
37
34
self .del_btn : QPushButton
38
35
39
- self .plan_regulation_groupbox : QgsCollapsibleGroupBox
40
- self .plan_regulation_grid_layout : QGridLayout
41
-
42
36
# INIT
43
37
self .feature = feature
44
38
self .layer = self .feature .layer # Should be plan_regulation_group layer
45
39
46
- self .input_value_header = None
47
- self .input_value_col = None
48
-
49
- self .additional_information_header = None
50
- self .additional_information_col = None
51
-
52
- self .bold_font = QFont ()
53
- self .bold_font .setBold (True )
54
-
55
40
self .init_buttons ()
56
-
57
- self .attribute_widgets : dict [str , dict [str , QWidget ]] = defaultdict (dict )
58
-
59
- for attribute_config in feature .attributes :
60
- if attribute_config .attribute == "name" :
61
- self .heading .setText (attribute_config .display ())
62
-
63
- if feature .child_features is not None :
64
- for child in feature .child_features :
65
- if child .layer == "plan_requlation" :
66
- self .create_widgets_for_plan_regulation (child )
41
+ self .set_group_heading ()
42
+ self .add_plan_regulation_widgets ()
67
43
68
44
def request_delete (self ):
69
45
self .delete_signal .emit (self )
70
46
71
47
def init_buttons (self ):
72
- self .conf_btn .setIcon (QIcon (plugin_path ("resources" , "icons" , "settings.svg" )))
73
48
self .del_btn .setIcon (QgsApplication .getThemeIcon ("mActionDeleteSelected.svg" ))
74
49
self .del_btn .clicked .connect (self .request_delete )
75
50
76
- def create_widgets_for_plan_regulation (self , plan_regulation_feature : Feature ):
77
- row = self .plan_regulation_grid_layout .rowCount () + 1
78
- for plan_regulation_config in plan_regulation_feature .attributes :
79
- if plan_regulation_config .attribute == "type_of_plan_regulation_id" :
80
- id_label = QLabel (plan_regulation_config .display ())
81
- # print(plan_regulation_config)
82
- self .plan_regulation_grid_layout .addWidget (id_label , row , 0 )
83
- elif plan_regulation_config .attribute == "numeric_default" :
84
- if not self .input_value_header :
85
- self .input_value_header = QLabel ("Arvo" )
86
- self .input_value_header .setFont (self .bold_font )
87
- self .input_value_col = self .plan_regulation_grid_layout .columnCount () + 1
88
- self .plan_regulation_grid_layout .addWidget (self .input_value_header , 0 , self .input_value_col )
89
-
90
- input_field = QLineEdit ()
91
- self .plan_regulation_grid_layout .addWidget (input_field , row , self .input_value_col )
92
-
93
- if plan_regulation_feature .child_features is None :
94
- return
95
- for child in plan_regulation_feature .child_features :
96
- # Additional information here, what else?
97
- # Assume attribute is "additional_information_of_plan_regulation"
98
- # NOTE: Could additional information be attribute of plan regulation instead of child feature?
99
-
100
- # Add header if not added yet
101
- if not self .additional_information_header :
102
- self .additional_information_header = QLabel ("Lisätiedot" )
103
- self .additional_information_header .setFont (self .bold_font )
104
- self .additonal_information_col = self .plan_regulation_grid_layout .columnCount () + 1
105
- self .plan_regulation_grid_layout .addWidget (
106
- self .additional_information_header , 0 , self .additonal_information_col
107
- )
108
-
109
- # TBD: Multiple additional feature per plan regulation
110
- for attribute in child .attributes :
111
- # Assume "type_of_additional_information_id"
112
- additional_information_label = QLabel (attribute .display ())
113
- self .plan_regulation_grid_layout .addWidget (
114
- additional_information_label , row , self .additonal_information_col
115
- )
51
+ def set_group_heading (self ):
52
+ for attribute_config in self .feature .attributes :
53
+ if attribute_config .attribute == "name" :
54
+ self .heading .setText (attribute_config .display ())
55
+
56
+ def add_plan_regulation_widgets (self ):
57
+ if self .feature .child_features is not None :
58
+ for child in self .feature .child_features :
59
+ if child .layer == "plan_requlation" :
60
+ self .add_plan_regulation_widget (child )
61
+
62
+ def add_plan_regulation_widget (self , plan_regulation_feature : Feature ):
63
+ plan_regulation_widget = PlanRegulationWidget (plan_regulation_feature )
64
+ self .frame .layout ().addWidget (plan_regulation_widget )
0 commit comments