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

View File

@ -398,8 +398,11 @@ class AirWingModel(QAbstractListModel):
return squadron.name return squadron.name
@staticmethod @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.""" """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 return None
def squadron_at_index(self, index: QModelIndex) -> Squadron: def squadron_at_index(self, index: QModelIndex) -> Squadron:

View File

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