Ablauf optimiert, Styles laden implementiert

This commit is contained in:
Michael Otto
2025-11-18 16:10:40 +01:00
parent a12fdae45e
commit 4336a70cff
4 changed files with 388 additions and 0 deletions

28
functions/styles.py Normal file
View File

@@ -0,0 +1,28 @@
# sn_basis/functions/styles.py
import os
from qgis.core import QgsVectorLayer
def apply_style(layer: QgsVectorLayer, style_name: str) -> bool:
"""
Lädt einen QML-Style aus dem styles-Ordner des Plugins und wendet ihn auf den Layer an.
style_name: Dateiname ohne Pfad, z.B. 'verfahrensgebiet.qml'
Rückgabe: True bei Erfolg, False sonst
"""
if not layer or not layer.isValid():
return False
# Basis-Pfad: sn_basis/styles
base_dir = os.path.dirname(os.path.dirname(__file__)) # geht von functions/ eins hoch
style_path = os.path.join(base_dir, "styles", style_name)
if not os.path.exists(style_path):
print(f"Style-Datei nicht gefunden: {style_path}")
return False
ok, error_msg = layer.loadNamedStyle(style_path)
if not ok:
print(f"Style konnte nicht geladen werden: {error_msg}")
return False
layer.triggerRepaint()
return True