1
0
Fork 0

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/
This commit is contained in:
James Turner 2018-07-23 09:10:08 +01:00
parent ec004d8c6b
commit f3a1c10b24
5 changed files with 26 additions and 16 deletions

View file

@ -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<const char*>(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<int>(newPkgs.size());
const int newTotalSize = firstRow + newSize;
if (m_packages.size() != newPkgs.size()) {
int oldSize = m_packages.size();
const int oldSize = static_cast<int>(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<int>(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<int>(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()

View file

@ -112,8 +112,7 @@ signals:
void aircraftInstallCompleted(QModelIndex index);
void catalogsRefreshed();
void contentsChanged();
private slots:
void onScanStarted();
void onScanAddedItems(int count);

View file

@ -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<quint32>(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<LocalAircraftCache> static_cacheInstance;
static std::unique_ptr<LocalAircraftCache> static_cacheInstance;
LocalAircraftCache* LocalAircraftCache::instance()
{

View file

@ -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));
}

View file

@ -35,6 +35,8 @@ signals:
void isEmptyChanged();
private:
void onModelContentsChanged();
AircraftItemModel* m_aircraftModel;
QList<QUrl> m_data;
};