mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-12 15:57:57 +00:00
Merge pull request #3058 from VladimirSinenko/master
Fixed sort order for datetime columns with empty values (closes #2988)
This commit is contained in:
commit
12b73747f5
@ -86,14 +86,7 @@ bool TransferListSortModel::lessThan(const QModelIndex &left, const QModelIndex
|
|||||||
case TorrentModel::TR_ADD_DATE:
|
case TorrentModel::TR_ADD_DATE:
|
||||||
case TorrentModel::TR_SEED_DATE:
|
case TorrentModel::TR_SEED_DATE:
|
||||||
case TorrentModel::TR_SEEN_COMPLETE_DATE: {
|
case TorrentModel::TR_SEEN_COMPLETE_DATE: {
|
||||||
QDateTime vL = left.data().toDateTime();
|
return dateLessThan(column, left, right);
|
||||||
QDateTime vR = right.data().toDateTime();
|
|
||||||
|
|
||||||
//not valid dates should be sorted at the bottom.
|
|
||||||
if (!vL.isValid()) return false;
|
|
||||||
if (!vR.isValid()) return true;
|
|
||||||
|
|
||||||
return vL < vR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case TorrentModel::TR_PRIORITY: {
|
case TorrentModel::TR_PRIORITY: {
|
||||||
@ -146,14 +139,7 @@ bool TransferListSortModel::lessThan(const QModelIndex &left, const QModelIndex
|
|||||||
|
|
||||||
if (invalidL && invalidR) {
|
if (invalidL && invalidR) {
|
||||||
if (seedingL) { //Both seeding
|
if (seedingL) { //Both seeding
|
||||||
QDateTime dateL = model->data(model->index(left.row(), TorrentModel::TR_SEED_DATE)).toDateTime();
|
return dateLessThan(TorrentModelItem::TR_SEED_DATE, left, right);
|
||||||
QDateTime dateR = model->data(model->index(right.row(), TorrentModel::TR_SEED_DATE)).toDateTime();
|
|
||||||
|
|
||||||
//not valid dates should be sorted at the bottom.
|
|
||||||
if (!dateL.isValid()) return false;
|
|
||||||
if (!dateR.isValid()) return true;
|
|
||||||
|
|
||||||
return dateL < dateR;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return prioL < prioR;
|
return prioL < prioR;
|
||||||
@ -210,8 +196,17 @@ bool TransferListSortModel::lowerPositionThan(const QModelIndex &left, const QMo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Sort according to TR_SEED_DATE
|
// Sort according to TR_SEED_DATE
|
||||||
const QDateTime dateL = model->data(model->index(left.row(), TorrentModel::TR_SEED_DATE)).toDateTime();
|
return dateLessThan(TorrentModelItem::TR_SEED_DATE, left, right);
|
||||||
const QDateTime dateR = model->data(model->index(right.row(), TorrentModel::TR_SEED_DATE)).toDateTime();
|
}
|
||||||
|
|
||||||
|
// Every time we compare QDateTimes we need a fallback comparison in case both
|
||||||
|
// values are empty. This is a workaround for unstable sort in QSortFilterProxyModel
|
||||||
|
// (detailed discussion in #2526 and #2158).
|
||||||
|
bool TransferListSortModel::dateLessThan(const int dateColumn, const QModelIndex &left, const QModelIndex &right) const
|
||||||
|
{
|
||||||
|
const TorrentModel *model = dynamic_cast<TorrentModel*>(sourceModel());
|
||||||
|
const QDateTime dateL = model->data(model->index(left.row(), dateColumn)).toDateTime();
|
||||||
|
const QDateTime dateR = model->data(model->index(right.row(), dateColumn)).toDateTime();
|
||||||
if (dateL.isValid() && dateR.isValid()) {
|
if (dateL.isValid() && dateR.isValid()) {
|
||||||
if (dateL != dateR)
|
if (dateL != dateR)
|
||||||
return dateL < dateR;
|
return dateL < dateR;
|
||||||
|
@ -52,6 +52,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
|
bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
|
||||||
bool lowerPositionThan(const QModelIndex &left, const QModelIndex &right) const;
|
bool lowerPositionThan(const QModelIndex &left, const QModelIndex &right) const;
|
||||||
|
bool dateLessThan(const int dateColumn, const QModelIndex &left, const QModelIndex &right) const;
|
||||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
|
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
|
||||||
bool matchFilter(int sourceRow, const QModelIndex &sourceParent) const;
|
bool matchFilter(int sourceRow, const QModelIndex &sourceParent) const;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user