|
|
|
@ -100,6 +100,14 @@ bool TransferListSortModel::lessThan_impl(const QModelIndex &left, const QModelI
@@ -100,6 +100,14 @@ bool TransferListSortModel::lessThan_impl(const QModelIndex &left, const QModelI
|
|
|
|
|
return lessThan_impl(left.sibling(left.row(), column), right.sibling(right.row(), column)); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const auto hashLessThan = [this, &left, &right]() -> bool |
|
|
|
|
{ |
|
|
|
|
const TransferListModel *model = qobject_cast<TransferListModel *>(sourceModel()); |
|
|
|
|
const QString hashL = model->torrentHandle(left)->hash(); |
|
|
|
|
const QString hashR = model->torrentHandle(right)->hash(); |
|
|
|
|
return hashL < hashR; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const int sortColumn = left.column(); |
|
|
|
|
const QVariant leftValue = left.data(TransferListModel::UnderlyingDataRole); |
|
|
|
|
const QVariant rightValue = right.data(TransferListModel::UnderlyingDataRole); |
|
|
|
@ -138,8 +146,9 @@ bool TransferListSortModel::lessThan_impl(const QModelIndex &left, const QModelI
@@ -138,8 +146,9 @@ bool TransferListSortModel::lessThan_impl(const QModelIndex &left, const QModelI
|
|
|
|
|
else if (dateR.isValid()) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return hashLessThan(); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case TransferListModel::TR_QUEUE_POSITION: { |
|
|
|
|
// QVariant has comparators for all basic types
|
|
|
|
@ -166,8 +175,9 @@ bool TransferListSortModel::lessThan_impl(const QModelIndex &left, const QModelI
@@ -166,8 +175,9 @@ bool TransferListSortModel::lessThan_impl(const QModelIndex &left, const QModelI
|
|
|
|
|
else if (dateR.isValid()) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return hashLessThan(); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case TransferListModel::TR_SEEDS: |
|
|
|
|
case TransferListModel::TR_PEERS: { |
|
|
|
@ -237,19 +247,11 @@ bool TransferListSortModel::lessThan_impl(const QModelIndex &left, const QModelI
@@ -237,19 +247,11 @@ bool TransferListSortModel::lessThan_impl(const QModelIndex &left, const QModelI
|
|
|
|
|
if (rightValue < 0) return true; |
|
|
|
|
|
|
|
|
|
return (leftValue < rightValue); |
|
|
|
|
|
|
|
|
|
default: |
|
|
|
|
if (leftValue != rightValue) |
|
|
|
|
return QSortFilterProxyModel::lessThan(left, right); |
|
|
|
|
|
|
|
|
|
return invokeLessThanForColumn(TransferListModel::TR_QUEUE_POSITION); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Finally, sort by hash
|
|
|
|
|
const TransferListModel *model = qobject_cast<TransferListModel *>(sourceModel()); |
|
|
|
|
const QString hashL = model->torrentHandle(left)->hash(); |
|
|
|
|
const QString hashR = model->torrentHandle(right)->hash(); |
|
|
|
|
return hashL < hashR; |
|
|
|
|
return (leftValue != rightValue) |
|
|
|
|
? QSortFilterProxyModel::lessThan(left, right) |
|
|
|
|
: invokeLessThanForColumn(TransferListModel::TR_QUEUE_POSITION); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool TransferListSortModel::filterAcceptsRow(const int sourceRow, const QModelIndex &sourceParent) const |
|
|
|
|