2021-12-30 14:36:57 -03:00
|
|
|
// Copyright (c) 2020-2021 The Bitcoin Core developers
|
2021-02-22 04:50:09 -03:00
|
|
|
// 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;
|
2022-02-10 03:45:25 -03:00
|
|
|
case PeerTableModel::Age:
|
|
|
|
return left_stats.m_connected > right_stats.m_connected;
|
2021-02-22 04:50:09 -03:00
|
|
|
case PeerTableModel::Address:
|
2021-08-26 04:39:10 -04:00
|
|
|
return left_stats.m_addr_name.compare(right_stats.m_addr_name) < 0;
|
2021-04-23 08:57:05 -04:00
|
|
|
case PeerTableModel::Direction:
|
|
|
|
return left_stats.fInbound > right_stats.fInbound; // default sort Inbound, then Outbound
|
2021-02-22 04:50:09 -03:00
|
|
|
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);
|
|
|
|
}
|