Bitcoin Core  22.99.0
P2P Digital Currency
peertablesortproxy.cpp
Go to the documentation of this file.
1 // Copyright (c) 2020 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
6 
7 #include <qt/peertablemodel.h>
8 #include <util/check.h>
9 
10 #include <QModelIndex>
11 #include <QString>
12 #include <QVariant>
13 
15  : QSortFilterProxyModel(parent)
16 {
17 }
18 
19 bool PeerTableSortProxy::lessThan(const QModelIndex& left_index, const QModelIndex& right_index) const
20 {
21  const CNodeStats left_stats = Assert(sourceModel()->data(left_index, PeerTableModel::StatsRole).value<CNodeCombinedStats*>())->nodeStats;
22  const CNodeStats right_stats = Assert(sourceModel()->data(right_index, PeerTableModel::StatsRole).value<CNodeCombinedStats*>())->nodeStats;
23 
24  switch (static_cast<PeerTableModel::ColumnIndex>(left_index.column())) {
26  return left_stats.nodeid < right_stats.nodeid;
28  return left_stats.m_addr_name.compare(right_stats.m_addr_name) < 0;
30  return left_stats.fInbound > right_stats.fInbound; // default sort Inbound, then Outbound
32  return left_stats.m_conn_type < right_stats.m_conn_type;
34  return left_stats.m_network < right_stats.m_network;
36  return left_stats.m_min_ping_time < right_stats.m_min_ping_time;
38  return left_stats.nSendBytes < right_stats.nSendBytes;
40  return left_stats.nRecvBytes < right_stats.nRecvBytes;
42  return left_stats.cleanSubVer.compare(right_stats.cleanSubVer) < 0;
43  } // no default case, so the compiler can warn about missing cases
44  assert(false);
45 }
PeerTableModel::Received
@ Received
Definition: peertablemodel.h:56
CNodeStats::fInbound
bool fInbound
Definition: net.h:253
assert
assert(!tx.IsCoinBase())
check.h
CNodeStats::m_network
Network m_network
Definition: net.h:272
PeerTableModel::NetNodeId
@ NetNodeId
Definition: peertablemodel.h:49
CNodeStats::nodeid
NodeId nodeid
Definition: net.h:241
PeerTableModel::Subversion
@ Subversion
Definition: peertablemodel.h:57
peertablesortproxy.h
PeerTableModel::Address
@ Address
Definition: peertablemodel.h:50
Assert
#define Assert(val)
Identity function.
Definition: check.h:57
CNodeStats::m_min_ping_time
std::chrono::microseconds m_min_ping_time
Definition: net.h:263
PeerTableModel::Direction
@ Direction
Definition: peertablemodel.h:51
CNodeStats::m_addr_name
std::string m_addr_name
Definition: net.h:250
CNodeStats::cleanSubVer
std::string cleanSubVer
Definition: net.h:252
CNodeStats::m_conn_type
ConnectionType m_conn_type
Definition: net.h:274
PeerTableModel::Ping
@ Ping
Definition: peertablemodel.h:54
PeerTableModel::StatsRole
@ StatsRole
Definition: peertablemodel.h:61
CNodeStats::nSendBytes
uint64_t nSendBytes
Definition: net.h:257
PeerTableModel::Sent
@ Sent
Definition: peertablemodel.h:55
PeerTableSortProxy::PeerTableSortProxy
PeerTableSortProxy(QObject *parent=nullptr)
Definition: peertablesortproxy.cpp:14
CNodeStats::nRecvBytes
uint64_t nRecvBytes
Definition: net.h:259
peertablemodel.h
PeerTableModel::Network
@ Network
Definition: peertablemodel.h:53
CNodeStats
Definition: net.h:238
PeerTableSortProxy::lessThan
bool lessThan(const QModelIndex &left_index, const QModelIndex &right_index) const override
Definition: peertablesortproxy.cpp:19
PeerTableModel::ConnectionType
@ ConnectionType
Definition: peertablemodel.h:52
PeerTableModel::ColumnIndex
ColumnIndex
Definition: peertablemodel.h:48