diff --git a/src/moodbar/moodbaritemdelegate.cpp b/src/moodbar/moodbaritemdelegate.cpp index 2f83518f4..345e688e8 100644 --- a/src/moodbar/moodbaritemdelegate.cpp +++ b/src/moodbar/moodbaritemdelegate.cpp @@ -23,10 +23,12 @@ #include "core/closure.h" #include "core/qhash_qurl.h" #include "playlist/playlist.h" +#include "playlist/playlistview.h" #include #include #include +#include #include MoodbarItemDelegate::Data::Data() @@ -34,9 +36,11 @@ MoodbarItemDelegate::Data::Data() { } -MoodbarItemDelegate::MoodbarItemDelegate(Application* app, QObject* parent) +MoodbarItemDelegate::MoodbarItemDelegate(Application* app, PlaylistView* view, + QObject* parent) : QItemDelegate(parent), app_(app), + view_(view), style_(MoodbarRenderer::Style_Normal) { connect(app_, SIGNAL(SettingsChanged()), SLOT(ReloadSettings())); @@ -244,12 +248,19 @@ void MoodbarItemDelegate::ImageLoaded(const QUrl& url, QFutureWatcher* w data->pixmap_ = QPixmap::fromImage(image); data->state_ = Data::State_Loaded; + + Playlist* playlist = view_->playlist(); + const QSortFilterProxyModel* filter = playlist->proxy(); // Update all the indices with the new pixmap. foreach (const QPersistentModelIndex& index, data->indexes_) { if (index.isValid() && index.sibling(index.row(), Playlist::Column_Filename).data().toUrl() == url) { - const_cast(reinterpret_cast(index.model())) - ->MoodbarUpdated(index); + Q_ASSERT(index.model() == filter); + QModelIndex source_index(filter->mapToSource(index)); + + Q_ASSERT(source_index.model() == playlist); + + playlist->MoodbarUpdated(source_index); } } } diff --git a/src/moodbar/moodbaritemdelegate.h b/src/moodbar/moodbaritemdelegate.h index aca4570ac..413326875 100644 --- a/src/moodbar/moodbaritemdelegate.h +++ b/src/moodbar/moodbaritemdelegate.h @@ -27,6 +27,7 @@ class Application; class MoodbarPipeline; +class PlaylistView; class QModelIndex; @@ -34,7 +35,7 @@ class MoodbarItemDelegate : public QItemDelegate { Q_OBJECT public: - MoodbarItemDelegate(Application* app, QObject* parent = 0); + MoodbarItemDelegate(Application* app, PlaylistView* view, QObject* parent = 0); void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; @@ -79,6 +80,7 @@ private: private: Application* app_; + PlaylistView* view_; QCache data_; MoodbarRenderer::MoodbarStyle style_; diff --git a/src/playlist/playlistview.cpp b/src/playlist/playlistview.cpp index db3b320a1..543d7c95e 100644 --- a/src/playlist/playlistview.cpp +++ b/src/playlist/playlistview.cpp @@ -205,7 +205,7 @@ void PlaylistView::SetItemDelegates(LibraryBackend* backend) { setItemDelegateForColumn(Playlist::Column_LastPlayed, new LastPlayedItemDelegate(this)); #ifdef HAVE_MOODBAR - setItemDelegateForColumn(Playlist::Column_Mood, new MoodbarItemDelegate(app_, this)); + setItemDelegateForColumn(Playlist::Column_Mood, new MoodbarItemDelegate(app_, this, this)); #endif if (app_ && app_->player()) {