From 7a0483281de102bbaf33b164e8b159973a4d14b3 Mon Sep 17 00:00:00 2001 From: James Turner Date: Thu, 28 Jun 2018 23:45:52 +0100 Subject: [PATCH] Aircraft update list gets its own tab --- src/GUI/AircraftModel.cxx | 20 --------------- src/GUI/AircraftModel.hxx | 15 +---------- src/GUI/AircraftSearchFilterModel.cxx | 33 ++++++++++++++++++++++++ src/GUI/AircraftSearchFilterModel.hxx | 8 ++++++ src/GUI/LauncherController.cxx | 4 +++ src/GUI/LauncherController.hxx | 2 ++ src/GUI/qml/AircraftList.qml | 36 ++++++++++++++++++++++++++- src/GUI/qml/UpdateAllPanel.qml | 17 ++----------- 8 files changed, 85 insertions(+), 50 deletions(-) diff --git a/src/GUI/AircraftModel.cxx b/src/GUI/AircraftModel.cxx index c55721d50..beeb26d9c 100644 --- a/src/GUI/AircraftModel.cxx +++ b/src/GUI/AircraftModel.cxx @@ -247,8 +247,6 @@ void AircraftItemModel::refreshPackages() } emit dataChanged(index(firstRow), index(firstRow + newSize - 1)); - m_cachedUpdateCount = m_packageRoot->packagesNeedingUpdate().size(); - emit aircraftNeedingUpdatedChanged(); } int AircraftItemModel::rowCount(const QModelIndex& parent) const @@ -701,22 +699,4 @@ bool AircraftItemModel::isIndexRunnable(const QModelIndex& index) const return !ex->isDownloading(); } -int AircraftItemModel::aircraftNeedingUpdated() const -{ - return m_cachedUpdateCount; -} - -bool AircraftItemModel::showUpdateAll() const -{ - return (m_cachedUpdateCount > 0) && m_showUpdateAll; -} - -void AircraftItemModel::setShowUpdateAll(bool showUpdateAll) -{ - if (m_showUpdateAll == showUpdateAll) - return; - - m_showUpdateAll = showUpdateAll; - emit aircraftNeedingUpdatedChanged(); -} diff --git a/src/GUI/AircraftModel.hxx b/src/GUI/AircraftModel.hxx index eae8d7188..28da1d617 100644 --- a/src/GUI/AircraftModel.hxx +++ b/src/GUI/AircraftModel.hxx @@ -66,9 +66,6 @@ class AircraftItemModel : public QAbstractListModel { Q_OBJECT - Q_PROPERTY(int aircraftNeedingUpdated READ aircraftNeedingUpdated NOTIFY aircraftNeedingUpdatedChanged) - Q_PROPERTY(bool showUpdateAll READ showUpdateAll WRITE setShowUpdateAll NOTIFY aircraftNeedingUpdatedChanged) - public: AircraftItemModel(QObject* pr); @@ -110,20 +107,12 @@ public: */ QString nameForAircraftURI(QUrl uri) const; - int aircraftNeedingUpdated() const; - - bool showUpdateAll() const; - signals: void aircraftInstallFailed(QModelIndex index, QString errorMessage); void aircraftInstallCompleted(QModelIndex index); - void aircraftNeedingUpdatedChanged(); - void catalogsRefreshed(); -public slots: - void setShowUpdateAll(bool showUpdateAll); private slots: void onScanStarted(); @@ -153,7 +142,7 @@ private: QVariant packagePreviews(simgear::pkg::PackageRef p, const DelegateState &ds) const; void refreshPackages(); - + void installSucceeded(QModelIndex index); void installFailed(QModelIndex index, simgear::pkg::Delegate::StatusCode reason); @@ -165,9 +154,7 @@ private: simgear::pkg::PackageList m_packages; mutable QHash m_downloadedPixmapCache; - int m_cachedUpdateCount = 0; int m_cachedLocalAircraftCount = 0; - bool m_showUpdateAll = true; }; #endif // of FG_GUI_AIRCRAFT_MODEL diff --git a/src/GUI/AircraftSearchFilterModel.cxx b/src/GUI/AircraftSearchFilterModel.cxx index 8134e195e..bd26107c0 100644 --- a/src/GUI/AircraftSearchFilterModel.cxx +++ b/src/GUI/AircraftSearchFilterModel.cxx @@ -15,6 +15,10 @@ AircraftProxyModel::AircraftProxyModel(QObject *pr, QAbstractItemModel * source) // kick off initial sort sort(0); + + connect(this, &QAbstractItemModel::rowsInserted, this, &AircraftProxyModel::countChanged); + connect(this, &QAbstractItemModel::rowsRemoved, this, &AircraftProxyModel::countChanged); + connect(this, &QAbstractItemModel::modelReset, this, &AircraftProxyModel::countChanged); } void AircraftProxyModel::setRatings(QList ratings) @@ -78,6 +82,11 @@ QString AircraftProxyModel::summaryText() const return tr("(%1 aircraft)").arg(unfilteredCount); } +int AircraftProxyModel::count() const +{ + return rowCount(); +} + void AircraftProxyModel::setInstalledFilterEnabled(bool e) { if (e == m_onlyShowInstalled) { @@ -88,6 +97,15 @@ void AircraftProxyModel::setInstalledFilterEnabled(bool e) invalidate(); } +void AircraftProxyModel::setHaveUpdateFilterEnabled(bool e) +{ + if (e == m_onlyShowWithUpdate) + return; + + m_onlyShowWithUpdate = e; + invalidate(); +} + bool AircraftProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); @@ -105,6 +123,21 @@ bool AircraftProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sour } } + if (m_onlyShowWithUpdate) { + QVariant v = index.data(AircraftPackageStatusRole); + const auto status = static_cast(v.toInt()); + switch (status) { + case LocalAircraftCache::PackageNotInstalled: + case LocalAircraftCache::PackageInstalled: + case LocalAircraftCache::NotPackaged: + return false; // no updated need / possible + + // otherwise, show in the update list + default: + break; + } + } + // if there is no search active, i.e we are browsing, we might apply the // ratings filter. if (m_filterString.isEmpty() && !m_onlyShowInstalled && m_ratingsFilter) { diff --git a/src/GUI/AircraftSearchFilterModel.hxx b/src/GUI/AircraftSearchFilterModel.hxx index 43ddf2fb5..e33bf6b2b 100644 --- a/src/GUI/AircraftSearchFilterModel.hxx +++ b/src/GUI/AircraftSearchFilterModel.hxx @@ -19,6 +19,8 @@ public: Q_INVOKABLE void setAircraftFilterString(QString s); + Q_PROPERTY(int count READ count NOTIFY countChanged) + /** * Compute the row (index in QML / ListView speak) based on an aircraft URI. * Return -1 if the UIR is not present in the (filtered) model @@ -41,15 +43,19 @@ public: void setRatingFilterEnabled(bool e); QString summaryText() const; + + int count() const; signals: void ratingsChanged(); void ratingsFilterEnabledChanged(); void summaryTextChanged(); + void countChanged(); public slots: void setInstalledFilterEnabled(bool e); + void setHaveUpdateFilterEnabled(bool e); protected: bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; @@ -58,6 +64,8 @@ private: bool m_ratingsFilter = true; bool m_onlyShowInstalled = false; + bool m_onlyShowWithUpdate = false; + QList m_ratings; QString m_filterString; SGPropertyNode_ptr m_filterProps; diff --git a/src/GUI/LauncherController.cxx b/src/GUI/LauncherController.cxx index 2c1886802..8620acac5 100644 --- a/src/GUI/LauncherController.cxx +++ b/src/GUI/LauncherController.cxx @@ -75,6 +75,10 @@ LauncherController::LauncherController(QObject *parent, QWindow* window) : m_installedAircraftModel = new AircraftProxyModel(this, m_aircraftModel); m_installedAircraftModel->setInstalledFilterEnabled(true); + m_aircraftWithUpdatesModel = new AircraftProxyModel(this, m_aircraftModel); + m_aircraftWithUpdatesModel->setInstalledFilterEnabled(true); + m_aircraftWithUpdatesModel->setHaveUpdateFilterEnabled(true); + m_browseAircraftModel = new AircraftProxyModel(this, m_aircraftModel); m_browseAircraftModel->setRatingFilterEnabled(true); diff --git a/src/GUI/LauncherController.hxx b/src/GUI/LauncherController.hxx index ef160187f..ef826a8d2 100644 --- a/src/GUI/LauncherController.hxx +++ b/src/GUI/LauncherController.hxx @@ -46,6 +46,7 @@ class LauncherController : public QObject Q_OBJECT Q_PROPERTY(AircraftProxyModel* installedAircraftModel MEMBER m_installedAircraftModel CONSTANT) + Q_PROPERTY(AircraftProxyModel* aircraftWithUpdatesModel MEMBER m_aircraftWithUpdatesModel CONSTANT) Q_PROPERTY(AircraftProxyModel* browseAircraftModel MEMBER m_browseAircraftModel CONSTANT) Q_PROPERTY(AircraftProxyModel* searchAircraftModel MEMBER m_aircraftSearchModel CONSTANT) @@ -230,6 +231,7 @@ private: AircraftItemModel* m_aircraftModel; AircraftProxyModel* m_aircraftSearchModel; AircraftProxyModel* m_browseAircraftModel; + AircraftProxyModel* m_aircraftWithUpdatesModel; MPServersModel* m_serversModel = nullptr; LocationController* m_location = nullptr; diff --git a/src/GUI/qml/AircraftList.qml b/src/GUI/qml/AircraftList.qml index d1e23de29..3e6c1c639 100644 --- a/src/GUI/qml/AircraftList.qml +++ b/src/GUI/qml/AircraftList.qml @@ -39,6 +39,17 @@ Item } active: root.state == "browse" } + + TabButton { + id: updatesButton + // visible: _launcher.baseAircraftModel.showUpdateAll + text: qsTr("Updates") + onClicked: { + root.state = "updates" + aircraftList.updateSelectionFromLauncher(); + } + active: root.state == "updates" + } } // of header row SearchButton { @@ -154,6 +165,21 @@ Item } } + StyledText { + id: noUpdatesMessage + anchors { + left: parent.left + top: tabBar.bottom + bottom: parent.bottom + right: scrollbar.left + } + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + font.pixelSize: Style.headingFontPixelSize + text: qsTr("No aircraft updates available right now") + visible: (root.state == "updates") && (_launcher.aircraftWithUpdatesModel.count == 0) + } + Scrollbar { id: scrollbar anchors.right: parent.right @@ -170,7 +196,6 @@ Item PropertyChanges { target: aircraftList model: _launcher.installedAircraftModel - header: _launcher.baseAircraftModel.showUpdateAll ? updateAllHeader : null } }, @@ -190,6 +215,15 @@ Item model: _launcher.browseAircraftModel header: _addOns.showNoOfficialHangar ? noDefaultCatalogHeader : ratingsHeader } + }, + + State { + name: "updates" + PropertyChanges { + target: aircraftList + model: _launcher.aircraftWithUpdatesModel + header: (_launcher.aircraftWithUpdatesModel.count > 0) ? updateAllHeader : null + } } ] diff --git a/src/GUI/qml/UpdateAllPanel.qml b/src/GUI/qml/UpdateAllPanel.qml index 2a1c1eff0..b14a9f27d 100644 --- a/src/GUI/qml/UpdateAllPanel.qml +++ b/src/GUI/qml/UpdateAllPanel.qml @@ -16,7 +16,7 @@ ListHeaderBox { } text: qsTr("%1 aircraft have updates available - download and install them now?"). - arg( _launcher.baseAircraftModel.aircraftNeedingUpdated); + arg(_launcher.aircraftWithUpdatesModel.count) wrapMode: Text.WordWrap }, @@ -24,24 +24,11 @@ ListHeaderBox { id: updateAllButton text: qsTr("Update all") anchors.verticalCenter: parent.verticalCenter - anchors.right: notNowButton.left - anchors.rightMargin: Style.margin - - onClicked: { - _launcher.requestUpdateAllAircraft(); - _launcher.baseAircraftModel.showUpdateAll = false - } - }, - - Button { - id: notNowButton - text: qsTr("Not now") - anchors.verticalCenter: parent.verticalCenter anchors.right: parent.right anchors.rightMargin: Style.margin onClicked: { - _launcher.baseAircraftModel.showUpdateAll = false + _launcher.requestUpdateAllAircraft(); } } ]