Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Waypoint altitude change #2981

Merged
merged 8 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Saves from 7.x are not compatible with 8.0.
## Features/Improvements

* **[UI]** Limited size of overfull airbase display and added scrollbar.
* **[UI]** Waypoint altitudes can be edited in Waypoints tab of Edit Flight window.

## Fixes

Expand Down
43 changes: 34 additions & 9 deletions qt_ui/windows/mission/flight/waypoints/QFlightWaypointList.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,23 @@
from game.ato.flightwaypoint import FlightWaypoint
from game.ato.flightwaypointtype import FlightWaypointType
from game.ato.package import Package
from game.utils import Distance
from qt_ui.windows.mission.flight.waypoints.QFlightWaypointItem import QWaypointItem


HEADER_LABELS = ["Name", "Alt (ft)", "Alt Type", "TOT/DEPART"]


class QFlightWaypointList(QTableView):
def __init__(self, package: Package, flight: Flight):
super().__init__()
self.package = package
self.flight = flight

self.model = QStandardItemModel(self)
self.model.itemChanged.connect(self.on_changed)
self.setModel(self.model)
self.model.setHorizontalHeaderLabels(["Name", "Alt", "TOT/DEPART"])
self.model.setHorizontalHeaderLabels(HEADER_LABELS)

header = self.horizontalHeader()
header.setSectionResizeMode(0, QHeaderView.ResizeToContents)
Expand All @@ -27,17 +32,21 @@ def __init__(self, package: Package, flight: Flight):
self.indexAt(QPoint(1, 1)), QItemSelectionModel.Select
)

def update_list(self):
def update_list(self) -> None:
# disconnect itemChanged signal from handler slot for making altitude changes
# in advance updating waypoint list
self.model.itemChanged.disconnect(self.on_changed)
DanAlbert marked this conversation as resolved.
Show resolved Hide resolved

# We need to keep just the row and rebuild the index later because the
# QModelIndex will not be valid after the model is cleared.
current_index = self.currentIndex().row()
self.model.clear()

self.model.setHorizontalHeaderLabels(["Name", "Alt", "TOT/DEPART"])
self.model.setHorizontalHeaderLabels(HEADER_LABELS)

waypoints = self.flight.flight_plan.waypoints
for row, waypoint in enumerate(waypoints):
self.add_waypoint_row(row, self.flight, waypoint)
self._add_waypoint_row(row, self.flight, waypoint)
self.selectionModel().setCurrentIndex(
self.model.index(current_index, 0), QItemSelectionModel.Select
)
Expand All @@ -47,23 +56,39 @@ def update_list(self):
total_column_width += self.columnWidth(i) + self.lineWidth()
self.setFixedWidth(total_column_width)

def add_waypoint_row(
# reconnect itemChanged signal to handler slot for making altitude changes
self.model.itemChanged.connect(self.on_changed)

def _add_waypoint_row(
self, row: int, flight: Flight, waypoint: FlightWaypoint
) -> None:
self.model.insertRow(self.model.rowCount())

self.model.setItem(row, 0, QWaypointItem(waypoint, row))

altitude = int(waypoint.alt.feet)
altitude_type = "AGL" if waypoint.alt_type == "RADIO" else "MSL"
altitude_item = QStandardItem(f"{altitude} ft {altitude_type}")
altitude_item.setEditable(False)
altitude_item = QStandardItem(f"{altitude}")
altitude_item.setEditable(True)
self.model.setItem(row, 1, altitude_item)

altitude_type = "AGL" if waypoint.alt_type == "RADIO" else "MSL"
altitude_type_item = QStandardItem(f"{altitude_type}")
altitude_type_item.setEditable(False)
self.model.setItem(row, 2, altitude_type_item)

tot = self.tot_text(flight, waypoint)
tot_item = QStandardItem(tot)
tot_item.setEditable(False)
self.model.setItem(row, 2, tot_item)
self.model.setItem(row, 3, tot_item)

def on_changed(self) -> None:
for i in range(self.model.rowCount()):
altitude = self.model.item(i, 1).text()
try:
altitude_feet = float(altitude)
except:
DanAlbert marked this conversation as resolved.
Show resolved Hide resolved
continue
self.flight.flight_plan.waypoints[i].alt = Distance.from_feet(altitude_feet)

def tot_text(self, flight: Flight, waypoint: FlightWaypoint) -> str:
if waypoint.waypoint_type == FlightWaypointType.TAKEOFF:
Expand Down