|
| 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 | + |
| 5 | +#include <qt/peertablesortproxy.h> |
| 6 | + |
| 7 | +#include <qt/peertablemodel.h> |
| 8 | +#include <util/check.h> |
| 9 | + |
| 10 | +#include <QModelIndex> |
| 11 | +#include <QString> |
| 12 | +#include <QVariant> |
| 13 | + |
| 14 | +PeerTableSortProxy::PeerTableSortProxy(QObject* parent) |
| 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())) { |
| 25 | + case PeerTableModel::NetNodeId: |
| 26 | + return left_stats.nodeid < right_stats.nodeid; |
| 27 | + case PeerTableModel::Address: |
| 28 | + return left_stats.addrName.compare(right_stats.addrName) < 0; |
| 29 | + case PeerTableModel::ConnectionType: |
| 30 | + return left_stats.m_conn_type < right_stats.m_conn_type; |
| 31 | + case PeerTableModel::Network: |
| 32 | + return left_stats.m_network < right_stats.m_network; |
| 33 | + case PeerTableModel::Ping: |
| 34 | + return left_stats.m_min_ping_time < right_stats.m_min_ping_time; |
| 35 | + case PeerTableModel::Sent: |
| 36 | + return left_stats.nSendBytes < right_stats.nSendBytes; |
| 37 | + case PeerTableModel::Received: |
| 38 | + return left_stats.nRecvBytes < right_stats.nRecvBytes; |
| 39 | + case PeerTableModel::Subversion: |
| 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 | +} |
0 commit comments