From 31c830e673277da449cf3679f35c46d535459c3b Mon Sep 17 00:00:00 2001 From: randymcmillan Date: Mon, 9 Aug 2021 03:21:55 -0400 Subject: [PATCH] peers-tab: sortable directions column --- src/qt/peertablemodel.cpp | 6 +++++- src/qt/peertablemodel.h | 2 ++ src/qt/peertablesortproxy.cpp | 2 ++ src/qt/rpcconsole.cpp | 1 + src/qt/rpcconsole.h | 1 + 5 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/qt/peertablemodel.cpp b/src/qt/peertablemodel.cpp index 1b7fda6e775..80812df8e74 100644 --- a/src/qt/peertablemodel.cpp +++ b/src/qt/peertablemodel.cpp @@ -71,9 +71,11 @@ QVariant PeerTableModel::data(const QModelIndex& index, int role) const switch (column) { case NetNodeId: return (qint64)rec->nodeStats.nodeid; + case Direction: + return QString::fromStdString((rec->nodeStats.fInbound ? "↓" : "↑")); case Address: // prepend to peer address down-arrow symbol for inbound connection and up-arrow for outbound connection - return QString::fromStdString((rec->nodeStats.fInbound ? "↓ " : "↑ ") + rec->nodeStats.addrName); + return QString::fromStdString(rec->nodeStats.addrName); case ConnectionType: return GUIUtil::ConnectionTypeToQString(rec->nodeStats.m_conn_type, /* prepend_direction */ false); case Network: @@ -92,6 +94,8 @@ QVariant PeerTableModel::data(const QModelIndex& index, int role) const switch (column) { case NetNodeId: return QVariant(Qt::AlignRight | Qt::AlignVCenter); + case Direction: + return QVariant(Qt::AlignCenter); case Address: return {}; case ConnectionType: diff --git a/src/qt/peertablemodel.h b/src/qt/peertablemodel.h index 0d841ebf28c..a71575dcbdf 100644 --- a/src/qt/peertablemodel.h +++ b/src/qt/peertablemodel.h @@ -47,6 +47,7 @@ class PeerTableModel : public QAbstractTableModel enum ColumnIndex { NetNodeId = 0, + Direction, Address, ConnectionType, Network, @@ -81,6 +82,7 @@ public Q_SLOTS: /*: Title of Peers Table column which contains a unique number used to identify a connection. */ tr("Peer"), + tr(""), /*: Title of Peers Table column which contains the IP/Onion/I2P address of the connected peer. */ tr("Address"), diff --git a/src/qt/peertablesortproxy.cpp b/src/qt/peertablesortproxy.cpp index 78932da8d48..98d8055f276 100644 --- a/src/qt/peertablesortproxy.cpp +++ b/src/qt/peertablesortproxy.cpp @@ -24,6 +24,8 @@ bool PeerTableSortProxy::lessThan(const QModelIndex& left_index, const QModelInd switch (static_cast(left_index.column())) { case PeerTableModel::NetNodeId: return left_stats.nodeid < right_stats.nodeid; + case PeerTableModel::Direction: + return left_stats.fInbound < right_stats.fInbound; case PeerTableModel::Address: return left_stats.addrName.compare(right_stats.addrName) < 0; case PeerTableModel::ConnectionType: diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 56f55363b26..3f394666ffb 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -672,6 +672,7 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_ if (!ui->peerWidget->horizontalHeader()->restoreState(m_peer_widget_header_state)) { ui->peerWidget->setColumnWidth(PeerTableModel::Address, ADDRESS_COLUMN_WIDTH); + ui->peerWidget->setColumnWidth(PeerTableModel::Direction, DIRECTION_COLUMN_WIDTH); ui->peerWidget->setColumnWidth(PeerTableModel::Subversion, SUBVERSION_COLUMN_WIDTH); ui->peerWidget->setColumnWidth(PeerTableModel::Ping, PING_COLUMN_WIDTH); } diff --git a/src/qt/rpcconsole.h b/src/qt/rpcconsole.h index 2412ae543c8..d8ad2e92900 100644 --- a/src/qt/rpcconsole.h +++ b/src/qt/rpcconsole.h @@ -145,6 +145,7 @@ public Q_SLOTS: enum ColumnWidths { ADDRESS_COLUMN_WIDTH = 200, + DIRECTION_COLUMN_WIDTH = 30, SUBVERSION_COLUMN_WIDTH = 150, PING_COLUMN_WIDTH = 80, BANSUBNET_COLUMN_WIDTH = 200,