mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-01-31 13:48:09 +01:00
TWK-998: Stable sort in job view proxy, by creation date
This commit is contained in:
parent
3fbd58fcc9
commit
b35e6ce61d
@ -18,10 +18,12 @@
|
||||
|
||||
|
||||
#include "JobStatusItem.h"
|
||||
#include <QTime>
|
||||
|
||||
|
||||
JobStatusItem::JobStatusItem()
|
||||
: QObject()
|
||||
, m_createdOn( QDateTime::currentMSecsSinceEpoch() )
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -65,12 +65,16 @@ public:
|
||||
virtual void createDelegate( QObject* parent );
|
||||
virtual QStyledItemDelegate* customDelegate() const;
|
||||
|
||||
qint64 age() const { return m_createdOn; }
|
||||
signals:
|
||||
/// Ask for an update
|
||||
void statusChanged();
|
||||
|
||||
/// Job is finished, will be deleted by the model
|
||||
void finished();
|
||||
|
||||
private:
|
||||
qint64 m_createdOn;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE( JobStatusItem* );
|
||||
|
@ -82,14 +82,14 @@ JobStatusSortModel::refreshDelegatesSlot()
|
||||
bool
|
||||
JobStatusSortModel::lessThan( const QModelIndex& left, const QModelIndex& right ) const
|
||||
{
|
||||
QVariant leftVar = left.data( JobStatusModel::JobDataRole );
|
||||
JobStatusItem* leftItem = leftVar.value< JobStatusItem* >();
|
||||
QVariant rightVar = right.data( JobStatusModel::JobDataRole );
|
||||
JobStatusItem* rightItem = rightVar.value< JobStatusItem* >();
|
||||
if ( !leftItem || !rightItem )
|
||||
return false;
|
||||
const int leftSort = left.data( JobStatusModel::SortRole ).toInt();
|
||||
const int rightSort = right.data( JobStatusModel::SortRole ).toInt();
|
||||
|
||||
return leftItem->weight() < rightItem->weight();
|
||||
if ( leftSort == rightSort )
|
||||
return left.data( JobStatusModel::AgeRole ).toUInt() > right.data( JobStatusModel::AgeRole ).toUInt();
|
||||
|
||||
|
||||
return leftSort < rightSort;
|
||||
}
|
||||
|
||||
|
||||
@ -204,6 +204,15 @@ JobStatusModel::data( const QModelIndex& index, int role ) const
|
||||
|
||||
case JobDataRole:
|
||||
return QVariant::fromValue< JobStatusItem* >( item );
|
||||
|
||||
case SortRole:
|
||||
return item->weight();
|
||||
|
||||
case AgeRole:
|
||||
return item->age();
|
||||
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
|
@ -37,7 +37,9 @@ public:
|
||||
// DisplayRole is main col
|
||||
RightColumnRole = Qt::UserRole + 1,
|
||||
AllowMultiLineRole = Qt::UserRole + 2,
|
||||
JobDataRole = Qt::UserRole + 3
|
||||
JobDataRole = Qt::UserRole + 3,
|
||||
SortRole = Qt::UserRole + 4,
|
||||
AgeRole = Qt::UserRole + 5
|
||||
};
|
||||
|
||||
explicit JobStatusModel( QObject* parent = 0 );
|
||||
|
Loading…
x
Reference in New Issue
Block a user