forked from AG_QGIS/Plugin_SN_Basis
Imports für sn_Verfahrensgebiet ergänzt, Stilprüfer wird jetzt auch für apply_style verwendet
This commit is contained in:
@@ -1,23 +1,44 @@
|
||||
# sn_basis/functions/ly_style_wrapper.py
|
||||
|
||||
from sn_basis.functions.ly_existence_wrapper import layer_exists
|
||||
from sn_basis.functions.sys_wrapper import (
|
||||
get_plugin_root,
|
||||
join_path,
|
||||
file_exists,
|
||||
)
|
||||
|
||||
from sn_basis.functions.sys_wrapper import get_plugin_root, join_path
|
||||
from sn_basis.modules.stilpruefer import Stilpruefer
|
||||
from typing import Optional
|
||||
|
||||
def apply_style(layer, style_name: str) -> bool:
|
||||
"""
|
||||
Wendet einen Layerstil an, sofern er gültig ist.
|
||||
|
||||
- Validierung erfolgt ausschließlich über Stilpruefer
|
||||
- Keine eigenen Dateisystem- oder Endungsprüfungen
|
||||
- Keine Seiteneffekte bei ungültigem Stil
|
||||
"""
|
||||
print(">>> apply_style() START")
|
||||
|
||||
if not layer_exists(layer):
|
||||
return False
|
||||
|
||||
style_path = join_path(get_plugin_root(), "styles", style_name)
|
||||
if not file_exists(style_path):
|
||||
# Stilpfad zusammensetzen
|
||||
style_path = join_path(get_plugin_root(), "sn_verfahrensgebiet","styles", style_name)
|
||||
|
||||
# Stil prüfen
|
||||
pruefer = Stilpruefer()
|
||||
ergebnis = pruefer.pruefe(style_path)
|
||||
print(">>> Stilprüfung:", ergebnis)
|
||||
|
||||
print(
|
||||
f"[Stilprüfung] ok={ergebnis.ok} | "
|
||||
f"aktion={ergebnis.aktion} | "
|
||||
f"meldung={ergebnis.meldung}"
|
||||
)
|
||||
|
||||
|
||||
if not ergebnis.ok:
|
||||
return False
|
||||
|
||||
# Stil anwenden
|
||||
try:
|
||||
ok, _ = layer.loadNamedStyle(style_path)
|
||||
ok, _ = layer.loadNamedStyle(str(ergebnis.kontext))
|
||||
if ok:
|
||||
getattr(layer, "triggerRepaint", lambda: None)()
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user