1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-07-31 11:20:22 +02: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 "JobStatusItem.h"
#include <QTime>
JobStatusItem::JobStatusItem() JobStatusItem::JobStatusItem()
: QObject() : QObject()
, m_createdOn( QDateTime::currentMSecsSinceEpoch() )
{ {
} }

View File

@@ -65,12 +65,16 @@ public:
virtual void createDelegate( QObject* parent ); virtual void createDelegate( QObject* parent );
virtual QStyledItemDelegate* customDelegate() const; virtual QStyledItemDelegate* customDelegate() const;
qint64 age() const { return m_createdOn; }
signals: signals:
/// Ask for an update /// Ask for an update
void statusChanged(); void statusChanged();
/// Job is finished, will be deleted by the model /// Job is finished, will be deleted by the model
void finished(); void finished();
private:
qint64 m_createdOn;
}; };
Q_DECLARE_METATYPE( JobStatusItem* ); Q_DECLARE_METATYPE( JobStatusItem* );

View File

@@ -82,14 +82,14 @@ JobStatusSortModel::refreshDelegatesSlot()
bool bool
JobStatusSortModel::lessThan( const QModelIndex& left, const QModelIndex& right ) const JobStatusSortModel::lessThan( const QModelIndex& left, const QModelIndex& right ) const
{ {
QVariant leftVar = left.data( JobStatusModel::JobDataRole ); const int leftSort = left.data( JobStatusModel::SortRole ).toInt();
JobStatusItem* leftItem = leftVar.value< JobStatusItem* >(); const int rightSort = right.data( JobStatusModel::SortRole ).toInt();
QVariant rightVar = right.data( JobStatusModel::JobDataRole );
JobStatusItem* rightItem = rightVar.value< JobStatusItem* >();
if ( !leftItem || !rightItem )
return false;
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: case JobDataRole:
return QVariant::fromValue< JobStatusItem* >( item ); return QVariant::fromValue< JobStatusItem* >( item );
case SortRole:
return item->weight();
case AgeRole:
return item->age();
default:
return QVariant();
} }
return QVariant(); return QVariant();

View File

@@ -37,7 +37,9 @@ public:
// DisplayRole is main col // DisplayRole is main col
RightColumnRole = Qt::UserRole + 1, RightColumnRole = Qt::UserRole + 1,
AllowMultiLineRole = Qt::UserRole + 2, 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 ); explicit JobStatusModel( QObject* parent = 0 );