Skip to content

Commit f0ff134

Browse files
committed
improve template attribute form
1 parent 54ac1e0 commit f0ff134

File tree

2 files changed

+247
-277
lines changed

2 files changed

+247
-277
lines changed

arho_feature_template/gui/template_attribute_form.py

+19-23
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33
from importlib import resources
44
from typing import TYPE_CHECKING
55

6-
from qgis.core import QgsApplication, QgsFeature
76
from qgis.gui import QgsSpinBox
87
from qgis.PyQt import uic
98
from qgis.PyQt.QtWidgets import (
109
QDialog,
1110
QDialogButtonBox,
1211
QLineEdit,
13-
QPushButton,
1412
QScrollArea,
1513
QSizePolicy,
1614
QSpacerItem,
1715
QTreeWidget,
16+
QTreeWidgetItem,
1817
)
1918

2019
from arho_feature_template.gui.plan_regulation_group_widget import PlanRegulationGroupWidget
2120

2221
if TYPE_CHECKING:
22+
from qgis.core import QgsFeature
2323
from qgis.PyQt.QtWidgets import QWidget
2424

2525
from arho_feature_template.core.template_library_config import Feature, FeatureTemplate
@@ -39,65 +39,61 @@ def __init__(self, feature_template_config: FeatureTemplate):
3939
self.feature_name: QLineEdit
4040
self.feature_description: QLineEdit
4141
self.feature_underground: QLineEdit
42-
self.feature_vertical_boundaries: QLineEdit
4342
self.plan_regulation_group_scrollarea: QScrollArea
4443
self.plan_regulation_group_scrollarea_contents: QWidget
4544
self.plan_regulation_groups_tree: QTreeWidget
46-
self.add_plan_regulation_group_btn: QPushButton
4745
self.button_box: QDialogButtonBox
4846

4947
# SIGNALS
5048
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)
5250

5351
# INIT
5452
self.attribute_widgets = {
5553
"name": self.feature_name,
5654
"description": self.feature_description,
5755
"type_of_underground_id": self.feature_underground,
58-
# self.feature_vertical_boundaries
5956
}
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] = {}
6060
self.scroll_area_spacer = None
6161
self.available_plan_regulation_group_configs: list[Feature] = []
62-
self.add_plan_regulation_group_btn.setIcon(QgsApplication.getThemeIcon("mActionAdd.svg"))
6362

6463
self.setWindowTitle(feature_template_config.name)
6564
self.init_feature_attributes_from_template(feature_template_config)
6665
self.init_plan_regulation_groups_from_template(feature_template_config)
6766
self.init_plan_regulation_group_library()
6867

69-
def add_spacer(self):
68+
def _add_spacer(self):
7069
self.scroll_area_spacer = QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Expanding)
7170
self.plan_regulation_group_scrollarea_contents.layout().addItem(self.scroll_area_spacer)
7271

73-
def remove_spacer(self):
72+
def _remove_spacer(self):
7473
if self.scroll_area_spacer is not None:
7574
self.plan_regulation_group_scrollarea_contents.layout().removeItem(self.scroll_area_spacer)
7675
self.scroll_area_spacer = None
7776

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+
7886
def add_plan_regulation_group(self, feature_config: Feature):
7987
new_plan_regulation_group = PlanRegulationGroupWidget(feature_config)
8088
new_plan_regulation_group.delete_signal.connect(self.remove_plan_regulation_group)
81-
self.remove_spacer()
89+
self._remove_spacer()
8290
self.plan_regulation_group_scrollarea_contents.layout().addWidget(new_plan_regulation_group)
83-
self.add_spacer()
91+
self._add_spacer()
8492

8593
def remove_plan_regulation_group(self, plan_regulation_group_widget: PlanRegulationGroupWidget):
8694
self.plan_regulation_group_scrollarea_contents.layout().removeWidget(plan_regulation_group_widget)
8795
plan_regulation_group_widget.deleteLater()
8896

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-
10197
def init_plan_regulation_group_library(self):
10298
# Now plan regulation group tree widget/view is just static placeholder for demo
10399
pass

0 commit comments

Comments
 (0)