Aufgeräumt und Widget fixiert.
This commit is contained in:
@@ -1,40 +1,37 @@
|
||||
from qgis.core import QgsProject, QgsExpressionContextUtils
|
||||
|
||||
|
||||
class SettingsLogic:
|
||||
def __init__(self):
|
||||
self.project = QgsProject.instance()
|
||||
|
||||
# Definition der Variablen-Namen
|
||||
self.global_vars = ["amt", "behoerde", "landkreis_user", "sachgebiet"]
|
||||
self.project_vars = ["bezeichnung", "verfahrensnummer", "gemeinden", "landkreise_proj"]
|
||||
|
||||
def save(self, fields: dict):
|
||||
"""Speichert Felder als globale und projektbezogene Ausdrucksvariablen."""
|
||||
|
||||
# 🟦 Globale Ausdrucksvariablen (nutzerspezifisch, Sitzungsspeicher)
|
||||
QgsExpressionContextUtils.setGlobalVariable("sn_amt", fields["amt"])
|
||||
QgsExpressionContextUtils.setGlobalVariable("sn_behoerde", fields["behoerde"])
|
||||
QgsExpressionContextUtils.setGlobalVariable("sn_landkreis_user", fields["landkreis_user"])
|
||||
QgsExpressionContextUtils.setGlobalVariable("sn_sachgebiet", fields["sachgebiet"])
|
||||
# Globale Variablen
|
||||
for key in self.global_vars:
|
||||
QgsExpressionContextUtils.setGlobalVariable(f"sn_{key}", fields.get(key, ""))
|
||||
|
||||
# 🟨 Projektvariablen (sichtbar in Projekt → Eigenschaften → Variablen)
|
||||
QgsExpressionContextUtils.setProjectVariable(self.project, "sn_bezeichnung", fields["bezeichnung"])
|
||||
QgsExpressionContextUtils.setProjectVariable(self.project, "sn_verfahrensnummer", fields["verfahrensnummer"])
|
||||
QgsExpressionContextUtils.setProjectVariable(self.project, "sn_gemeinden", fields["gemeinden"])
|
||||
QgsExpressionContextUtils.setProjectVariable(self.project, "sn_landkreise_proj", fields["landkreise_proj"])
|
||||
# Projektvariablen
|
||||
for key in self.project_vars:
|
||||
QgsExpressionContextUtils.setProjectVariable(self.project, f"sn_{key}", fields.get(key, ""))
|
||||
|
||||
print("✅ Ausdrucksvariablen gespeichert.")
|
||||
|
||||
def load(self) -> dict:
|
||||
"""Lädt Werte ausschließlich aus Ausdrucksvariablen (global + projektbezogen)."""
|
||||
|
||||
return {
|
||||
# Globale Variablen (nutzerspezifisch)
|
||||
"amt": QgsExpressionContextUtils.globalScope().variable("sn_amt") or "",
|
||||
"behoerde": QgsExpressionContextUtils.globalScope().variable("sn_behoerde") or "",
|
||||
"landkreis_user": QgsExpressionContextUtils.globalScope().variable("sn_landkreis_user") or "",
|
||||
"sachgebiet": QgsExpressionContextUtils.globalScope().variable("sn_sachgebiet") or "",
|
||||
data = {}
|
||||
|
||||
# Globale Variablen
|
||||
for key in self.global_vars:
|
||||
data[key] = QgsExpressionContextUtils.globalScope().variable(f"sn_{key}") or ""
|
||||
|
||||
# Projektvariablen
|
||||
"bezeichnung": QgsExpressionContextUtils.projectScope(self.project).variable("sn_bezeichnung") or "",
|
||||
"verfahrensnummer": QgsExpressionContextUtils.projectScope(self.project).variable("sn_verfahrensnummer") or "",
|
||||
"gemeinden": QgsExpressionContextUtils.projectScope(self.project).variable("sn_gemeinden") or "",
|
||||
"landkreise_proj": QgsExpressionContextUtils.projectScope(self.project).variable("sn_landkreise_proj") or ""
|
||||
}
|
||||
for key in self.project_vars:
|
||||
data[key] = QgsExpressionContextUtils.projectScope(self.project).variable(f"sn_{key}") or ""
|
||||
|
||||
return data
|
||||
|
||||
10
main.py
10
main.py
@@ -1,21 +1,15 @@
|
||||
from qgis.PyQt.QtCore import QCoreApplication
|
||||
from qgis.PyQt.QtGui import QIcon
|
||||
from sn_basis.ui.navigation import Navigation
|
||||
from sn_basis.ui.dockmanager import DockManager
|
||||
|
||||
class BasisPlugin:
|
||||
def __init__(self, iface):
|
||||
self.iface = iface
|
||||
self.ui = None
|
||||
self.quitting = False
|
||||
QCoreApplication.instance().aboutToQuit.connect(self._on_quit)
|
||||
|
||||
def _on_quit(self):
|
||||
self.quitting = True
|
||||
QCoreApplication.instance().aboutToQuit.connect(self.unload)
|
||||
|
||||
def initGui(self):
|
||||
self.ui = Navigation(self.iface)
|
||||
|
||||
def unload(self):
|
||||
if not self.quitting and self.ui:
|
||||
if self.ui:
|
||||
self.ui.remove_all()
|
||||
|
||||
21
ui/base_dockwidget.py
Normal file
21
ui/base_dockwidget.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from qgis.PyQt.QtWidgets import QDockWidget, QTabWidget
|
||||
|
||||
class BaseDockWidget(QDockWidget):
|
||||
base_title = "LNO Sachsen"
|
||||
tabs = []
|
||||
|
||||
def __init__(self, parent=None, subtitle=""):
|
||||
super().__init__(parent)
|
||||
|
||||
# Titel zusammensetzen
|
||||
title = self.base_title if not subtitle else f"{self.base_title} | {subtitle}"
|
||||
self.setWindowTitle(title)
|
||||
|
||||
# Dock fixieren (Nur schließen erlaubt)
|
||||
self.setFeatures(QDockWidget.DockWidgetFeature.DockWidgetClosable)
|
||||
|
||||
|
||||
tab_widget = QTabWidget()
|
||||
for tab_class in self.tabs:
|
||||
tab_widget.addTab(tab_class(), getattr(tab_class, "tab_title", tab_class.__name__))
|
||||
self.setWidget(tab_widget)
|
||||
@@ -2,17 +2,17 @@ from qgis.PyQt.QtCore import Qt
|
||||
from qgis.PyQt.QtWidgets import QDockWidget
|
||||
from qgis.utils import iface
|
||||
|
||||
|
||||
class DockManager:
|
||||
default_area = Qt.DockWidgetArea.RightDockWidgetArea
|
||||
|
||||
@classmethod
|
||||
def show(cls, dock_widget, area=None):
|
||||
if area is None:
|
||||
area = cls.default_area
|
||||
area = area or cls.default_area
|
||||
|
||||
# Alle vorhandenen Plugin-Docks schließen
|
||||
# Bestehende Plugin-Docks mit Präfix schließen
|
||||
for widget in iface.mainWindow().findChildren(QDockWidget):
|
||||
if widget != dock_widget and widget.objectName().startswith("sn_dock_"):
|
||||
if widget is not dock_widget and widget.objectName().startswith("sn_dock_"):
|
||||
iface.removeDockWidget(widget)
|
||||
widget.deleteLater()
|
||||
|
||||
|
||||
@@ -13,25 +13,22 @@ class Navigation:
|
||||
iface.addToolBar(self.toolbar)
|
||||
|
||||
def add_action(self, text, callback, tooltip="", priority=100, icon=None):
|
||||
action = QAction(icon, text, self.iface.mainWindow()) if icon else QAction(text, self.iface.mainWindow())
|
||||
action = QAction(text, self.iface.mainWindow())
|
||||
if icon:
|
||||
action.setIcon(icon)
|
||||
if tooltip:
|
||||
action.setToolTip(tooltip)
|
||||
action.triggered.connect(callback)
|
||||
|
||||
# Action mit Priority speichern
|
||||
self.actions.append((priority, action))
|
||||
return action
|
||||
|
||||
def finalize_menu_and_toolbar(self):
|
||||
# Sortieren nach Priority
|
||||
self.actions.sort(key=lambda x: x[0])
|
||||
|
||||
# Menüeinträge
|
||||
# Menü und Toolbar leeren
|
||||
self.menu.clear()
|
||||
for _, action in self.actions:
|
||||
self.menu.addAction(action)
|
||||
|
||||
# Toolbar-Einträge
|
||||
self.toolbar.clear()
|
||||
for _, action in self.actions:
|
||||
|
||||
# Sortiert nach Priority einfügen
|
||||
for _, action in sorted(self.actions, key=lambda x: x[0]):
|
||||
self.menu.addAction(action)
|
||||
self.toolbar.addAction(action)
|
||||
|
||||
@@ -6,44 +6,46 @@ from sn_basis.logic.settings_logic import SettingsLogic
|
||||
|
||||
|
||||
class SettingsTab(QWidget):
|
||||
tab_title = "Projekteigenschaften" # Titel für den Tab
|
||||
|
||||
def __init__(self, parent=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:",
|
||||
"verfahrensnummer": "Verfahrensnummer:",
|
||||
"gemeinden": "Gemeinde(n):",
|
||||
"landkreise_proj": "Landkreis(e):"
|
||||
}
|
||||
|
||||
# 🟦 Benutzerspezifische Festlegungen
|
||||
user_group = QGroupBox("Benutzerspezifische Festlegungen")
|
||||
user_layout = QGridLayout()
|
||||
self.amt = QLineEdit()
|
||||
self.behoerde = QLineEdit()
|
||||
self.landkreis_user = QLineEdit()
|
||||
self.sachgebiet = QLineEdit()
|
||||
user_layout.addWidget(QLabel("Amt:"), 0, 0)
|
||||
user_layout.addWidget(self.amt, 0, 1)
|
||||
user_layout.addWidget(QLabel("Behörde:"), 1, 0)
|
||||
user_layout.addWidget(self.behoerde, 1, 1)
|
||||
user_layout.addWidget(QLabel("Landkreis:"), 2, 0)
|
||||
user_layout.addWidget(self.landkreis_user, 2, 1)
|
||||
user_layout.addWidget(QLabel("Sachgebiet:"), 3, 0)
|
||||
user_layout.addWidget(self.sachgebiet, 3, 1)
|
||||
self.user_inputs = {}
|
||||
for row, (key, label) in enumerate(self.user_fields.items()):
|
||||
self.user_inputs[key] = QLineEdit()
|
||||
user_layout.addWidget(QLabel(label), row, 0)
|
||||
user_layout.addWidget(self.user_inputs[key], row, 1)
|
||||
user_group.setLayout(user_layout)
|
||||
|
||||
# 🟨 Projektspezifische Festlegungen
|
||||
project_group = QGroupBox("Projektspezifische Festlegungen")
|
||||
project_layout = QGridLayout()
|
||||
self.bezeichnung = QLineEdit()
|
||||
self.verfahrensnummer = QLineEdit()
|
||||
self.gemeinden = QLineEdit()
|
||||
self.landkreise_proj = QLineEdit()
|
||||
project_layout.addWidget(QLabel("Bezeichnung:"), 0, 0)
|
||||
project_layout.addWidget(self.bezeichnung, 0, 1)
|
||||
project_layout.addWidget(QLabel("Verfahrensnummer:"), 1, 0)
|
||||
project_layout.addWidget(self.verfahrensnummer, 1, 1)
|
||||
project_layout.addWidget(QLabel("Gemeinde(n):"), 2, 0)
|
||||
project_layout.addWidget(self.gemeinden, 2, 1)
|
||||
project_layout.addWidget(QLabel("Landkreis(e):"), 3, 0)
|
||||
project_layout.addWidget(self.landkreise_proj, 3, 1)
|
||||
self.project_inputs = {}
|
||||
for row, (key, label) in enumerate(self.project_fields.items()):
|
||||
self.project_inputs[key] = QLineEdit()
|
||||
project_layout.addWidget(QLabel(label), row, 0)
|
||||
project_layout.addWidget(self.project_inputs[key], row, 1)
|
||||
project_group.setLayout(project_layout)
|
||||
|
||||
# 🟩 Speichern-Button
|
||||
@@ -60,25 +62,11 @@ class SettingsTab(QWidget):
|
||||
self.load_data()
|
||||
|
||||
def save_data(self):
|
||||
fields = {
|
||||
"amt": self.amt.text(),
|
||||
"behoerde": self.behoerde.text(),
|
||||
"landkreis_user": self.landkreis_user.text(),
|
||||
"sachgebiet": self.sachgebiet.text(),
|
||||
"bezeichnung": self.bezeichnung.text(),
|
||||
"verfahrensnummer": self.verfahrensnummer.text(),
|
||||
"gemeinden": self.gemeinden.text(),
|
||||
"landkreise_proj": self.landkreise_proj.text()
|
||||
}
|
||||
# Alle Felder zusammenführen
|
||||
fields = {key: widget.text() for key, widget in {**self.user_inputs, **self.project_inputs}.items()}
|
||||
self.logic.save(fields)
|
||||
|
||||
def load_data(self):
|
||||
data = self.logic.load()
|
||||
self.amt.setText(data["amt"])
|
||||
self.behoerde.setText(data["behoerde"])
|
||||
self.landkreis_user.setText(data["landkreis_user"])
|
||||
self.sachgebiet.setText(data["sachgebiet"])
|
||||
self.bezeichnung.setText(data["bezeichnung"])
|
||||
self.verfahrensnummer.setText(data["verfahrensnummer"])
|
||||
self.gemeinden.setText(data["gemeinden"])
|
||||
self.landkreise_proj.setText(data["landkreise_proj"])
|
||||
for key, widget in {**self.user_inputs, **self.project_inputs}.items():
|
||||
widget.setText(data.get(key, ""))
|
||||
|
||||
Reference in New Issue
Block a user