1
0
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:
Leo Franchi 2012-07-27 14:59:22 -04:00
parent 3fbd58fcc9
commit b35e6ce61d
4 changed files with 25 additions and 8 deletions

View File

@ -18,10 +18,12 @@
#include "JobStatusItem.h"
#include <QTime>
JobStatusItem::JobStatusItem()
: QObject()
, m_createdOn( QDateTime::currentMSecsSinceEpoch() )
{
}

View File

@ -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* );

View File

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

View File

@ -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 );