Refactoring Aufgrund Fehler beim Beenden.
This commit is contained in:
40
logic/settings_logic.py
Normal file
40
logic/settings_logic.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from qgis.core import QgsProject, QgsExpressionContextUtils
|
||||
|
||||
|
||||
class SettingsLogic:
|
||||
def __init__(self):
|
||||
self.project = QgsProject.instance()
|
||||
|
||||
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"])
|
||||
|
||||
# 🟨 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"])
|
||||
|
||||
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 "",
|
||||
|
||||
# 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 ""
|
||||
}
|
||||
Reference in New Issue
Block a user