Fix crash when changing squadrons in new flight.

This commit is contained in:
Dan Albert 2023-07-22 17:30:40 -07:00
parent e35e49e05e
commit d3269bca93
2 changed files with 10 additions and 6 deletions

View File

@ -144,7 +144,7 @@ class QFlightCreator(QDialog):
def reject(self) -> None:
super().reject()
# Clear the roster to return pilots to the pool.
self.roster_editor.replace(None)
self.roster_editor.replace(None, None)
def set_custom_name_text(self, text: str):
self.custom_name_text = text
@ -230,9 +230,9 @@ class QFlightCreator(QDialog):
def on_squadron_changed(self, index: int) -> None:
squadron: Optional[Squadron] = self.squadron_selector.itemData(index)
self.update_max_size(self.squadron_selector.aircraft_available)
# Clear the roster first so we return the pilots to the pool. This way if we end
# up repopulating from the same squadron we'll get the same pilots back.
self.roster_editor.replace(None)
# Clear the roster first so that we return the pilots to the pool. This way if
# we end up repopulating from the same squadron we'll get the same pilots back.
self.roster_editor.replace(None, None)
if squadron is not None:
self.roster_editor.replace(
squadron, FlightRoster(squadron, self.flight_size_spinner.value())

View File

@ -84,7 +84,9 @@ class PilotSelector(QComboBox):
self.roster.set_pilot(self.pilot_index, pilot)
self.available_pilots_changed.emit()
def replace(self, squadron: Squadron, new_roster: Optional[FlightRoster]) -> None:
def replace(
self, squadron: Squadron | None, new_roster: Optional[FlightRoster]
) -> None:
self.squadron = squadron
self.roster = new_roster
self.rebuild()
@ -199,7 +201,9 @@ class FlightRosterEditor(QVBoxLayout):
for controls in self.pilot_controls[new_size:]:
controls.disable_and_clear()
def replace(self, squadron: Squadron, new_roster: Optional[FlightRoster]) -> None:
def replace(
self, squadron: Squadron | None, new_roster: Optional[FlightRoster]
) -> None:
if self.roster is not None:
self.roster.clear()
self.roster = new_roster