Vertikale Ausrichtung für Textfelder ergänzt; default: top

This commit is contained in:
2026-04-17 14:44:30 +02:00
parent 5564c06d5c
commit 4b842bf635
3 changed files with 35 additions and 4 deletions
+27 -2
View File
@@ -7,7 +7,7 @@ import importlib
import math
from typing import Any
from sn_basis.functions.qt_wrapper import QFont
from sn_basis.functions.qt_wrapper import QFont, Qt
from sn_basis.functions.qgiscore_wrapper import (
MAP_GRID_ANNOTATION_DISPLAY_HIDE_ALL,
MAP_GRID_ANNOTATION_DISPLAY_SHOW_X,
@@ -220,6 +220,7 @@ class PrintLayout:
html_mode: bool = False,
expression_enabled: bool = False,
object_name: str | None = None,
v_align: str = "top",
) -> Any:
if self._current_layout is None:
raise RuntimeError("Kein Layout aktiv. Bitte create_single_page_layout() aufrufen.")
@@ -235,6 +236,7 @@ class PrintLayout:
html_mode=html_mode,
expression_enabled=expression_enabled,
object_name=object_name,
v_align=v_align,
)
def _setup_layout_objects(
@@ -352,7 +354,9 @@ class PrintLayout:
("Aktenzeichen: ", 16.0, -3.0, 171.0, 4.0, "Format_1", "Aktenzeichen"),
]
for text, rx, ry, w, h, fmt, obj_name in labels:
for entry in labels:
text, rx, ry, w, h, fmt, obj_name = entry[:7]
v_align = entry[7] if len(entry) > 7 else "top"
x, y = _coords_rel_untere_rechte_ecke(rx, ry)
self.add_text_label(
text,
@@ -363,6 +367,7 @@ class PrintLayout:
text_format=fmt,
expression_enabled=True,
object_name=obj_name,
v_align=v_align,
)
def _create_label_item(
@@ -382,6 +387,7 @@ class PrintLayout:
html_mode: bool = False,
expression_enabled: bool = False,
object_name: str | None = None,
v_align: str = "top",
) -> Any:
template = self._OBJECT_TEMPLATES[template_name]
label = QgsLayoutItemLabel(layout)
@@ -424,6 +430,25 @@ class PrintLayout:
if callable(set_reference_point) and lower_left is not None:
set_reference_point(lower_left)
align_map = {
"top": "AlignTop",
"center": "AlignVCenter",
"bottom": "AlignBottom",
}
align_attr = align_map.get(str(v_align).lower(), "AlignTop")
align_qt = getattr(Qt, align_attr, None)
if align_qt is None:
alignment_flag = getattr(Qt, "AlignmentFlag", None)
if alignment_flag is not None:
align_qt = getattr(alignment_flag, align_attr, None)
set_v_align = getattr(label, "setVAlign", None)
if callable(set_v_align) and align_qt is not None:
try:
set_v_align(align_qt)
except Exception:
pass
template_width, template_height = template.get("size_mm", (0.0, 0.0))
label.attemptMove(QgsLayoutPoint(x_mm, y_mm, MM))
label.attemptResize(
+5 -2
View File
@@ -351,7 +351,7 @@ class PrintLayoutBaufreigabe(PrintLayout):
# Positionen werden bewusst als feste Werte gesetzt und bei Bedarf manuell angepasst.
labels = [
("Teilnehmergemeinschaft [%@sn_bezeichnung %] [%@sn_name %]", 14.0, -84.0, 74.0, 8.0, "Format_1", "Herausgeber"),
("Teilnehmergemeinschaft [%@sn_bezeichnung %] [%@sn_name %]", 14.0, -82.0, 74.0, 8.0, "Format_1", "Herausgeber","Bottom"),
("[% @sn_bezeichnung %]", 14.0, -75.0, 74.0, 4.0, "Format_1", "Bezeichnung_Flurbereinigung"),
("[% @sn_name %]", 14.0, -64.0, 74.0, 5.0, "Format_2", "Name_Flurbereinigung"),
("[% @sn_gemeinden %]", 14.0, -56.0, 74.0, 4.0, "Format_1", "Stadt_Gemeinde"),
@@ -370,7 +370,9 @@ class PrintLayoutBaufreigabe(PrintLayout):
]
for text, rx, ry, w, h, fmt, obj_name in labels:
for entry in labels:
text, rx, ry, w, h, fmt, obj_name = entry[:7]
v_align = entry[7] if len(entry) > 7 else "top"
x, y = _coords_rel_untere_rechte_ecke(rx, ry)
self.add_text_label(
text,
@@ -381,6 +383,7 @@ class PrintLayoutBaufreigabe(PrintLayout):
text_format=fmt,
expression_enabled=True,
object_name=obj_name,
v_align=v_align,
)
def _calc_atlas_margin_percent(self, map_width_mm: float, map_height_mm: float) -> float: