]> git.mxchange.org Git - flightgear.git/commitdiff
Fix persistence of on-ground location.
authorJames Turner <zakalawe@mac.com>
Sat, 16 Jul 2016 17:23:48 +0000 (18:23 +0100)
committerRoland Haeder <roland@mxchange.org>
Thu, 22 Sep 2016 21:27:47 +0000 (23:27 +0200)
src/Airports/groundnetwork.cxx
src/Airports/groundnetwork.hxx
src/GUI/LocationWidget.cxx

index 31ed8131bf3c0e042177c3270399ee2193e7c71d..0d036937ef2536980bc72c67333b3639ea19978b 100644 (file)
@@ -410,6 +410,16 @@ FGTaxiNodeRef FGGroundNetwork::findNodeByIndex(int index) const
    return FGTaxiNodeRef();
 }
 
+FGParkingRef FGGroundNetwork::getParkingByIndex(unsigned int index) const
+{
+    FGTaxiNodeRef tn = findNodeByIndex(index);
+    if (!tn.valid() || (tn->type() != FGPositioned::PARKING)) {
+        return FGParkingRef();
+    }
+
+    return FGParkingRef(static_cast<FGParking*>(tn.ptr()));
+}
+
 void FGGroundNetwork::addSegment(const FGTaxiNodeRef &from, const FGTaxiNodeRef &to)
 {
     FGTaxiSegment* seg = new FGTaxiSegment(from, to);
index 04e318898e4d084a055746a3c906ae8830a6c1a0..a134f5947b594009f3bced2ba976ade7c0547803 100644 (file)
@@ -255,6 +255,8 @@ public:
 
     const FGParkingList& allParkings() const;
 
+    FGParkingRef getParkingByIndex(unsigned int index) const;
+
     /**
      * Find the taxiway segment joining two (ground-net) nodes. Returns
      * NULL if no such segment exists.
index f09acbdd187ff79f298aa15d7ac9548dd86aa093..97d149104682171f81815bc6eac581f96d340e13 100644 (file)
@@ -447,6 +447,31 @@ void LocationWidget::restoreSettings()
     m_searchModel->setItems(m_recentLocations);
 
     onLocationChanged();
+
+    // now we've loaded airport location data (potentially), we can apply
+    // more settings
+    if (FGAirport::isAirportType(m_location.ptr())) {
+        if (settings.contains("location-apt-runway")) {
+            QString runway = settings.value("location-apt-runway").toString();
+            int index = m_ui->runwayCombo->findText(runway);
+            if (index < 0) {
+                index = 0; // revert to 'active' option
+            }
+            m_ui->runwayRadio->setChecked(true);
+            m_ui->runwayCombo->setCurrentIndex(index);
+        } else if (settings.contains("location-apt-parking")) {
+            QString parking = settings.value("location-apt-parking").toString();
+            int index = m_ui->parkingCombo->findText(parking);
+            if (index >= 0) {
+                m_ui->parkingRadio->setChecked(true);
+                m_ui->parkingCombo->setCurrentIndex(index);
+            }
+        }
+
+        m_ui->onFinalCheckbox->setChecked(settings.value("location-on-final").toBool());
+        m_ui->approachDistanceSpin->setValue(settings.value("location-apt-final-distance").toInt());
+    } // of location is an airport
+
     updateDescription();
 }
 
@@ -476,14 +501,30 @@ void LocationWidget::saveSettings()
     if (m_locationIsLatLon) {
         settings.setValue("location-lat", m_geodLocation.getLatitudeDeg());
         settings.setValue("location-lon", m_geodLocation.getLongitudeDeg());
-
     } else if (m_location) {
         settings.setValue("location-id", static_cast<qlonglong>(m_location->guid()));
-    }
+
+        if (FGAirport::isAirportType(m_location.ptr())) {
+            settings.remove("location-apt-runway");
+            settings.remove("location-apt-parking");
+
+            settings.setValue("location-on-final", m_ui->onFinalCheckbox->isChecked());
+            settings.setValue("location-apt-final-distance", m_ui->approachDistanceSpin->value());
+            if (m_ui->runwayRadio->isChecked()) {
+                if (m_ui->runwayCombo->currentIndex() > 0) {
+                    settings.setValue("location-apt-runway", m_ui->runwayCombo->currentText());
+                } else {
+                    settings.setValue("location-apt-runway", "active");
+                }
+            } else if (m_ui->parkingRadio->isChecked()) {
+                settings.setValue("location-apt-parking", m_ui->parkingCombo->currentText());
+            }
+        } // of location is an airport
+    } // of m_location is valid
+
 
     settings.setValue("altitude", m_ui->altitudeSpinbox->value());
     settings.setValue("speed", m_ui->airspeedSpinbox->value());
-
     settings.setValue("offset-enabled", m_ui->offsetGroup->isChecked());
     settings.setValue("offset-bearing", m_ui->offsetBearingSpinbox->value());
     settings.setValue("offset-distance", m_ui->offsetNmSpinbox->value());
@@ -866,7 +907,6 @@ void LocationWidget::updateDescription()
             int comboIndex = m_ui->runwayCombo->currentIndex();
             int runwayIndex = m_ui->runwayCombo->itemData(comboIndex).toInt();
             if (apt->type() == FGPositioned::HELIPORT) {
-                m_ui->airportDiagram->setSelectedRunway(FGRunwayRef());
                 FGHelipadRef pad = (runwayIndex >= 0) ?
                             apt->getHelipadByIndex(runwayIndex) : FGHelipadRef();
                 m_ui->airportDiagram->setSelectedHelipad(pad);
@@ -876,6 +916,10 @@ void LocationWidget::updateDescription()
                     apt->getRunwayByIndex(runwayIndex) : FGRunwayRef();
                 m_ui->airportDiagram->setSelectedRunway(rwy);
             }
+        } else if (m_ui->parkingRadio->isChecked()) {
+            int groundNetIndex = m_ui->parkingCombo->currentData().toInt();
+            FGParkingRef park = apt->groundNetwork()->getParkingByIndex(groundNetIndex);
+            m_ui->airportDiagram->setSelectedParking(park);
         }
 
         if (m_ui->onFinalCheckbox->isChecked()) {