From f3a1c10b24d839368276df420be90b7e3ba2007a Mon Sep 17 00:00:00 2001 From: James Turner Date: Mon, 23 Jul 2018 09:10:08 +0100 Subject: [PATCH] Fix bug #2306 - missed refresh of the history model The HistoryPopup was caching its contents rather early, and we failed to tell the model when its underlying data updated. Connect that through so the history model refreshes also. https://sourceforge.net/p/flightgear/codetickets/2036/ --- src/GUI/AircraftModel.cxx | 22 +++++++++++----------- src/GUI/AircraftModel.hxx | 3 +-- src/GUI/LocalAircraftCache.cxx | 5 +++-- src/GUI/RecentAircraftModel.cxx | 10 +++++++++- src/GUI/RecentAircraftModel.hxx | 2 ++ 5 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/GUI/AircraftModel.cxx b/src/GUI/AircraftModel.cxx index 54ca58ea8..b1a8443de 100644 --- a/src/GUI/AircraftModel.cxx +++ b/src/GUI/AircraftModel.cxx @@ -51,13 +51,13 @@ public: m_model->m_packageRoot->addDelegate(this); } - ~PackageDelegate() + ~PackageDelegate() override { m_model->m_packageRoot->removeDelegate(this); } protected: - virtual void catalogRefreshed(CatalogRef aCatalog, StatusCode aReason) + void catalogRefreshed(CatalogRef aCatalog, StatusCode aReason) override { if (aReason == STATUS_IN_PROGRESS) { // nothing to do @@ -66,9 +66,7 @@ protected: } else { qWarning() << "failed refresh of" << QString::fromStdString(aCatalog->url()) << ":" << aReason << endl; - } - - m_model->catalogsRefreshed(); + } } void startInstall(InstallRef aInstall) override @@ -119,7 +117,7 @@ protected: virtual void dataForThumbnail(const std::string& aThumbnailUrl, - size_t length, const uint8_t* bytes) + size_t length, const uint8_t* bytes) override { QImage img = QImage::fromData(QByteArray::fromRawData(reinterpret_cast(bytes), length)); if (img.isNull()) { @@ -220,11 +218,11 @@ void AircraftItemModel::refreshPackages() { simgear::pkg::PackageList newPkgs = m_packageRoot->allPackages(); const int firstRow = m_cachedLocalAircraftCount; - const int newSize = newPkgs.size(); + const int newSize = static_cast(newPkgs.size()); const int newTotalSize = firstRow + newSize; if (m_packages.size() != newPkgs.size()) { - int oldSize = m_packages.size(); + const int oldSize = static_cast(m_packages.size()); if (newSize > oldSize) { // growing int firstNewRow = firstRow + oldSize; @@ -247,11 +245,12 @@ void AircraftItemModel::refreshPackages() } emit dataChanged(index(firstRow), index(firstRow + newSize - 1)); + emit contentsChanged(); } -int AircraftItemModel::rowCount(const QModelIndex& parent) const +int AircraftItemModel::rowCount(const QModelIndex&) const { - return m_cachedLocalAircraftCount + m_packages.size(); + return m_cachedLocalAircraftCount + static_cast(m_packages.size()); } QVariant AircraftItemModel::data(const QModelIndex& index, int role) const @@ -586,7 +585,7 @@ void AircraftItemModel::selectVariantForAircraftURI(QUrl uri) if (pkg) { for (size_t i=0; i < m_packages.size(); ++i) { if (m_packages[i] == pkg) { - modelIndex = index(rowOffset + i); + modelIndex = index(rowOffset + static_cast(i)); variantIndex = pkg->indexOfVariant(ident.toStdString()); break; } @@ -648,6 +647,7 @@ void AircraftItemModel::onScanAddedItems(int addedCount) m_delegateStates.insert(m_cachedLocalAircraftCount, newItemCount, {}); m_cachedLocalAircraftCount += newItemCount; endInsertRows(); + emit contentsChanged(); } void AircraftItemModel::onLocalCacheCleared() diff --git a/src/GUI/AircraftModel.hxx b/src/GUI/AircraftModel.hxx index 28da1d617..96e5680ef 100644 --- a/src/GUI/AircraftModel.hxx +++ b/src/GUI/AircraftModel.hxx @@ -112,8 +112,7 @@ signals: void aircraftInstallCompleted(QModelIndex index); - void catalogsRefreshed(); - + void contentsChanged(); private slots: void onScanStarted(); void onScanAddedItems(int count); diff --git a/src/GUI/LocalAircraftCache.cxx b/src/GUI/LocalAircraftCache.cxx index c35588a84..c79bfbd68 100644 --- a/src/GUI/LocalAircraftCache.cxx +++ b/src/GUI/LocalAircraftCache.cxx @@ -198,6 +198,7 @@ int AircraftItem::indexOfVariant(QUrl uri) const QVariant AircraftItem::status(int variant) { + Q_UNUSED(variant) if (needsMaintenance) { return LocalAircraftCache::AircraftUnmaintained; } @@ -294,7 +295,7 @@ private: QByteArray cacheData; { QDataStream ds(&cacheData, QIODevice::WriteOnly); - quint32 count = m_nextCache.count(); + quint32 count = static_cast(m_nextCache.count()); ds << CACHE_VERSION << count; Q_FOREACH(AircraftItemPtr item, m_nextCache.values()) { @@ -387,7 +388,7 @@ private: bool m_done; }; -std::unique_ptr static_cacheInstance; +static std::unique_ptr static_cacheInstance; LocalAircraftCache* LocalAircraftCache::instance() { diff --git a/src/GUI/RecentAircraftModel.cxx b/src/GUI/RecentAircraftModel.cxx index 162a313a2..9fad02def 100644 --- a/src/GUI/RecentAircraftModel.cxx +++ b/src/GUI/RecentAircraftModel.cxx @@ -15,6 +15,9 @@ RecentAircraftModel::RecentAircraftModel(AircraftItemModel* acModel, QObject* pr QSettings settings; const QStringList urls = settings.value("recent-aircraft").toStringList(); m_data = QUrl::fromStringList(urls); + + connect(m_aircraftModel, &AircraftItemModel::contentsChanged, + this, &RecentAircraftModel::onModelContentsChanged); } void RecentAircraftModel::saveToSettings() @@ -45,7 +48,7 @@ QVariant RecentAircraftModel::data(const QModelIndex &index, int role) const return {}; } -int RecentAircraftModel::rowCount(const QModelIndex &parent) const +int RecentAircraftModel::rowCount(const QModelIndex&) const { return m_data.size(); } @@ -97,3 +100,8 @@ void RecentAircraftModel::insert(QUrl aircraftUrl) emit isEmptyChanged(); } + +void RecentAircraftModel::onModelContentsChanged() +{ + emit dataChanged(index(0), index(m_data.size() - 1)); +} diff --git a/src/GUI/RecentAircraftModel.hxx b/src/GUI/RecentAircraftModel.hxx index 35bd36954..57ee361e2 100644 --- a/src/GUI/RecentAircraftModel.hxx +++ b/src/GUI/RecentAircraftModel.hxx @@ -35,6 +35,8 @@ signals: void isEmptyChanged(); private: + void onModelContentsChanged(); + AircraftItemModel* m_aircraftModel; QList m_data; };