From 36331dc253e151edb6574fa2ca295b79cfa3d312 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Mon, 25 Nov 2019 22:25:29 +0100 Subject: [PATCH] Fix removing nodes from pending art --- src/collection/collectionmodel.cpp | 38 ++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/src/collection/collectionmodel.cpp b/src/collection/collectionmodel.cpp index 72623798c..944fe537d 100644 --- a/src/collection/collectionmodel.cpp +++ b/src/collection/collectionmodel.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -439,21 +440,26 @@ void CollectionModel::SongsDeleted(const SongList &songs) { // Remove from pixmap cache const QString cache_key = AlbumIconPixmapCacheKey(idx); 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 - QMapIterator i(pending_art_); - while (i.hasNext()) { - i.next(); - if (i.value().first == node) { - pending_art_.remove(i.key()); - break; + QMap::iterator i = pending_art_.begin(); + while (i != pending_art_.end()) { + if (i.value().first == node->parent) { + i = pending_art_.erase(i); + } + else { + ++i; } } + beginRemoveRows(idx, node->row, node->row); node->parent->Delete(node->row); song_nodes_.remove(song.id()); endRemoveRows(); + } else { // 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 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::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 beginRemoveRows(ItemToIndex(node->parent), node->row, node->row); node->parent->Delete(node->row);