From 19a8fc882261830aee1363da9e5c70b2480f92d2 Mon Sep 17 00:00:00 2001 From: James Turner Date: Thu, 12 Nov 2015 00:11:12 +0000 Subject: [PATCH] Fixing launcher save/restore of settings. --- src/GUI/AircraftModel.cxx | 1 + src/GUI/AircraftModel.hxx | 3 +- src/GUI/LocationWidget.cxx | 82 +++++-------- src/GUI/QtLauncher.cxx | 243 ++----------------------------------- 4 files changed, 43 insertions(+), 286 deletions(-) diff --git a/src/GUI/AircraftModel.cxx b/src/GUI/AircraftModel.cxx index 3b156e701..f0e76c362 100644 --- a/src/GUI/AircraftModel.cxx +++ b/src/GUI/AircraftModel.cxx @@ -744,6 +744,7 @@ void AircraftItemModel::onScanFinished() { delete m_scanThread; m_scanThread = NULL; + emit scanCompleted(); } void AircraftItemModel::installFailed(QModelIndex index, simgear::pkg::Delegate::StatusCode reason) diff --git a/src/GUI/AircraftModel.hxx b/src/GUI/AircraftModel.hxx index 43208253d..c6a85e836 100644 --- a/src/GUI/AircraftModel.hxx +++ b/src/GUI/AircraftModel.hxx @@ -116,7 +116,6 @@ public: * given a -set.xml path, return the corresponding model index, if one * exists. */ - // QModelIndex indexOfAircraftPath(QString path) const; QModelIndex indexOfAircraftURI(QUrl uri) const; @@ -131,6 +130,8 @@ signals: void aircraftInstallCompleted(QModelIndex index); + void scanCompleted(); + private slots: void onScanResults(); diff --git a/src/GUI/LocationWidget.cxx b/src/GUI/LocationWidget.cxx index 69723a1b5..d6dab1b5d 100644 --- a/src/GUI/LocationWidget.cxx +++ b/src/GUI/LocationWidget.cxx @@ -41,8 +41,6 @@ #include
#include
// for fgSetDouble -const int MAX_RECENT_AIRPORTS = 32; - using namespace flightgear; QString fixNavaidName(QString s) @@ -205,7 +203,7 @@ public: } if (role == Qt::DecorationRole) { - return AirportDiagram::iconForPositioned(pos); + return AirportDiagram::iconForPositioned(pos, true); } if (role == Qt::EditRole) { @@ -301,6 +299,8 @@ LocationWidget::LocationWidget(QWidget *parent) : connect(m_ui->locationSearchEdit, &QLineEdit::returnPressed, this, &LocationWidget::onSearch); + // disabled for now + m_ui->searchHistory->hide(); connect(m_ui->searchHistory, &QPushButton::clicked, this, &LocationWidget::onPopupHistory); @@ -338,14 +338,22 @@ LocationWidget::~LocationWidget() void LocationWidget::restoreSettings() { QSettings settings; - Q_FOREACH(QVariant v, settings.value("recent-locations").toList()) { - m_recentAirports.push_back(v.toLongLong()); - } - if (!m_recentAirports.empty()) { - setBaseLocation(NavDataCache::instance()->loadById(m_recentAirports.front())); + if (settings.contains("location-lat")) { + m_locationIsLatLon = true; + m_geodLocation = SGGeod::fromDeg(settings.value("location-lon").toDouble(), + settings.value("location-lat").toDouble()); + } else if (settings.contains("location-id")) { + m_location = NavDataCache::instance()->loadById(settings.value("location-id").toULongLong()); } + m_ui->altitudeSpinbox->setValue(settings.value("altitude").toInt()); + m_ui->airspeedSpinbox->setValue(settings.value("speed").toInt()); + m_ui->offsetGroup->setChecked(settings.value("offset-enabled").toBool()); + m_ui->offsetBearingSpinbox->setValue(settings.value("offset-bearing").toInt()); + m_ui->offsetNmSpinbox->setValue(settings.value("offset-distance").toInt()); + + onLocationChanged(); updateDescription(); } @@ -369,12 +377,21 @@ void LocationWidget::saveSettings() { QSettings settings; - QVariantList locations; - Q_FOREACH(PositionedID v, m_recentAirports) { - locations.push_back(v); + settings.remove("location-id"); + 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", m_location->guid()); } - settings.setValue("recent-airports", locations); + 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()); } void LocationWidget::setLocationOptions() @@ -571,7 +588,7 @@ void LocationWidget::onLocationChanged() } else if (m_locationIsLatLon) { m_ui->stack->setCurrentIndex(1); m_ui->navaidDiagram->setGeod(m_geodLocation); - } else { + } else if (m_location) { // navaid m_ui->stack->setCurrentIndex(1); m_ui->navaidDiagram->setNavaid(m_location); @@ -708,28 +725,6 @@ void LocationWidget::onOffsetBearingTrueChanged(bool on) void LocationWidget::onPopupHistory() { - if (m_recentAirports.isEmpty()) { - return; - } - -#if 0 - QMenu m; - Q_FOREACH(QString aptCode, m_recentAirports) { - FGAirportRef apt = FGAirport::findByIdent(aptCode.toStdString()); - QString name = QString::fromStdString(apt->name()); - QAction* act = m.addAction(QString("%1 - %2").arg(aptCode).arg(name)); - act->setData(aptCode); - } - - QPoint popupPos = m_ui->airportHistory->mapToGlobal(m_ui->airportHistory->rect().bottomLeft()); - QAction* triggered = m.exec(popupPos); - if (triggered) { - FGAirportRef apt = FGAirport::findByIdent(triggered->data().toString().toStdString()); - setAirport(apt); - m_ui->airportEdit->clear(); - m_ui->locationStack->setCurrentIndex(0); - } -#endif } void LocationWidget::setBaseLocation(FGPositionedRef ref) @@ -740,23 +735,6 @@ void LocationWidget::setBaseLocation(FGPositionedRef ref) m_location = ref; onLocationChanged(); -#if 0 - if (ref.valid()) { - // maintain the recent airport list - QString icao = QString::fromStdString(ref->ident()); - if (m_recentAirports.contains(icao)) { - // move to front - m_recentAirports.removeOne(icao); - m_recentAirports.push_front(icao); - } else { - // insert and trim list if necessary - m_recentAirports.push_front(icao); - if (m_recentAirports.size() > MAX_RECENT_AIRPORTS) { - m_recentAirports.pop_back(); - } - } - } -#endif updateDescription(); } diff --git a/src/GUI/QtLauncher.cxx b/src/GUI/QtLauncher.cxx index 57f8be6f3..e0c2683c9 100644 --- a/src/GUI/QtLauncher.cxx +++ b/src/GUI/QtLauncher.cxx @@ -260,116 +260,6 @@ public: } }; -class AirportSearchModel : public QAbstractListModel -{ - Q_OBJECT -public: - AirportSearchModel() : - m_searchActive(false) - { - } - - void setSearch(QString t) - { - beginResetModel(); - - m_items.clear(); - m_ids.clear(); - - std::string term(t.toUpper().toStdString()); - - IdentSearchFilter filter; - FGPositionedList exactMatches = NavDataCache::instance()->findAllWithIdent(term, &filter, true); - - for (unsigned int i=0; iguid()); - m_items.push_back(exactMatches[i]); - } - endResetModel(); - - - m_search.reset(new NavDataCache::ThreadedGUISearch(term)); - QTimer::singleShot(100, this, SLOT(onSearchResultsPoll())); - m_searchActive = true; - endResetModel(); - } - - bool isSearchActive() const - { - return m_searchActive; - } - - virtual int rowCount(const QModelIndex&) const - { - // if empty, return 1 for special 'no matches'? - return m_ids.size(); - } - - virtual QVariant data(const QModelIndex& index, int role) const - { - if (!index.isValid()) - return QVariant(); - - FGPositionedRef pos = itemAtRow(index.row()); - if (role == Qt::DisplayRole) { - QString name = QString::fromStdString(pos->name()); - return QString("%1: %2").arg(QString::fromStdString(pos->ident())).arg(name); - } - - if (role == Qt::EditRole) { - return QString::fromStdString(pos->ident()); - } - - if (role == Qt::UserRole) { - return static_cast(m_ids[index.row()]); - } - - return QVariant(); - } - - FGPositionedRef itemAtRow(unsigned int row) const - { - FGPositionedRef pos = m_items[row]; - if (!pos.valid()) { - pos = NavDataCache::instance()->loadById(m_ids[row]); - m_items[row] = pos; - } - - return pos; - } -Q_SIGNALS: - void searchComplete(); - -private slots: - void onSearchResultsPoll() - { - PositionedIDVec newIds = m_search->results(); - - beginInsertRows(QModelIndex(), m_ids.size(), newIds.size() - 1); - for (unsigned int i=m_ids.size(); i < newIds.size(); ++i) { - m_ids.push_back(newIds[i]); - m_items.push_back(FGPositionedRef()); // null ref - } - endInsertRows(); - - if (m_search->isComplete()) { - m_searchActive = false; - m_search.reset(); - emit searchComplete(); - } else { - QTimer::singleShot(100, this, SLOT(onSearchResultsPoll())); - } - } - -private: - PositionedIDVec m_ids; - mutable FGPositionedList m_items; - bool m_searchActive; - QScopedPointer m_search; -}; -======= ->>>>>>> Work on LocationWidget for Qt launcher - class AircraftProxyModel : public QSortFilterProxyModel { Q_OBJECT @@ -465,7 +355,6 @@ bool runLauncherDialog() { sglog().setLogLevels( SG_ALL, SG_INFO ); - initQtResources(); // can't be called inside a namespaceb // startup the nav-cache now. This pre-empts normal startup of @@ -473,7 +362,6 @@ bool runLauncherDialog() initNavCache(); - fgInitPackageRoot(); // startup the HTTP system now since packages needs it @@ -483,7 +371,6 @@ bool runLauncherDialog() // will happen as normal http->init(); - // setup scenery paths now, especially TerraSync path for airport // parking locations (after they're downloaded) @@ -545,24 +432,6 @@ QtLauncher::QtLauncher() : connect(m_ui->aircraftFilter, &QLineEdit::textChanged, m_aircraftProxy, &QSortFilterProxyModel::setFilterFixedString); -<<<<<<< 56d7d049bc0b7361d1799298c38e61084f5d5e3f - connect(m_ui->runwayCombo, SIGNAL(currentIndexChanged(int)), - this, SLOT(updateLocationDescription())); - connect(m_ui->parkingCombo, SIGNAL(currentIndexChanged(int)), - this, SLOT(updateLocationDescription())); - connect(m_ui->runwayRadio, SIGNAL(toggled(bool)), - this, SLOT(updateLocationDescription())); - connect(m_ui->parkingRadio, SIGNAL(toggled(bool)), - this, SLOT(updateLocationDescription())); - connect(m_ui->onFinalCheckbox, SIGNAL(toggled(bool)), - this, SLOT(updateLocationDescription())); - - - connect(m_ui->airportDiagram, &AirportDiagram::clickedRunway, - this, &QtLauncher::onAirportDiagramClicked); -======= ->>>>>>> Work on LocationWidget for Qt launcher - connect(m_ui->runButton, SIGNAL(clicked()), this, SLOT(onRun())); connect(m_ui->quitButton, SIGNAL(clicked()), this, SLOT(onQuit())); @@ -630,7 +499,8 @@ QtLauncher::QtLauncher() : this, &QtLauncher::onAircraftInstalledCompleted); connect(m_aircraftModel, &AircraftItemModel::aircraftInstallFailed, this, &QtLauncher::onAircraftInstallFailed); - + connect(m_aircraftModel, &AircraftItemModel::scanCompleted, + this, &QtLauncher::updateSelectedAircraft); connect(m_ui->pathsButton, &QPushButton::clicked, this, &QtLauncher::onEditPaths); @@ -723,7 +593,9 @@ void QtLauncher::restoreSettings() if (!m_recentAircraft.empty()) { m_selectedAircraft = m_recentAircraft.front(); + qDebug() << "restoring aircraft" << m_selectedAircraft; } else { + qDebug() << "recent aircraft is empty"; // select the default C172p } @@ -741,6 +613,8 @@ void QtLauncher::restoreSettings() m_aircraftProxy->setRatings(m_ratingFilters); m_ui->commandLineArgs->setPlainText(settings.value("additional-args").toString()); + + qDebug() << "restoring settings"; } void QtLauncher::saveSettings() @@ -760,6 +634,7 @@ void QtLauncher::saveSettings() settings.setValue("additional-args", m_ui->commandLineArgs->toPlainText()); m_ui->location->saveSettings(); + qDebug() << "saving settings"; } void QtLauncher::setEnableDisableOptionFromCheckbox(QCheckBox* cbox, QString name) const @@ -825,6 +700,8 @@ void QtLauncher::onRun() m_recentAircraft.prepend(m_selectedAircraft); if (m_recentAircraft.size() > MAX_RECENT_AIRCRAFT) m_recentAircraft.pop_back(); + + qDebug() << "recent aircraft is now" << m_recentAircraft; } m_ui->location->setLocationOptions(); @@ -932,107 +809,6 @@ void QtLauncher::onQuit() reject(); } -<<<<<<< 56d7d049bc0b7361d1799298c38e61084f5d5e3f -void QtLauncher::onSearchAirports() -{ - QString search = m_ui->airportEdit->text(); - m_airportsModel->setSearch(search); - - if (m_airportsModel->isSearchActive()) { - m_ui->searchStatusText->setText(QString("Searching for '%1'").arg(search)); - m_ui->locationStack->setCurrentIndex(2); - } else if (m_airportsModel->rowCount(QModelIndex()) == 1) { - setBaseLocation(m_airportsModel->itemAtRow(0)); - m_ui->locationStack->setCurrentIndex(0); - } -} - -void QtLauncher::onAirportSearchComplete() -{ - int numResults = m_airportsModel->rowCount(QModelIndex()); - if (numResults == 0) { - m_ui->searchStatusText->setText(QString("No matching airports for '%1'").arg(m_ui->airportEdit->text())); - } else if (numResults == 1) { - setBaseLocation(m_airportsModel->itemAtRow(0)); - m_ui->locationStack->setCurrentIndex(0); - } else { - m_ui->locationStack->setCurrentIndex(1); - } -} - -void QtLauncher::onLocationChanged() -{ - bool locIsAirport = FGAirport::isAirportType(m_location.ptr()); - - m_ui->runwayCombo->setEnabled(locIsAirport); - m_ui->parkingCombo->setEnabled(locIsAirport); - if (locIsAirport) { - FGAirport* apt = static_cast(m_location.ptr()); - m_ui->airportDiagram->setAirport(apt); - - m_ui->runwayRadio->setChecked(true); // default back to runway mode - // unless multiplayer is enabled ? - m_ui->airportDiagram->setEnabled(true); - - m_ui->runwayCombo->clear(); - m_ui->runwayCombo->addItem("Automatic", -1); - for (unsigned int r=0; rnumRunways(); ++r) { - FGRunwayRef rwy = apt->getRunwayByIndex(r); - // add runway with index as data role - m_ui->runwayCombo->addItem(QString::fromStdString(rwy->ident()), r); - - m_ui->airportDiagram->addRunway(rwy); - } - - m_ui->parkingCombo->clear(); - FGAirportDynamics* dynamics = apt->getDynamics(); - PositionedIDVec parkings = NavDataCache::instance()->airportItemsOfType(m_location->guid(), - FGPositioned::PARKING); - if (parkings.empty()) { - m_ui->parkingCombo->setEnabled(false); - m_ui->parkingRadio->setEnabled(false); - } else { - m_ui->parkingCombo->setEnabled(true); - m_ui->parkingRadio->setEnabled(true); - Q_FOREACH(PositionedID parking, parkings) { - FGParking* park = dynamics->getParking(parking); - m_ui->parkingCombo->addItem(QString::fromStdString(park->getName()), - static_cast(parking)); - - m_ui->airportDiagram->addParking(park); - } - } - - - } // of location is aiport - - - - -} - -void QtLauncher::onOffsetRadioToggled(bool on) -{ - m_ui->offsetNmSpinbox->setEnabled(on); - m_ui->offsetBearingSpinbox->setEnabled(on); - m_ui->trueBearing->setEnabled(on); - m_ui->offsetBearingLabel->setEnabled(on); - m_ui->offsetDistanceLabel->setEnabled(on); -} - -void QtLauncher::onAirportDiagramClicked(FGRunwayRef rwy) -{ - if (rwy) { - m_ui->runwayRadio->setChecked(true); - int rwyIndex = m_ui->runwayCombo->findText(QString::fromStdString(rwy->ident())); - m_ui->runwayCombo->setCurrentIndex(rwyIndex); - } - - updateLocationDescription(); -} -======= ->>>>>>> Work on LocationWidget for Qt launcher - void QtLauncher::onToggleTerrasync(bool enabled) { if (enabled) { @@ -1092,6 +868,7 @@ void QtLauncher::onAircraftInstallFailed(QModelIndex index, QString errorMessage void QtLauncher::onAircraftSelected(const QModelIndex& index) { m_selectedAircraft = index.data(AircraftURIRole).toUrl(); + qDebug() << "selected aircraft is now" << m_selectedAircraft; updateSelectedAircraft(); } -- 2.39.5