mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Do not draw empty property rows.
This commit is contained in:
parent
26a71f4f0e
commit
2a8f34ea25
@ -1,3 +1,4 @@
|
||||
import itertools
|
||||
import logging
|
||||
from typing import Callable, Optional
|
||||
|
||||
@ -28,7 +29,9 @@ class PropertyEditor(QGridLayout):
|
||||
|
||||
def build_props(self, flight):
|
||||
self.setGeometry(QRect())
|
||||
for row, prop in enumerate(flight.unit_type.iter_props()):
|
||||
last_label: QWidget | None = None
|
||||
row = itertools.count()
|
||||
for prop in flight.unit_type.iter_props():
|
||||
if prop.label is None:
|
||||
if prop.control != "label":
|
||||
logging.error(
|
||||
@ -49,15 +52,26 @@ class PropertyEditor(QGridLayout):
|
||||
)
|
||||
continue
|
||||
|
||||
# Draw any deferred label if this is a real control.
|
||||
if last_label is not None and widget is not None:
|
||||
self.addWidget(last_label, next(row), 0)
|
||||
last_label = None
|
||||
|
||||
label = prop.label
|
||||
if widget is None:
|
||||
label = f"<strong>{label}</label>"
|
||||
self.addWidget(QLabel(label), row, 0)
|
||||
|
||||
# If prop.control is "label", widget will be None. We only need to add the
|
||||
# label, not the control.
|
||||
if widget is not None:
|
||||
self.addWidget(widget, row, 1)
|
||||
label = QLabel(label)
|
||||
if widget is None:
|
||||
# The "control" is only a section label. Defer adding it to the layout
|
||||
# so that we can skip empty sections.
|
||||
last_label = label
|
||||
else:
|
||||
# Else the label is for the control itself and should be drawn
|
||||
# immediately.
|
||||
this_row = next(row)
|
||||
self.addWidget(label, this_row, 0)
|
||||
self.addWidget(widget, this_row, 1)
|
||||
|
||||
def control_for_property(self, prop: UnitPropertyDescription) -> Optional[QWidget]:
|
||||
# Valid values are:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user