From 13f69a22456f97584ec1e8b963baeb6cfadcf1bb Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Mon, 1 Jan 2018 20:04:54 +0200 Subject: [PATCH] Fix constant status of '[F] Downloading'. Closes #7628. --- src/gui/torrentmodel.cpp | 2 +- src/gui/transferlistsortmodel.cpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/gui/torrentmodel.cpp b/src/gui/torrentmodel.cpp index 4feef0897..79d916733 100644 --- a/src/gui/torrentmodel.cpp +++ b/src/gui/torrentmodel.cpp @@ -184,7 +184,7 @@ QVariant TorrentModel::data(const QModelIndex &index, int role) const case TR_PROGRESS: return torrent->progress(); case TR_STATUS: - return static_cast(torrent->state()); + return QVariant::fromValue(torrent->state()); case TR_SEEDS: return (role == Qt::DisplayRole) ? torrent->seedsCount() : torrent->totalSeedsCount(); case TR_PEERS: diff --git a/src/gui/transferlistsortmodel.cpp b/src/gui/transferlistsortmodel.cpp index e57b35baf..419e27bd9 100644 --- a/src/gui/transferlistsortmodel.cpp +++ b/src/gui/transferlistsortmodel.cpp @@ -98,6 +98,20 @@ bool TransferListSortModel::lessThan(const QModelIndex &left, const QModelIndex return (result < 0); } + case TorrentModel::TR_STATUS: { + // QSortFilterProxyModel::lessThan() uses the < operator only for specific QVariant types + // so our custom type is outside that list. + // In this case QSortFilterProxyModel::lessThan() converts other types to QString and + // sorts them. + // Thus we can't use the code in the default label. + const BitTorrent::TorrentState leftValue = left.data().value(); + const BitTorrent::TorrentState rightValue = right.data().value(); + if (leftValue != rightValue) + return leftValue < rightValue; + + return lowerPositionThan(left, right); + } + case TorrentModel::TR_ADD_DATE: case TorrentModel::TR_SEED_DATE: case TorrentModel::TR_SEEN_COMPLETE_DATE: {