Fix removing nodes from pending art

This commit is contained in:
Jonas Kvinge
2019-11-25 22:25:29 +01:00
parent 4265cf31b2
commit 36331dc253

View File

@@ -37,6 +37,7 @@
#include <QVariant> #include <QVariant>
#include <QList> #include <QList>
#include <QSet> #include <QSet>
#include <QMap>
#include <QChar> #include <QChar>
#include <QRegExp> #include <QRegExp>
#include <QString> #include <QString>
@@ -439,21 +440,26 @@ void CollectionModel::SongsDeleted(const SongList &songs) {
// Remove from pixmap cache // Remove from pixmap cache
const QString cache_key = AlbumIconPixmapCacheKey(idx); const QString cache_key = AlbumIconPixmapCacheKey(idx);
QPixmapCache::remove(cache_key); QPixmapCache::remove(cache_key);
if (pending_cache_keys_.contains(cache_key)) pending_cache_keys_.remove(cache_key); if (pending_cache_keys_.contains(cache_key)) {
pending_cache_keys_.remove(cache_key);
}
// Remove from pending art loading // Remove from pending art loading
QMapIterator<quint64, ItemAndCacheKey> i(pending_art_); QMap<quint64, ItemAndCacheKey>::iterator i = pending_art_.begin();
while (i.hasNext()) { while (i != pending_art_.end()) {
i.next(); if (i.value().first == node->parent) {
if (i.value().first == node) { i = pending_art_.erase(i);
pending_art_.remove(i.key()); }
break; else {
++i;
} }
} }
beginRemoveRows(idx, node->row, node->row); beginRemoveRows(idx, node->row, node->row);
node->parent->Delete(node->row); node->parent->Delete(node->row);
song_nodes_.remove(song.id()); song_nodes_.remove(song.id());
endRemoveRows(); endRemoveRows();
} }
else { else {
// If we get here it means some of the songs we want to delete haven't been lazy-loaded yet. // If we get here it means some of the songs we want to delete haven't been lazy-loaded yet.
@@ -487,6 +493,24 @@ void CollectionModel::SongsDeleted(const SongList &songs) {
else else
container_nodes_[node->container_level].remove(node->key); container_nodes_[node->container_level].remove(node->key);
// Remove from pixmap cache
const QString cache_key = AlbumIconPixmapCacheKey(ItemToIndex(node));
QPixmapCache::remove(cache_key);
if (pending_cache_keys_.contains(cache_key)) {
pending_cache_keys_.remove(cache_key);
}
// Remove from pending art loading
QMap<quint64, ItemAndCacheKey>::iterator i = pending_art_.begin();
while (i != pending_art_.end()) {
if (i.value().first == node) {
i = pending_art_.erase(i);
}
else {
++i;
}
}
// It was empty - delete it // It was empty - delete it
beginRemoveRows(ItemToIndex(node->parent), node->row, node->row); beginRemoveRows(ItemToIndex(node->parent), node->row, node->row);
node->parent->Delete(node->row); node->parent->Delete(node->row);