- Landkreis-Feld in den Projekteigenschaften als Dropdown statt Freitext, Landkreiskennzahl zusätzlich als eigene Projektvariable verfügbar. - ask_bror_kombination(en) auf echte Mehrfachauswahl umgestellt, inkl. Titel, Wappen-Icon, kompakter/anpassbarer Größe und Scrollbar-Fix. - Neuer Dialog ask_landkreis_objekte für die landkreisweite Objektsuche (Mehrfachauswahl, "Alle auswählen", "Nur laden ohne weiteren Ablauf"). - qt_wrapper um QDialog/QDialogButtonBox/QListWidget/QListWidgetItem/ QAbstractItemView/QIcon sowie QComboBox-userData/currentData erweitert.
158 lines
5.3 KiB
Python
158 lines
5.3 KiB
Python
"""
|
||
sn_basis/ui/tabs/settings_tab.py – Einstellungen-Tab für Projektinformationen.
|
||
Verwaltet benutzerspezifische und projektspezifische Einstellungen.
|
||
"""
|
||
|
||
from sn_basis.functions.qt_wrapper import (
|
||
QWidget,
|
||
QGridLayout,
|
||
QLabel,
|
||
QLineEdit,
|
||
QComboBox,
|
||
QGroupBox,
|
||
QVBoxLayout,
|
||
QPushButton,
|
||
)
|
||
from sn_basis.functions.settings_logic import SettingsLogic
|
||
from sn_basis.functions.landkreise import LANDKREISE
|
||
|
||
#: Feldschlüssel, die als Landkreis-Dropdown (statt Freitext) dargestellt werden.
|
||
_LANDKREIS_DROPDOWN_FELDER = {"landkreis_user"}
|
||
|
||
|
||
class SettingsTab(QWidget):
|
||
"""
|
||
Tab-Widget für die Verwaltung von Projekt- und Benutzereinstellungen.
|
||
|
||
Attributes:
|
||
tab_title: Anzeigetitel des Tabs ("Projekteigenschaften")
|
||
logic: SettingsLogic-Instanz für persistente Einstellungen
|
||
"""
|
||
|
||
tab_title = "Projekteigenschaften"
|
||
|
||
def __init__(self, parent=None):
|
||
"""
|
||
Initialisiert den Settings-Tab mit Eingabefeldern.
|
||
|
||
Args:
|
||
parent: Übergeordnetes Widget (Standard: None)
|
||
"""
|
||
super().__init__(parent)
|
||
self.logic = SettingsLogic()
|
||
|
||
main_layout = QVBoxLayout()
|
||
|
||
# -----------------------------
|
||
# Definition der Felder
|
||
# -----------------------------
|
||
self.user_fields = {
|
||
"amt": "Amt:",
|
||
"behoerde": "Behörde:",
|
||
"landkreis_user": "Landkreis:",
|
||
"sachgebiet": "Sachgebiet:",
|
||
}
|
||
|
||
self.project_fields = {
|
||
"bezeichnung": "Bezeichnung:",
|
||
"name": "Name:",
|
||
"verfahrensnummer": "Verfahrensnummer:",
|
||
"gemeinden": "Gemeinde(n):",
|
||
"landkreise_proj": "Landkreis(e):",
|
||
}
|
||
|
||
# -----------------------------
|
||
# Benutzerspezifische Festlegungen
|
||
# -----------------------------
|
||
user_group = QGroupBox("Benutzerspezifische Festlegungen")
|
||
user_layout = QGridLayout()
|
||
self.user_inputs = {}
|
||
|
||
for row, (key, label) in enumerate(self.user_fields.items()):
|
||
input_widget = self._build_input(key)
|
||
self.user_inputs[key] = input_widget
|
||
|
||
user_layout.addWidget(QLabel(label), row, 0)
|
||
user_layout.addWidget(input_widget, row, 1)
|
||
|
||
user_group.setLayout(user_layout)
|
||
|
||
# -----------------------------
|
||
# Projektspezifische Festlegungen
|
||
# -----------------------------
|
||
project_group = QGroupBox("Projektspezifische Festlegungen")
|
||
project_layout = QGridLayout()
|
||
self.project_inputs = {}
|
||
|
||
for row, (key, label) in enumerate(self.project_fields.items()):
|
||
input_widget = self._build_input(key)
|
||
self.project_inputs[key] = input_widget
|
||
|
||
project_layout.addWidget(QLabel(label), row, 0)
|
||
project_layout.addWidget(input_widget, row, 1)
|
||
|
||
project_group.setLayout(project_layout)
|
||
|
||
# -----------------------------
|
||
# Speichern-Button
|
||
# -----------------------------
|
||
save_button = QPushButton("Speichern")
|
||
save_button.clicked.connect(self.save_data)
|
||
|
||
# -----------------------------
|
||
# Layout zusammenfügen
|
||
# -----------------------------
|
||
main_layout.addWidget(user_group)
|
||
main_layout.addWidget(project_group)
|
||
main_layout.addStretch()
|
||
main_layout.addWidget(save_button)
|
||
|
||
self.setLayout(main_layout)
|
||
|
||
# Daten laden
|
||
self.load_data()
|
||
|
||
# ---------------------------------------------------------
|
||
# Eingabewidget je Feld erzeugen
|
||
# ---------------------------------------------------------
|
||
def _build_input(self, key: str):
|
||
if key in _LANDKREIS_DROPDOWN_FELDER:
|
||
combo = QComboBox()
|
||
combo.addItem("", None) # Platzhalter: keine Vorbelegung bei leerem Projekt
|
||
for kennzahl, name in LANDKREISE:
|
||
combo.addItem(name, kennzahl)
|
||
return combo
|
||
return QLineEdit()
|
||
|
||
# ---------------------------------------------------------
|
||
# Speichern
|
||
# ---------------------------------------------------------
|
||
def save_data(self):
|
||
fields = {}
|
||
for key, widget in {**self.user_inputs, **self.project_inputs}.items():
|
||
if isinstance(widget, QComboBox):
|
||
fields[key] = widget.currentText()
|
||
else:
|
||
fields[key] = widget.text()
|
||
|
||
# Landkreiskennzahl aus der Dropdown-Auswahl zusätzlich als eigene
|
||
# Variable bereitstellen (siehe landkreise.py).
|
||
landkreis_widget = self.user_inputs.get("landkreis_user")
|
||
if isinstance(landkreis_widget, QComboBox):
|
||
fields["landkreis_kennzahl"] = landkreis_widget.currentData() or ""
|
||
|
||
self.logic.save(fields)
|
||
|
||
# ---------------------------------------------------------
|
||
# Laden
|
||
# ---------------------------------------------------------
|
||
def load_data(self):
|
||
data = self.logic.load()
|
||
for key, widget in {**self.user_inputs, **self.project_inputs}.items():
|
||
if isinstance(widget, QComboBox):
|
||
gespeicherter_name = data.get(key, "")
|
||
index = widget.findText(gespeicherter_name)
|
||
widget.setCurrentIndex(index if index >= 0 else 0)
|
||
else:
|
||
widget.setText(data.get(key, ""))
|