From 5ba6a5fca19ab7f143a1590f7e094aa8a30b862e Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Thu, 10 Dec 2020 15:58:54 +0800 Subject: [PATCH] Add operator< for InfoHash class --- src/base/bittorrent/infohash.cpp | 5 +++++ src/base/bittorrent/infohash.h | 1 + src/gui/transferlistsortmodel.cpp | 4 ++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/base/bittorrent/infohash.cpp b/src/base/bittorrent/infohash.cpp index 495a4f47d..3a2c0371c 100644 --- a/src/base/bittorrent/infohash.cpp +++ b/src/base/bittorrent/infohash.cpp @@ -84,6 +84,11 @@ bool BitTorrent::operator!=(const InfoHash &left, const InfoHash &right) return !(left == right); } +bool BitTorrent::operator<(const InfoHash &left, const InfoHash &right) +{ + return static_cast(left) < static_cast(right); +} + uint BitTorrent::qHash(const InfoHash &key, const uint seed) { return ::qHash((std::hash {})(key), seed); diff --git a/src/base/bittorrent/infohash.h b/src/base/bittorrent/infohash.h index be0a0ef75..81c35f5dd 100644 --- a/src/base/bittorrent/infohash.h +++ b/src/base/bittorrent/infohash.h @@ -61,6 +61,7 @@ namespace BitTorrent bool operator==(const InfoHash &left, const InfoHash &right); bool operator!=(const InfoHash &left, const InfoHash &right); + bool operator<(const InfoHash &left, const InfoHash &right); uint qHash(const InfoHash &key, uint seed); } diff --git a/src/gui/transferlistsortmodel.cpp b/src/gui/transferlistsortmodel.cpp index e1d32b84f..1d37f4a02 100644 --- a/src/gui/transferlistsortmodel.cpp +++ b/src/gui/transferlistsortmodel.cpp @@ -102,8 +102,8 @@ bool TransferListSortModel::lessThan_impl(const QModelIndex &left, const QModelI const auto hashLessThan = [this, &left, &right]() -> bool { const TransferListModel *model = qobject_cast(sourceModel()); - const QString hashL = model->torrentHandle(left)->hash(); - const QString hashR = model->torrentHandle(right)->hash(); + const BitTorrent::InfoHash hashL = model->torrentHandle(left)->hash(); + const BitTorrent::InfoHash hashR = model->torrentHandle(right)->hash(); return hashL < hashR; };