From b7e98caecf66106ae086b8bf3260971a1b050759 Mon Sep 17 00:00:00 2001 From: James Turner Date: Sun, 1 Jul 2018 09:55:37 +0100 Subject: [PATCH] Ensure the C172P tutorial airport (PHTO) is always listed Adjust the location history so the default and tutorial airports always appear at history locations 0 and 1. --- src/GUI/LocationController.cxx | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/GUI/LocationController.cxx b/src/GUI/LocationController.cxx index e591c9461..654a3baf6 100644 --- a/src/GUI/LocationController.cxx +++ b/src/GUI/LocationController.cxx @@ -603,18 +603,26 @@ QObjectList LocationController::airportParkings() const void LocationController::showHistoryInSearchModel() { - // prepend the default location - FGPositionedList locs = m_recentLocations; + // prepend the default location and tutorial airport + + FGPositionedList locs = m_recentLocations; const std::string defaultICAO = flightgear::defaultAirportICAO(); + const std::string tutorialICAO = "PHTO"; // C172P tutorial aiurport - auto it = std::find_if(locs.begin(), locs.end(), [defaultICAO](FGPositionedRef pos) { - return pos->ident() == defaultICAO; + // remove them from the recent locations + auto it = std::remove_if(locs.begin(), locs.end(), + [defaultICAO, tutorialICAO](FGPositionedRef pos) + { + return (pos->ident() == defaultICAO) || (pos->ident() == tutorialICAO); }); + locs.erase(it, locs.end()); - if (it == locs.end()) { - FGAirportRef apt = FGAirport::findByIdent(defaultICAO); - locs.insert(locs.begin(), apt); - } + // prepend them + FGAirportRef apt = FGAirport::findByIdent(tutorialICAO); + locs.insert(locs.begin(), apt); + + apt = FGAirport::findByIdent(defaultICAO); + locs.insert(locs.begin(), apt); m_searchModel->setItems(locs); }