Fix errors when changing task or aircraft type.

Fixes https://github.com/dcs-liberation/dcs_liberation/issues/1587
This commit is contained in:
Dan Albert 2021-09-01 17:14:51 -07:00
parent 15ce48e712
commit 8a60fa5c83
2 changed files with 4 additions and 7 deletions

View File

@ -85,7 +85,7 @@ class QFlightCreator(QDialog):
squadron, initial_size=self.flight_size_spinner.value() squadron, initial_size=self.flight_size_spinner.value()
) )
self.roster_editor = FlightRosterEditor(roster) self.roster_editor = FlightRosterEditor(roster)
self.flight_size_spinner.valueChanged.connect(self.resize_roster) self.flight_size_spinner.valueChanged.connect(self.roster_editor.resize)
self.squadron_selector.currentIndexChanged.connect(self.on_squadron_changed) self.squadron_selector.currentIndexChanged.connect(self.on_squadron_changed)
roster_layout = QHBoxLayout() roster_layout = QHBoxLayout()
layout.addLayout(roster_layout) layout.addLayout(roster_layout)
@ -136,10 +136,6 @@ class QFlightCreator(QDialog):
def set_custom_name_text(self, text: str): def set_custom_name_text(self, text: str):
self.custom_name_text = text self.custom_name_text = text
def resize_roster(self, new_size: int) -> None:
self.roster_editor.roster.resize(new_size)
self.roster_editor.resize(new_size)
def verify_form(self) -> Optional[str]: def verify_form(self) -> Optional[str]:
aircraft: Optional[Type[FlyingType]] = self.aircraft_selector.currentData() aircraft: Optional[Type[FlyingType]] = self.aircraft_selector.currentData()
squadron: Optional[Squadron] = self.squadron_selector.currentData() squadron: Optional[Squadron] = self.squadron_selector.currentData()
@ -196,7 +192,6 @@ class QFlightCreator(QDialog):
self.squadron_selector.update_items( self.squadron_selector.update_items(
self.task_selector.currentData(), new_aircraft self.task_selector.currentData(), new_aircraft
) )
self.departure.change_aircraft(new_aircraft)
self.divert.change_aircraft(new_aircraft) self.divert.change_aircraft(new_aircraft)
def on_departure_changed(self, departure: ControlPoint) -> None: def on_departure_changed(self, departure: ControlPoint) -> None:
@ -229,7 +224,7 @@ class QFlightCreator(QDialog):
self.roster_editor.replace( self.roster_editor.replace(
FlightRoster(squadron, self.flight_size_spinner.value()) FlightRoster(squadron, self.flight_size_spinner.value())
) )
self.on_departure_changed(squadron.location) self.on_departure_changed(squadron.location)
def update_max_size(self, available: int) -> None: def update_max_size(self, available: int) -> None:
aircraft = self.aircraft_selector.currentData() aircraft = self.aircraft_selector.currentData()

View File

@ -176,6 +176,8 @@ class FlightRosterEditor(QVBoxLayout):
def resize(self, new_size: int) -> None: def resize(self, new_size: int) -> None:
if new_size > self.MAX_PILOTS: if new_size > self.MAX_PILOTS:
raise ValueError("A flight may not have more than four pilots.") raise ValueError("A flight may not have more than four pilots.")
if self.roster is not None:
self.roster.resize(new_size)
for controls in self.pilot_controls[:new_size]: for controls in self.pilot_controls[:new_size]:
controls.enable_and_reset() controls.enable_and_reset()
for controls in self.pilot_controls[new_size:]: for controls in self.pilot_controls[new_size:]: