Funktionen von ligic nach functions verschoben
This commit is contained in:
37
functions/settings_logic.py
Normal file
37
functions/settings_logic.py
Normal file
@@ -0,0 +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 Variablen
|
||||
for key in self.global_vars:
|
||||
QgsExpressionContextUtils.setGlobalVariable(f"sn_{key}", fields.get(key, ""))
|
||||
|
||||
# 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)."""
|
||||
|
||||
data = {}
|
||||
|
||||
# Globale Variablen
|
||||
for key in self.global_vars:
|
||||
data[key] = QgsExpressionContextUtils.globalScope().variable(f"sn_{key}") or ""
|
||||
|
||||
# Projektvariablen
|
||||
for key in self.project_vars:
|
||||
data[key] = QgsExpressionContextUtils.projectScope(self.project).variable(f"sn_{key}") or ""
|
||||
|
||||
return data
|
||||
Reference in New Issue
Block a user