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:
parent
ec004d8c6b
commit
f3a1c10b24
5 changed files with 26 additions and 16 deletions
|
@ -51,13 +51,13 @@ public:
|
||||||
m_model->m_packageRoot->addDelegate(this);
|
m_model->m_packageRoot->addDelegate(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
~PackageDelegate()
|
~PackageDelegate() override
|
||||||
{
|
{
|
||||||
m_model->m_packageRoot->removeDelegate(this);
|
m_model->m_packageRoot->removeDelegate(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void catalogRefreshed(CatalogRef aCatalog, StatusCode aReason)
|
void catalogRefreshed(CatalogRef aCatalog, StatusCode aReason) override
|
||||||
{
|
{
|
||||||
if (aReason == STATUS_IN_PROGRESS) {
|
if (aReason == STATUS_IN_PROGRESS) {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
|
@ -66,9 +66,7 @@ protected:
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "failed refresh of"
|
qWarning() << "failed refresh of"
|
||||||
<< QString::fromStdString(aCatalog->url()) << ":" << aReason << endl;
|
<< QString::fromStdString(aCatalog->url()) << ":" << aReason << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_model->catalogsRefreshed();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void startInstall(InstallRef aInstall) override
|
void startInstall(InstallRef aInstall) override
|
||||||
|
@ -119,7 +117,7 @@ protected:
|
||||||
|
|
||||||
|
|
||||||
virtual void dataForThumbnail(const std::string& aThumbnailUrl,
|
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));
|
QImage img = QImage::fromData(QByteArray::fromRawData(reinterpret_cast<const char*>(bytes), length));
|
||||||
if (img.isNull()) {
|
if (img.isNull()) {
|
||||||
|
@ -220,11 +218,11 @@ void AircraftItemModel::refreshPackages()
|
||||||
{
|
{
|
||||||
simgear::pkg::PackageList newPkgs = m_packageRoot->allPackages();
|
simgear::pkg::PackageList newPkgs = m_packageRoot->allPackages();
|
||||||
const int firstRow = m_cachedLocalAircraftCount;
|
const int firstRow = m_cachedLocalAircraftCount;
|
||||||
const int newSize = newPkgs.size();
|
const int newSize = static_cast<int>(newPkgs.size());
|
||||||
const int newTotalSize = firstRow + newSize;
|
const int newTotalSize = firstRow + newSize;
|
||||||
|
|
||||||
if (m_packages.size() != newPkgs.size()) {
|
if (m_packages.size() != newPkgs.size()) {
|
||||||
int oldSize = m_packages.size();
|
const int oldSize = static_cast<int>(m_packages.size());
|
||||||
if (newSize > oldSize) {
|
if (newSize > oldSize) {
|
||||||
// growing
|
// growing
|
||||||
int firstNewRow = firstRow + oldSize;
|
int firstNewRow = firstRow + oldSize;
|
||||||
|
@ -247,11 +245,12 @@ void AircraftItemModel::refreshPackages()
|
||||||
}
|
}
|
||||||
|
|
||||||
emit dataChanged(index(firstRow), index(firstRow + newSize - 1));
|
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
|
QVariant AircraftItemModel::data(const QModelIndex& index, int role) const
|
||||||
|
@ -586,7 +585,7 @@ void AircraftItemModel::selectVariantForAircraftURI(QUrl uri)
|
||||||
if (pkg) {
|
if (pkg) {
|
||||||
for (size_t i=0; i < m_packages.size(); ++i) {
|
for (size_t i=0; i < m_packages.size(); ++i) {
|
||||||
if (m_packages[i] == pkg) {
|
if (m_packages[i] == pkg) {
|
||||||
modelIndex = index(rowOffset + i);
|
modelIndex = index(rowOffset + static_cast<int>(i));
|
||||||
variantIndex = pkg->indexOfVariant(ident.toStdString());
|
variantIndex = pkg->indexOfVariant(ident.toStdString());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -648,6 +647,7 @@ void AircraftItemModel::onScanAddedItems(int addedCount)
|
||||||
m_delegateStates.insert(m_cachedLocalAircraftCount, newItemCount, {});
|
m_delegateStates.insert(m_cachedLocalAircraftCount, newItemCount, {});
|
||||||
m_cachedLocalAircraftCount += newItemCount;
|
m_cachedLocalAircraftCount += newItemCount;
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
emit contentsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AircraftItemModel::onLocalCacheCleared()
|
void AircraftItemModel::onLocalCacheCleared()
|
||||||
|
|
|
@ -112,8 +112,7 @@ signals:
|
||||||
|
|
||||||
void aircraftInstallCompleted(QModelIndex index);
|
void aircraftInstallCompleted(QModelIndex index);
|
||||||
|
|
||||||
void catalogsRefreshed();
|
void contentsChanged();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onScanStarted();
|
void onScanStarted();
|
||||||
void onScanAddedItems(int count);
|
void onScanAddedItems(int count);
|
||||||
|
|
|
@ -198,6 +198,7 @@ int AircraftItem::indexOfVariant(QUrl uri) const
|
||||||
|
|
||||||
QVariant AircraftItem::status(int variant)
|
QVariant AircraftItem::status(int variant)
|
||||||
{
|
{
|
||||||
|
Q_UNUSED(variant)
|
||||||
if (needsMaintenance) {
|
if (needsMaintenance) {
|
||||||
return LocalAircraftCache::AircraftUnmaintained;
|
return LocalAircraftCache::AircraftUnmaintained;
|
||||||
}
|
}
|
||||||
|
@ -294,7 +295,7 @@ private:
|
||||||
QByteArray cacheData;
|
QByteArray cacheData;
|
||||||
{
|
{
|
||||||
QDataStream ds(&cacheData, QIODevice::WriteOnly);
|
QDataStream ds(&cacheData, QIODevice::WriteOnly);
|
||||||
quint32 count = m_nextCache.count();
|
quint32 count = static_cast<quint32>(m_nextCache.count());
|
||||||
ds << CACHE_VERSION << count;
|
ds << CACHE_VERSION << count;
|
||||||
|
|
||||||
Q_FOREACH(AircraftItemPtr item, m_nextCache.values()) {
|
Q_FOREACH(AircraftItemPtr item, m_nextCache.values()) {
|
||||||
|
@ -387,7 +388,7 @@ private:
|
||||||
bool m_done;
|
bool m_done;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::unique_ptr<LocalAircraftCache> static_cacheInstance;
|
static std::unique_ptr<LocalAircraftCache> static_cacheInstance;
|
||||||
|
|
||||||
LocalAircraftCache* LocalAircraftCache::instance()
|
LocalAircraftCache* LocalAircraftCache::instance()
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,6 +15,9 @@ RecentAircraftModel::RecentAircraftModel(AircraftItemModel* acModel, QObject* pr
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
const QStringList urls = settings.value("recent-aircraft").toStringList();
|
const QStringList urls = settings.value("recent-aircraft").toStringList();
|
||||||
m_data = QUrl::fromStringList(urls);
|
m_data = QUrl::fromStringList(urls);
|
||||||
|
|
||||||
|
connect(m_aircraftModel, &AircraftItemModel::contentsChanged,
|
||||||
|
this, &RecentAircraftModel::onModelContentsChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RecentAircraftModel::saveToSettings()
|
void RecentAircraftModel::saveToSettings()
|
||||||
|
@ -45,7 +48,7 @@ QVariant RecentAircraftModel::data(const QModelIndex &index, int role) const
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
int RecentAircraftModel::rowCount(const QModelIndex &parent) const
|
int RecentAircraftModel::rowCount(const QModelIndex&) const
|
||||||
{
|
{
|
||||||
return m_data.size();
|
return m_data.size();
|
||||||
}
|
}
|
||||||
|
@ -97,3 +100,8 @@ void RecentAircraftModel::insert(QUrl aircraftUrl)
|
||||||
|
|
||||||
emit isEmptyChanged();
|
emit isEmptyChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RecentAircraftModel::onModelContentsChanged()
|
||||||
|
{
|
||||||
|
emit dataChanged(index(0), index(m_data.size() - 1));
|
||||||
|
}
|
||||||
|
|
|
@ -35,6 +35,8 @@ signals:
|
||||||
void isEmptyChanged();
|
void isEmptyChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void onModelContentsChanged();
|
||||||
|
|
||||||
AircraftItemModel* m_aircraftModel;
|
AircraftItemModel* m_aircraftModel;
|
||||||
QList<QUrl> m_data;
|
QList<QUrl> m_data;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue