]> git.mxchange.org Git - flightgear.git/commitdiff
Launcher: Maintain aircraft selection better
authorJames Turner <zakalawe@mac.com>
Sun, 10 Jan 2016 19:47:57 +0000 (13:47 -0600)
committerJames Turner <zakalawe@mac.com>
Sun, 10 Jan 2016 19:47:57 +0000 (13:47 -0600)
- when launching or toggling settings, try to keep the current
  aircraft selected and in-view.

src/GUI/QtLauncher.cxx
src/GUI/QtLauncher_private.hxx

index d99d25023d707802e7a6976a95c6af97624bab51..c66ef3c3e8c78d066eee9790b12cfeec002125ca 100644 (file)
@@ -303,7 +303,7 @@ protected:
             }
         }
 
-        if (m_ratingsFilter) {
+        if (!m_onlyShowInstalled && m_ratingsFilter) {
             QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
             for (int i=0; i<4; ++i) {
                 if (m_ratings[i] > index.data(AircraftRatingRole + i).toInt()) {
@@ -475,6 +475,9 @@ QtLauncher::QtLauncher() :
     m_aircraftProxy = new AircraftProxyModel(this);
     connect(m_ui->ratingsFilterCheck, &QAbstractButton::toggled,
             m_aircraftProxy, &AircraftProxyModel::setRatingFilterEnabled);
+    connect(m_ui->ratingsFilterCheck, &QAbstractButton::toggled,
+            this, &QtLauncher::maybeRestoreAircraftSelection);
+
     connect(m_ui->onlyShowInstalledCheck, &QAbstractButton::toggled,
             m_aircraftProxy, &AircraftProxyModel::setInstalledFilterEnabled);
     connect(m_ui->aircraftFilter, &QLineEdit::textChanged,
@@ -554,6 +557,13 @@ QtLauncher::QtLauncher() :
     connect(m_ui->pathsButton, &QPushButton::clicked,
             this, &QtLauncher::onEditPaths);
 
+    // after any kind of reset, try to restore selection and scroll
+    // to match the m_selectedAircraft. This needs to be delayed
+    // fractionally otherwise the scrollTo seems to be ignored,
+    // unfortunately.
+    connect(m_aircraftProxy, &AircraftProxyModel::modelReset,
+            this, &QtLauncher::delayedAircraftModelReset);
+
     restoreSettings();
 
     QSettings settings;
@@ -616,9 +626,30 @@ void QtLauncher::restoreSettings()
     m_aircraftProxy->setRatingFilterEnabled(m_ui->ratingsFilterCheck->isChecked());
     m_aircraftProxy->setRatings(m_ratingFilters);
 
+    updateSelectedAircraft();
+    maybeRestoreAircraftSelection();
+
     m_ui->commandLineArgs->setPlainText(settings.value("additional-args").toString());
 }
 
+void QtLauncher::delayedAircraftModelReset()
+{
+    QTimer::singleShot(1, this, &QtLauncher::maybeRestoreAircraftSelection);
+}
+
+void QtLauncher::maybeRestoreAircraftSelection()
+{
+    QModelIndex aircraftIndex = m_aircraftModel->indexOfAircraftURI(m_selectedAircraft);
+    QModelIndex proxyIndex = m_aircraftProxy->mapFromSource(aircraftIndex);
+    if (proxyIndex.isValid()) {
+        m_ui->aircraftList->selectionModel()->setCurrentIndex(proxyIndex,
+                                                              QItemSelectionModel::ClearAndSelect);
+        m_ui->aircraftList->selectionModel()->select(proxyIndex,
+                                                     QItemSelectionModel::ClearAndSelect);
+        m_ui->aircraftList->scrollTo(proxyIndex);
+    }
+}
+
 void QtLauncher::saveSettings()
 {
     QSettings settings;
@@ -848,6 +879,15 @@ void QtLauncher::onAircraftInstalledCompleted(QModelIndex index)
     maybeUpdateSelectedAircraft(index);
 }
 
+void QtLauncher::onRatingsFilterToggled()
+{
+    QModelIndex aircraftIndex = m_aircraftModel->indexOfAircraftURI(m_selectedAircraft);
+    QModelIndex proxyIndex = m_aircraftProxy->mapFromSource(aircraftIndex);
+    if (proxyIndex.isValid()) {
+        m_ui->aircraftList->scrollTo(proxyIndex);
+    }
+}
+
 void QtLauncher::onAircraftInstallFailed(QModelIndex index, QString errorMessage)
 {
     qWarning() << Q_FUNC_INFO << index.data(AircraftURIRole) << errorMessage;
@@ -870,6 +910,10 @@ void QtLauncher::onAircraftSelected(const QModelIndex& index)
 
 void QtLauncher::onRequestPackageInstall(const QModelIndex& index)
 {
+    // also select, otherwise UI is confusing
+    m_selectedAircraft = index.data(AircraftURIRole).toUrl();
+    updateSelectedAircraft();
+
     QString pkg = index.data(AircraftPackageIdRole).toString();
     simgear::pkg::PackageRef pref = globals->packageRoot()->getPackageById(pkg.toStdString());
     if (pref->isInstalled()) {
@@ -1029,12 +1073,7 @@ void QtLauncher::onRembrandtToggled(bool b)
 void QtLauncher::onShowInstalledAircraftToggled(bool b)
 {
     m_ui->ratingsFilterCheck->setEnabled(!b);
-    if (b) {
-        // don't filter installed aircraft by rating
-        m_aircraftProxy->setRatingFilterEnabled(false);
-    } else {
-        m_aircraftProxy->setRatingFilterEnabled(m_ui->ratingsFilterCheck->isChecked());
-    }
+    maybeRestoreAircraftSelection();
 }
 
 void QtLauncher::onSubsytemIdleTimeout()
index feeb9d47b2e350fa34d655aa8ec975b8c8e461fc..c0a6d5c09bc6eea574340ec09a3ab5d6b2d07e77 100644 (file)
@@ -104,6 +104,12 @@ private:
 
     simgear::pkg::PackageRef packageForAircraftURI(QUrl uri) const;
 
+    void maybeRestoreAircraftSelection();
+    // need to wait after a model reset before restoring selection and
+    // scrolling, to give the view time it seems.
+    void delayedAircraftModelReset();
+    void onRatingsFilterToggled();
+
     QScopedPointer<Ui::Launcher> m_ui;
     AircraftProxyModel* m_aircraftProxy;
     AircraftItemModel* m_aircraftModel;