Bitcoin Core  21.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.addrName.compare(right_stats.addrName) < 0;
30  return left_stats.m_conn_type < right_stats.m_conn_type;
32  return left_stats.m_network < right_stats.m_network;
34  return left_stats.m_min_ping_time < right_stats.m_min_ping_time;
36  return left_stats.nSendBytes < right_stats.nSendBytes;
38  return left_stats.nRecvBytes < right_stats.nRecvBytes;
40  return left_stats.cleanSubVer.compare(right_stats.cleanSubVer) < 0;
41  } // no default case, so the compiler can warn about missing cases
42  assert(false);
43 }
CNodeStats::addrName
std::string addrName
Definition: net.h:253
PeerTableModel::Received
@ Received
Definition: peertablemodel.h:54
check.h
CNodeStats::m_network
Network m_network
Definition: net.h:275
PeerTableModel::NetNodeId
@ NetNodeId
Definition: peertablemodel.h:48
CNodeStats::nodeid
NodeId nodeid
Definition: net.h:244
PeerTableModel::Subversion
@ Subversion
Definition: peertablemodel.h:55
peertablesortproxy.h
PeerTableModel::Address
@ Address
Definition: peertablemodel.h:49
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:266
CNodeStats::cleanSubVer
std::string cleanSubVer
Definition: net.h:255
CNodeStats::m_conn_type
ConnectionType m_conn_type
Definition: net.h:277
PeerTableModel::Ping
@ Ping
Definition: peertablemodel.h:52
PeerTableModel::StatsRole
@ StatsRole
Definition: peertablemodel.h:59
CNodeStats::nSendBytes
uint64_t nSendBytes
Definition: net.h:260
PeerTableModel::Sent
@ Sent
Definition: peertablemodel.h:53
PeerTableSortProxy::PeerTableSortProxy
PeerTableSortProxy(QObject *parent=nullptr)
Definition: peertablesortproxy.cpp:14
CNodeStats::nRecvBytes
uint64_t nRecvBytes
Definition: net.h:262
peertablemodel.h
PeerTableModel::Network
@ Network
Definition: peertablemodel.h:51
assert
assert(std::addressof(::ChainstateActive().CoinsTip())==std::addressof(coins_cache))
CNodeStats
Definition: net.h:241
PeerTableSortProxy::lessThan
bool lessThan(const QModelIndex &left_index, const QModelIndex &right_index) const override
Definition: peertablesortproxy.cpp:19
PeerTableModel::ConnectionType
@ ConnectionType
Definition: peertablemodel.h:50
PeerTableModel::ColumnIndex
ColumnIndex
Definition: peertablemodel.h:47