Show aircraft type in the squadron list.

https://github.com/dcs-liberation/dcs_liberation/issues/276
This commit is contained in:
Dan Albert 2021-05-26 17:20:29 -07:00
parent 2f8656d54f
commit 57a2457050
3 changed files with 18 additions and 4 deletions

View File

@ -38,6 +38,7 @@ class Pilot:
class Squadron:
name: str
nickname: str
country: str
role: str
aircraft: Type[FlyingType]
mission_types: Tuple[FlightType, ...]
@ -104,6 +105,7 @@ class Squadron:
return Squadron(
name=data["name"],
nickname=data["nickname"],
country=game.country_for(player),
role=data["role"],
aircraft=unit_type,
mission_types=tuple(FlightType.from_name(n) for n in data["mission_types"]),
@ -127,6 +129,7 @@ class AirWing:
Squadron(
name=f"Squadron {num + 1:03}",
nickname=self.random_nickname(),
country=game.country_for(player),
role="Flying Squadron",
aircraft=aircraft,
mission_types=tuple(FlightType),

View File

@ -398,8 +398,11 @@ class AirWingModel(QAbstractListModel):
return squadron.name
@staticmethod
def icon_for_squadron(_squadron: Squadron) -> Optional[QIcon]:
def icon_for_squadron(squadron: Squadron) -> Optional[QIcon]:
"""Returns the icon that should be displayed for the squadron."""
name = db.unit_type_name(squadron.aircraft)
if name in AIRCRAFT_ICONS:
return QIcon(AIRCRAFT_ICONS[name])
return None
def squadron_at_index(self, index: QModelIndex) -> Squadron:

View File

@ -4,6 +4,7 @@ from PySide2.QtCore import (
QItemSelectionModel,
QModelIndex,
Qt,
QSize,
)
from PySide2.QtWidgets import (
QAbstractItemView,
@ -12,6 +13,7 @@ from PySide2.QtWidgets import (
QVBoxLayout,
)
from game import db
from game.squadrons import Squadron
from qt_ui.delegates import TwoColumnRowDelegate
from qt_ui.models import GameModel, AirWingModel, SquadronModel
@ -20,7 +22,7 @@ from qt_ui.windows.SquadronDialog import SquadronDialog
class SquadronDelegate(TwoColumnRowDelegate):
def __init__(self, air_wing_model: AirWingModel) -> None:
super().__init__(rows=2, columns=1, font_size=12)
super().__init__(rows=2, columns=2, font_size=12)
self.air_wing_model = air_wing_model
@staticmethod
@ -28,9 +30,14 @@ class SquadronDelegate(TwoColumnRowDelegate):
return index.data(AirWingModel.SquadronRole)
def text_for(self, index: QModelIndex, row: int, column: int) -> str:
if row == 0:
if (row, column) == (0, 0):
return self.air_wing_model.data(index, Qt.DisplayRole)
elif row == 1:
elif (row, column) == (0, 1):
squadron = self.air_wing_model.data(index, AirWingModel.SquadronRole)
return db.unit_get_expanded_info(
squadron.country, squadron.aircraft, "name"
)
elif (row, column) == (1, 0):
return self.squadron(index).nickname
return ""
@ -43,6 +50,7 @@ class SquadronList(QListView):
self.air_wing_model = air_wing_model
self.dialog: Optional[SquadronDialog] = None
self.setIconSize(QSize(91, 24))
self.setItemDelegate(SquadronDelegate(self.air_wing_model))
self.setModel(self.air_wing_model)
self.selectionModel().setCurrentIndex(