forked from AG_QGIS/Plugin_SN_Basis
Ablauf optimiert, Styles laden implementiert
This commit is contained in:
28
functions/styles.py
Normal file
28
functions/styles.py
Normal 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
|
||||
Reference in New Issue
Block a user