2025-12-18 22:00:31 +01:00
|
|
|
|
"""
|
2025-12-19 14:29:52 +01:00
|
|
|
|
sn_basis/modules/stilpruefer.py – Prüfung von Layerstilen.
|
|
|
|
|
|
Prüft ausschließlich, ob ein Stilpfad gültig ist.
|
|
|
|
|
|
Die Anwendung erfolgt später über eine Aktion.
|
2025-12-18 22:00:31 +01:00
|
|
|
|
"""
|
|
|
|
|
|
|
2026-03-12 16:14:02 +01:00
|
|
|
|
import os
|
2025-12-18 22:00:31 +01:00
|
|
|
|
|
2026-03-12 16:14:02 +01:00
|
|
|
|
from sn_basis.functions.os_wrapper import is_absolute_path
|
|
|
|
|
|
from sn_basis.functions.sys_wrapper import get_plugin_root, file_exists, join_path
|
2025-12-18 22:00:31 +01:00
|
|
|
|
from sn_basis.modules.pruef_ergebnis import pruef_ergebnis
|
2025-12-02 20:55:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Stilpruefer:
|
|
|
|
|
|
"""
|
2025-12-19 14:29:52 +01:00
|
|
|
|
Prüft, ob ein Stilpfad gültig ist und angewendet werden kann.
|
|
|
|
|
|
Keine Seiteneffekte, keine QGIS-Aufrufe.
|
2025-12-02 20:55:51 +01:00
|
|
|
|
"""
|
|
|
|
|
|
|
2025-12-19 14:29:52 +01:00
|
|
|
|
def __init__(self):
|
|
|
|
|
|
pass
|
2025-12-18 22:00:31 +01:00
|
|
|
|
|
|
|
|
|
|
# ---------------------------------------------------------
|
|
|
|
|
|
# Hauptfunktion
|
|
|
|
|
|
# ---------------------------------------------------------
|
|
|
|
|
|
|
2025-12-19 14:29:52 +01:00
|
|
|
|
def pruefe(self, stil_pfad: str) -> pruef_ergebnis:
|
2025-12-18 22:00:31 +01:00
|
|
|
|
"""
|
2025-12-19 14:29:52 +01:00
|
|
|
|
Prüft einen Stilpfad.
|
2025-12-18 22:00:31 +01:00
|
|
|
|
Rückgabe: pruef_ergebnis
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
2025-12-19 14:29:52 +01:00
|
|
|
|
# -----------------------------------------------------
|
|
|
|
|
|
# 1. Kein Stil angegeben → OK
|
|
|
|
|
|
# -----------------------------------------------------
|
|
|
|
|
|
if not stil_pfad:
|
2025-12-18 22:00:31 +01:00
|
|
|
|
return pruef_ergebnis(
|
|
|
|
|
|
ok=True,
|
2025-12-19 14:29:52 +01:00
|
|
|
|
meldung="Kein Stil angegeben.",
|
2025-12-18 22:00:31 +01:00
|
|
|
|
aktion="ok",
|
2025-12-19 14:29:52 +01:00
|
|
|
|
kontext=None,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2026-03-12 16:14:02 +01:00
|
|
|
|
pfad = str(stil_pfad)
|
|
|
|
|
|
|
|
|
|
|
|
if not is_absolute_path(pfad):
|
|
|
|
|
|
plugin_root = get_plugin_root()
|
|
|
|
|
|
pfad = str(join_path(plugin_root, "sn_plan41", "assets", pfad))
|
2025-12-19 14:29:52 +01:00
|
|
|
|
|
|
|
|
|
|
# -----------------------------------------------------
|
|
|
|
|
|
# 2. Datei existiert nicht
|
|
|
|
|
|
# -----------------------------------------------------
|
|
|
|
|
|
if not file_exists(pfad):
|
|
|
|
|
|
return pruef_ergebnis(
|
|
|
|
|
|
ok=False,
|
|
|
|
|
|
meldung=f"Die Stil-Datei '{stil_pfad}' wurde nicht gefunden.",
|
|
|
|
|
|
aktion="datei_nicht_gefunden",
|
|
|
|
|
|
kontext=pfad,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# -----------------------------------------------------
|
|
|
|
|
|
# 3. Falsche Endung
|
|
|
|
|
|
# -----------------------------------------------------
|
2026-03-12 16:14:02 +01:00
|
|
|
|
if os.path.splitext(pfad)[1].lower() != ".qml":
|
2025-12-19 14:29:52 +01:00
|
|
|
|
return pruef_ergebnis(
|
|
|
|
|
|
ok=False,
|
|
|
|
|
|
meldung="Die Stil-Datei muss die Endung '.qml' haben.",
|
|
|
|
|
|
aktion="falsche_endung",
|
|
|
|
|
|
kontext=pfad,
|
2025-12-02 20:55:51 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2025-12-19 14:29:52 +01:00
|
|
|
|
# -----------------------------------------------------
|
|
|
|
|
|
# 4. Stil ist gültig → Anwendung später
|
|
|
|
|
|
# -----------------------------------------------------
|
2025-12-18 22:00:31 +01:00
|
|
|
|
return pruef_ergebnis(
|
2025-12-19 14:29:52 +01:00
|
|
|
|
ok=True,
|
|
|
|
|
|
meldung="Stil-Datei ist gültig.",
|
|
|
|
|
|
aktion="stil_anwendbar",
|
|
|
|
|
|
kontext=pfad,
|
2025-12-02 20:55:51 +01:00
|
|
|
|
)
|