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