]> git.mxchange.org Git - flightgear.git/commitdiff
‘only show installed checkbox’ for Qt launcher
authorJames Turner <zakalawe@mac.com>
Sun, 10 Jan 2016 18:56:46 +0000 (12:56 -0600)
committerJames Turner <zakalawe@mac.com>
Sun, 10 Jan 2016 18:56:46 +0000 (12:56 -0600)
- will be replaced when I think of a prettier UI, but this
  feature is important to have for now.

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

index 9e696ca2859aee9528812c87467245240931d737..b10749fd2c11d2861e1c55096d171e534fe6a0af 100644 (file)
        </item>
        <item>
         <layout class="QHBoxLayout" name="horizontalLayout_5">
+         <item>
+          <widget class="QCheckBox" name="onlyShowInstalledCheck">
+           <property name="text">
+            <string>Only show installed aircraft</string>
+           </property>
+          </widget>
+         </item>
+         <item>
+          <spacer name="horizontalSpacer_3">
+           <property name="orientation">
+            <enum>Qt::Horizontal</enum>
+           </property>
+           <property name="sizeHint" stdset="0">
+            <size>
+             <width>40</width>
+             <height>20</height>
+            </size>
+           </property>
+          </spacer>
+         </item>
          <item>
           <widget class="QCheckBox" name="ratingsFilterCheck">
            <property name="sizePolicy">
index 53bae459e1d7c57e15e510a2aeb7b7b555c63ed6..d99d25023d707802e7a6976a95c6af97624bab51 100644 (file)
@@ -252,7 +252,8 @@ class AircraftProxyModel : public QSortFilterProxyModel
 public:
     AircraftProxyModel(QObject* pr) :
         QSortFilterProxyModel(pr),
-        m_ratingsFilter(true)
+        m_ratingsFilter(true),
+        m_onlyShowInstalled(false)
     {
         for (int i=0; i<4; ++i) {
             m_ratings[i] = 3;
@@ -276,6 +277,16 @@ public slots:
         invalidate();
     }
 
+    void setInstalledFilterEnabled(bool e)
+    {
+        if (e == m_onlyShowInstalled) {
+            return;
+        }
+
+        m_onlyShowInstalled = e;
+        invalidate();
+    }
+
 protected:
     bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
     {
@@ -283,6 +294,15 @@ protected:
             return false;
         }
 
+        if (m_onlyShowInstalled) {
+            QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
+            QVariant v = index.data(AircraftPackageStatusRole);
+            AircraftItemStatus status = static_cast<AircraftItemStatus>(v.toInt());
+            if (status == PackageNotInstalled) {
+                return false;
+            }
+        }
+
         if (m_ratingsFilter) {
             QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
             for (int i=0; i<4; ++i) {
@@ -297,6 +317,7 @@ protected:
 
 private:
     bool m_ratingsFilter;
+    bool m_onlyShowInstalled;
     int m_ratings[4];
 };
 
@@ -454,6 +475,8 @@ QtLauncher::QtLauncher() :
     m_aircraftProxy = new AircraftProxyModel(this);
     connect(m_ui->ratingsFilterCheck, &QAbstractButton::toggled,
             m_aircraftProxy, &AircraftProxyModel::setRatingFilterEnabled);
+    connect(m_ui->onlyShowInstalledCheck, &QAbstractButton::toggled,
+            m_aircraftProxy, &AircraftProxyModel::setInstalledFilterEnabled);
     connect(m_ui->aircraftFilter, &QLineEdit::textChanged,
             m_aircraftProxy, &QSortFilterProxyModel::setFilterFixedString);
 
@@ -473,6 +496,8 @@ QtLauncher::QtLauncher() :
 
     connect(m_ui->editRatingFilter, &QPushButton::clicked,
             this, &QtLauncher::onEditRatingsFilter);
+    connect(m_ui->onlyShowInstalledCheck, &QCheckBox::toggled,
+            this, &QtLauncher::onShowInstalledAircraftToggled);
 
     QIcon historyIcon(":/history-icon");
     m_ui->aircraftHistory->setIcon(historyIcon);
@@ -577,6 +602,11 @@ void QtLauncher::restoreSettings()
     m_ui->location->restoreSettings();
 
     // rating filters
+    m_ui->onlyShowInstalledCheck->setChecked(settings.value("only-show-installed", false).toBool());
+    if (m_ui->onlyShowInstalledCheck->isChecked()) {
+        m_ui->ratingsFilterCheck->setEnabled(false);
+    }
+
     m_ui->ratingsFilterCheck->setChecked(settings.value("ratings-filter", true).toBool());
     int index = 0;
     Q_FOREACH(QVariant v, settings.value("min-ratings").toList()) {
@@ -599,6 +629,7 @@ void QtLauncher::saveSettings()
     settings.setValue("enable-realwx", m_ui->fetchRealWxrCheckbox->isChecked());
     settings.setValue("start-paused", m_ui->startPausedCheck->isChecked());
     settings.setValue("ratings-filter", m_ui->ratingsFilterCheck->isChecked());
+    settings.setValue("only-show-installed", m_ui->onlyShowInstalledCheck->isChecked());
     settings.setValue("recent-aircraft", QUrl::toStringList(m_recentAircraft));
 
     settings.setValue("timeofday", m_ui->timeOfDayCombo->currentIndex());
@@ -995,6 +1026,17 @@ void QtLauncher::onRembrandtToggled(bool b)
     m_ui->msaaCheckbox->setEnabled(!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());
+    }
+}
+
 void QtLauncher::onSubsytemIdleTimeout()
 {
     globals->get_subsystem_mgr()->update(0.0);
index 64b38014a778fd86772b82213240dadcb6b2c57d..feeb9d47b2e350fa34d655aa8ec975b8c8e461fc 100644 (file)
@@ -83,6 +83,8 @@ private slots:
 
     void onAircraftInstalledCompleted(QModelIndex index);
     void onAircraftInstallFailed(QModelIndex index, QString errorMessage);
+
+    void onShowInstalledAircraftToggled(bool b);
 private:
 
     /**