diff --git a/__init__.py b/__init__.py index 854d63e..9949070 100644 --- a/__init__.py +++ b/__init__.py @@ -1,3 +1,5 @@ +from .logic.variable_utils import get_variable + def classFactory(iface): from .main import BasisPlugin return BasisPlugin(iface) diff --git a/logic/variable_utils.py b/logic/variable_utils.py new file mode 100644 index 0000000..6ac4af9 --- /dev/null +++ b/logic/variable_utils.py @@ -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.") diff --git a/ui/navigation.py b/ui/navigation.py index e3bfa19..44a8895 100644 --- a/ui/navigation.py +++ b/ui/navigation.py @@ -10,6 +10,7 @@ class Navigation: iface.mainWindow().menuBar().addMenu(self.menu) self.toolbar = QToolBar("LNO Sachsen") + self.toolbar.setObjectName("LnoSachsenToolbar") iface.addToolBar(self.toolbar) # Gruppe für exklusive Auswahl (nur ein Plugin aktiv)