forked from AG_QGIS/Plugin_SN_Basis
Laden und Speichern der Variablen
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
from .logic.variable_utils import get_variable
|
||||||
|
|
||||||
def classFactory(iface):
|
def classFactory(iface):
|
||||||
from .main import BasisPlugin
|
from .main import BasisPlugin
|
||||||
return BasisPlugin(iface)
|
return BasisPlugin(iface)
|
||||||
|
|||||||
35
logic/variable_utils.py
Normal file
35
logic/variable_utils.py
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
from qgis.core import QgsProject, QgsExpressionContextUtils
|
||||||
|
|
||||||
|
def get_variable(key: str, scope: str = "project") -> str:
|
||||||
|
"""
|
||||||
|
Liefert den Wert einer sn_* Variable zurück.
|
||||||
|
key: Name ohne Präfix, z.B. "verfahrensnummer"
|
||||||
|
scope: 'project' oder 'global'
|
||||||
|
"""
|
||||||
|
projekt = QgsProject.instance()
|
||||||
|
var_name = f"sn_{key}"
|
||||||
|
|
||||||
|
if scope == "project":
|
||||||
|
return QgsExpressionContextUtils.projectScope(projekt).variable(var_name) or ""
|
||||||
|
elif scope == "global":
|
||||||
|
return QgsExpressionContextUtils.globalScope().variable(var_name) or ""
|
||||||
|
else:
|
||||||
|
raise ValueError("Scope muss 'project' oder 'global' sein.")
|
||||||
|
|
||||||
|
|
||||||
|
def set_variable(key: str, value: str, scope: str = "project"):
|
||||||
|
"""
|
||||||
|
Schreibt den Wert einer sn_* Variable.
|
||||||
|
key: Name ohne Präfix, z.B. "verfahrensnummer"
|
||||||
|
value: Wert, der gespeichert werden soll
|
||||||
|
scope: 'project' oder 'global'
|
||||||
|
"""
|
||||||
|
projekt = QgsProject.instance()
|
||||||
|
var_name = f"sn_{key}"
|
||||||
|
|
||||||
|
if scope == "project":
|
||||||
|
QgsExpressionContextUtils.setProjectVariable(projekt, var_name, value)
|
||||||
|
elif scope == "global":
|
||||||
|
QgsExpressionContextUtils.setGlobalVariable(var_name, value)
|
||||||
|
else:
|
||||||
|
raise ValueError("Scope muss 'project' oder 'global' sein.")
|
||||||
@@ -10,6 +10,7 @@ class Navigation:
|
|||||||
iface.mainWindow().menuBar().addMenu(self.menu)
|
iface.mainWindow().menuBar().addMenu(self.menu)
|
||||||
|
|
||||||
self.toolbar = QToolBar("LNO Sachsen")
|
self.toolbar = QToolBar("LNO Sachsen")
|
||||||
|
self.toolbar.setObjectName("LnoSachsenToolbar")
|
||||||
iface.addToolBar(self.toolbar)
|
iface.addToolBar(self.toolbar)
|
||||||
|
|
||||||
# Gruppe für exklusive Auswahl (nur ein Plugin aktiv)
|
# Gruppe für exklusive Auswahl (nur ein Plugin aktiv)
|
||||||
|
|||||||
Reference in New Issue
Block a user