Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Muokkauksia kaavakohdetemplaattien lomakkeeseen #68

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 19 additions & 23 deletions arho_feature_template/gui/template_attribute_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
from importlib import resources
from typing import TYPE_CHECKING

from qgis.core import QgsApplication, QgsFeature
from qgis.gui import QgsSpinBox
from qgis.PyQt import uic
from qgis.PyQt.QtWidgets import (
QDialog,
QDialogButtonBox,
QLineEdit,
QPushButton,
QScrollArea,
QSizePolicy,
QSpacerItem,
QTreeWidget,
QTreeWidgetItem,
)

from arho_feature_template.gui.plan_regulation_group_widget import PlanRegulationGroupWidget

if TYPE_CHECKING:
from qgis.core import QgsFeature
from qgis.PyQt.QtWidgets import QWidget

from arho_feature_template.core.template_library_config import Feature, FeatureTemplate
Expand All @@ -39,65 +39,61 @@ def __init__(self, feature_template_config: FeatureTemplate):
self.feature_name: QLineEdit
self.feature_description: QLineEdit
self.feature_underground: QLineEdit
self.feature_vertical_boundaries: QLineEdit
self.plan_regulation_group_scrollarea: QScrollArea
self.plan_regulation_group_scrollarea_contents: QWidget
self.plan_regulation_groups_tree: QTreeWidget
self.add_plan_regulation_group_btn: QPushButton
self.button_box: QDialogButtonBox

# SIGNALS
self.button_box.accepted.connect(self._on_ok_clicked)
self.add_plan_regulation_group_btn.clicked.connect(self._on_add_plan_regulation_group_clicked)
self.plan_regulation_groups_tree.itemDoubleClicked.connect(self.add_selected_plan_regulation_group)

# INIT
self.attribute_widgets = {
"name": self.feature_name,
"description": self.feature_description,
"type_of_underground_id": self.feature_underground,
# self.feature_vertical_boundaries
}
# TODO: The 'configs' could be a mapping where keys are plan regulation group names and
# values are the related configurations
self.configs: dict[str, Feature] = {}
self.scroll_area_spacer = None
self.available_plan_regulation_group_configs: list[Feature] = []
self.add_plan_regulation_group_btn.setIcon(QgsApplication.getThemeIcon("mActionAdd.svg"))

self.setWindowTitle(feature_template_config.name)
self.init_feature_attributes_from_template(feature_template_config)
self.init_plan_regulation_groups_from_template(feature_template_config)
self.init_plan_regulation_group_library()

def add_spacer(self):
def _add_spacer(self):
self.scroll_area_spacer = QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Expanding)
self.plan_regulation_group_scrollarea_contents.layout().addItem(self.scroll_area_spacer)

def remove_spacer(self):
def _remove_spacer(self):
if self.scroll_area_spacer is not None:
self.plan_regulation_group_scrollarea_contents.layout().removeItem(self.scroll_area_spacer)
self.scroll_area_spacer = None

def add_selected_plan_regulation_group(self, item: QTreeWidgetItem, column: int):
if not item.parent():
return
config = self.configs.get(item.text(column))
if not config:
print(f"Could not find plan regulation group configuration for {item.text(column)}") # noqa: T201
return
self.add_plan_regulation_group(config)

def add_plan_regulation_group(self, feature_config: Feature):
new_plan_regulation_group = PlanRegulationGroupWidget(feature_config)
new_plan_regulation_group.delete_signal.connect(self.remove_plan_regulation_group)
self.remove_spacer()
self._remove_spacer()
self.plan_regulation_group_scrollarea_contents.layout().addWidget(new_plan_regulation_group)
self.add_spacer()
self._add_spacer()

def remove_plan_regulation_group(self, plan_regulation_group_widget: PlanRegulationGroupWidget):
self.plan_regulation_group_scrollarea_contents.layout().removeWidget(plan_regulation_group_widget)
plan_regulation_group_widget.deleteLater()

def _on_add_plan_regulation_group_clicked(self):
selected = self.plan_regulation_groups_tree.selectedItems()
if len(selected) == 0:
# Nothing selected
return
if len(selected) > 1:
# Too many selected, but should allow selecting only 1 item at a time
return
selected_plan_regulation_group = selected[0]
print(f"Trying to add plan regulation group {selected_plan_regulation_group.text(0)}") # noqa: T201
# self.add_plan_regulation_group() # TODO: Implement

def init_plan_regulation_group_library(self):
# Now plan regulation group tree widget/view is just static placeholder for demo
pass
Expand Down
Loading
Loading