1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-17 03:45:56 +01:00

Update the moodbar column on the correct model

This commit is contained in:
David Sansome 2012-05-30 11:06:41 +01:00
parent ba2f4ddedc
commit 836a2b0c89
3 changed files with 18 additions and 5 deletions

View File

@ -23,10 +23,12 @@
#include "core/closure.h"
#include "core/qhash_qurl.h"
#include "playlist/playlist.h"
#include "playlist/playlistview.h"
#include <QApplication>
#include <QPainter>
#include <QSettings>
#include <QSortFilterProxyModel>
#include <QtConcurrentRun>
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()));
@ -245,11 +249,18 @@ void MoodbarItemDelegate::ImageLoaded(const QUrl& url, QFutureWatcher<QImage>* 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<Playlist*>(reinterpret_cast<const Playlist*>(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);
}
}
}

View File

@ -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<QUrl, Data> data_;
MoodbarRenderer::MoodbarStyle style_;

View File

@ -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()) {