aboutsummaryrefslogtreecommitdiff
path: root/src/qt/peertablesortproxy.cpp
diff options
context:
space:
mode:
authorHennadii Stepanov <32963518+hebasto@users.noreply.github.com>2021-02-22 09:50:09 +0200
committerHennadii Stepanov <32963518+hebasto@users.noreply.github.com>2021-03-07 16:57:11 +0200
commitdf2d165ba9e0acc53f36a326f68f57ad9c297872 (patch)
tree88e629023ce8fd4e31b32a1b5e4755b665a9ef7c /src/qt/peertablesortproxy.cpp
parent8c049fe9afcb749e0b80bb318641aee87c800bc5 (diff)
downloadbitcoin-df2d165ba9e0acc53f36a326f68f57ad9c297872.tar.xz
qt: Add peertablesortproxy module
Diffstat (limited to 'src/qt/peertablesortproxy.cpp')
-rw-r--r--src/qt/peertablesortproxy.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/qt/peertablesortproxy.cpp b/src/qt/peertablesortproxy.cpp
new file mode 100644
index 0000000000..78932da8d4
--- /dev/null
+++ b/src/qt/peertablesortproxy.cpp
@@ -0,0 +1,43 @@
+// Copyright (c) 2020 The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#include <qt/peertablesortproxy.h>
+
+#include <qt/peertablemodel.h>
+#include <util/check.h>
+
+#include <QModelIndex>
+#include <QString>
+#include <QVariant>
+
+PeerTableSortProxy::PeerTableSortProxy(QObject* parent)
+ : QSortFilterProxyModel(parent)
+{
+}
+
+bool PeerTableSortProxy::lessThan(const QModelIndex& left_index, const QModelIndex& right_index) const
+{
+ const CNodeStats left_stats = Assert(sourceModel()->data(left_index, PeerTableModel::StatsRole).value<CNodeCombinedStats*>())->nodeStats;
+ const CNodeStats right_stats = Assert(sourceModel()->data(right_index, PeerTableModel::StatsRole).value<CNodeCombinedStats*>())->nodeStats;
+
+ switch (static_cast<PeerTableModel::ColumnIndex>(left_index.column())) {
+ case PeerTableModel::NetNodeId:
+ return left_stats.nodeid < right_stats.nodeid;
+ case PeerTableModel::Address:
+ return left_stats.addrName.compare(right_stats.addrName) < 0;
+ case PeerTableModel::ConnectionType:
+ return left_stats.m_conn_type < right_stats.m_conn_type;
+ case PeerTableModel::Network:
+ return left_stats.m_network < right_stats.m_network;
+ case PeerTableModel::Ping:
+ return left_stats.m_min_ping_time < right_stats.m_min_ping_time;
+ case PeerTableModel::Sent:
+ return left_stats.nSendBytes < right_stats.nSendBytes;
+ case PeerTableModel::Received:
+ return left_stats.nRecvBytes < right_stats.nRecvBytes;
+ case PeerTableModel::Subversion:
+ return left_stats.cleanSubVer.compare(right_stats.cleanSubVer) < 0;
+ } // no default case, so the compiler can warn about missing cases
+ assert(false);
+}