mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-13 20:39:57 +01:00
Add acl job queue and custom delegate removal capability
This commit is contained in:
parent
c84cfc8bf0
commit
1695b39abf
@ -20,6 +20,7 @@
|
||||
#define JOB_STATUS_ITEM
|
||||
|
||||
#include <QObject>
|
||||
#include <QMetaType>
|
||||
|
||||
class QStyledItemDelegate;
|
||||
class QPixmap;
|
||||
@ -67,4 +68,6 @@ signals:
|
||||
void finished();
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE( JobStatusItem* );
|
||||
|
||||
#endif
|
||||
|
@ -26,6 +26,7 @@
|
||||
|
||||
JobStatusModel::JobStatusModel( QObject* parent )
|
||||
: QAbstractListModel ( parent )
|
||||
, m_aclJobCount( 0 )
|
||||
{
|
||||
|
||||
}
|
||||
@ -41,6 +42,12 @@ JobStatusModel::~JobStatusModel()
|
||||
void
|
||||
JobStatusModel::addJob( JobStatusItem* item )
|
||||
{
|
||||
if ( item->type() == "acljob" && m_aclJobCount >= 3 )
|
||||
{
|
||||
m_aclJobQueue.enqueue( item );
|
||||
return;
|
||||
}
|
||||
|
||||
connect( item, SIGNAL( statusChanged() ), this, SLOT( itemUpdated() ) );
|
||||
connect( item, SIGNAL( finished() ), this, SLOT( itemFinished() ) );
|
||||
|
||||
@ -174,7 +181,19 @@ JobStatusModel::itemFinished()
|
||||
m_items.removeAll( item );
|
||||
endRemoveRows();
|
||||
|
||||
if ( item->customDelegate() )
|
||||
emit customDelegateJobRemoved( idx, item->customDelegate() );
|
||||
|
||||
if ( item->type() == "acljob" )
|
||||
m_aclJobCount--;
|
||||
|
||||
item->deleteLater();
|
||||
|
||||
if ( !m_aclJobQueue.empty() )
|
||||
{
|
||||
JobStatusItem* item = m_aclJobQueue.dequeue();
|
||||
QMetaObject::invokeMethod( this, "addJob", Qt::QueuedConnection, Q_ARG( JobStatusItem*, item ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "dllmacro.h"
|
||||
|
||||
#include <QModelIndex>
|
||||
#include <QQueue>
|
||||
|
||||
class QStyledItemDelegate;
|
||||
class JobStatusItem;
|
||||
@ -44,11 +45,13 @@ public:
|
||||
virtual QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const;
|
||||
virtual int rowCount( const QModelIndex& parent = QModelIndex() ) const;
|
||||
|
||||
/// Takes ownership of job
|
||||
void addJob( JobStatusItem* item );
|
||||
|
||||
signals:
|
||||
void customDelegateJobInserted( int row, QStyledItemDelegate* delegate );
|
||||
void customDelegateJobRemoved( int row, QStyledItemDelegate* delegate );
|
||||
|
||||
public slots:
|
||||
/// Takes ownership of job
|
||||
void addJob( JobStatusItem* item );
|
||||
|
||||
private slots:
|
||||
void itemUpdated();
|
||||
@ -57,6 +60,8 @@ private slots:
|
||||
private:
|
||||
QList< JobStatusItem* > m_items;
|
||||
QHash< QString, QList< JobStatusItem* > > m_collapseCount;
|
||||
QQueue< JobStatusItem* > m_aclJobQueue;
|
||||
int m_aclJobCount;
|
||||
};
|
||||
|
||||
#endif // JOBSTATUSMODEL_H
|
||||
|
@ -87,6 +87,7 @@ JobStatusView::setModel( JobStatusModel* m )
|
||||
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( customDelegateJobInserted( int, QStyledItemDelegate* ) ), this, SLOT( customDelegateJobInserted( int, QStyledItemDelegate* ) ) );
|
||||
connect( m_view->model(), SIGNAL( customDelegateJobRemoved( int, QStyledItemDelegate* ) ), this, SLOT( customDelegateJobRemoved( int, QStyledItemDelegate* ) ) );
|
||||
}
|
||||
|
||||
|
||||
@ -100,6 +101,16 @@ JobStatusView::customDelegateJobInserted( int row, QStyledItemDelegate* delegate
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
JobStatusView::customDelegateJobRemoved( int row, QStyledItemDelegate* delegate )
|
||||
{
|
||||
if ( !delegate )
|
||||
return;
|
||||
|
||||
m_view->setItemDelegateForRow( row, m_view->itemDelegate() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
JobStatusView::checkCount()
|
||||
{
|
||||
|
@ -53,6 +53,7 @@ public:
|
||||
private slots:
|
||||
void checkCount();
|
||||
void customDelegateJobInserted( int row, QStyledItemDelegate* delegate );
|
||||
void customDelegateJobRemoved( int row, QStyledItemDelegate* delegate );
|
||||
|
||||
private:
|
||||
QListView* m_view;
|
||||
|
Loading…
x
Reference in New Issue
Block a user