1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-17 03:24:15 +02:00

RETHINK MUSIC COMMIT #1!!1!!11! Implement a way to set a custom delegate in job view items

This commit is contained in:
Jeff Mitchell
2012-04-21 10:39:21 -04:00
parent 53e97e75da
commit c84cfc8bf0
6 changed files with 30 additions and 1 deletions

View File

@@ -40,3 +40,8 @@ bool JobStatusItem::collapseItem() const
{ {
return false; return false;
} }
QStyledItemDelegate* JobStatusItem::customDelegate() const
{
return 0;
}

View File

@@ -21,6 +21,7 @@
#include <QObject> #include <QObject>
class QStyledItemDelegate;
class QPixmap; class QPixmap;
/** /**
@@ -56,6 +57,8 @@ public:
virtual bool collapseItem() const; virtual bool collapseItem() const;
virtual bool allowMultiLine() const; virtual bool allowMultiLine() const;
virtual QStyledItemDelegate* customDelegate() const;
signals: signals:
/// Ask for an update /// Ask for an update
void statusChanged(); void statusChanged();

View File

@@ -60,9 +60,12 @@ JobStatusModel::addJob( JobStatusItem* item )
} }
qDebug() << "Adding item:" << item; qDebug() << "Adding item:" << item;
beginInsertRows( QModelIndex(), m_items.count(), m_items.count() ); int currentEndRow = m_items.count();
beginInsertRows( QModelIndex(), currentEndRow, currentEndRow );
m_items.append( item ); m_items.append( item );
endInsertRows(); endInsertRows();
if ( item->customDelegate() )
emit customDelegateJobInserted( currentEndRow, item->customDelegate() );
} }

View File

@@ -23,7 +23,9 @@
#include <QModelIndex> #include <QModelIndex>
class QStyledItemDelegate;
class JobStatusItem; class JobStatusItem;
class DLLEXPORT JobStatusModel : public QAbstractListModel class DLLEXPORT JobStatusModel : public QAbstractListModel
{ {
Q_OBJECT Q_OBJECT
@@ -45,6 +47,9 @@ public:
/// Takes ownership of job /// Takes ownership of job
void addJob( JobStatusItem* item ); void addJob( JobStatusItem* item );
signals:
void customDelegateJobInserted( int row, QStyledItemDelegate* delegate );
private slots: private slots:
void itemUpdated(); void itemUpdated();
void itemFinished(); void itemFinished();

View File

@@ -86,6 +86,17 @@ JobStatusView::setModel( JobStatusModel* m )
connect( m_view->model(), SIGNAL( rowsInserted( QModelIndex, int, int ) ), this, SLOT( checkCount() ) ); connect( m_view->model(), SIGNAL( rowsInserted( QModelIndex, int, int ) ), this, SLOT( checkCount() ) );
connect( m_view->model(), SIGNAL( rowsRemoved( QModelIndex, int, int ) ), this, SLOT( checkCount() ) ); connect( m_view->model(), SIGNAL( rowsRemoved( QModelIndex, int, int ) ), this, SLOT( checkCount() ) );
connect( m_view->model(), SIGNAL( modelReset() ), this, SLOT( checkCount() ) ); connect( m_view->model(), SIGNAL( modelReset() ), this, SLOT( checkCount() ) );
connect( m_view->model(), SIGNAL( customDelegateJobInserted( int, QStyledItemDelegate* ) ), this, SLOT( customDelegateJobInserted( int, QStyledItemDelegate* ) ) );
}
void
JobStatusView::customDelegateJobInserted( int row, QStyledItemDelegate* delegate )
{
if ( !delegate )
return;
m_view->setItemDelegateForRow( row, delegate );
} }

View File

@@ -28,6 +28,7 @@ class QAbstractItemModel;
class QListView; class QListView;
class JobStatusModel; class JobStatusModel;
class StreamConnection; class StreamConnection;
class QStyledItemDelegate;
class DLLEXPORT JobStatusView : public AnimatedWidget class DLLEXPORT JobStatusView : public AnimatedWidget
{ {
@@ -51,6 +52,7 @@ public:
private slots: private slots:
void checkCount(); void checkCount();
void customDelegateJobInserted( int row, QStyledItemDelegate* delegate );
private: private:
QListView* m_view; QListView* m_view;