Skip to content

Commit 6f1ccc7

Browse files
committed
qt: Rework RPCConsole::clearSelectedNode function
Only successfully disconnected peers are deselected from the selection.
1 parent 0525954 commit 6f1ccc7

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/qt/rpcconsole.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_
647647
connect(unbanAction, &QAction::triggered, this, &RPCConsole::unbanSelectedNode);
648648

649649
// ban table signal handling - clear peer details when clicking a peer in the ban table
650-
connect(ui->banlistWidget, &QTableView::clicked, this, &RPCConsole::clearSelectedNode);
650+
connect(ui->banlistWidget, &QTableView::clicked, ui->peerWidget->selectionModel(), &QItemSelectionModel::clearSelection);
651651
// ban table signal handling - ensure ban table is shown or hidden (if empty)
652652
connect(model->getBanTableModel(), &BanTableModel::layoutChanged, this, &RPCConsole::showOrHideBanTableIfRequired);
653653
showOrHideBanTableIfRequired();
@@ -1125,8 +1125,9 @@ void RPCConsole::disconnectSelectedNode()
11251125
// Get currently selected peer address
11261126
NodeId id = nodes.at(i).data().toLongLong();
11271127
// Find the node, disconnect it and clear the selected node
1128-
if(m_node.disconnectById(id))
1129-
clearSelectedNode();
1128+
if (m_node.disconnectById(id)) {
1129+
clearSelectedNode(nodes.at(i));
1130+
}
11301131
}
11311132
}
11321133

@@ -1140,10 +1141,11 @@ void RPCConsole::banSelectedNode(int bantime)
11401141
const CNodeCombinedStats* stats = clientModel->getPeerTableModel()->getNodeStats(peer.row());
11411142
if (stats) {
11421143
m_node.ban(stats->nodeStats.addr, bantime);
1143-
m_node.disconnectByAddress(stats->nodeStats.addr);
1144+
if (m_node.disconnectByAddress(stats->nodeStats.addr)) {
1145+
clearSelectedNode(peer);
1146+
}
11441147
}
11451148
}
1146-
clearSelectedNode();
11471149
clientModel->getBanTableModel()->refresh();
11481150
}
11491151

@@ -1168,11 +1170,10 @@ void RPCConsole::unbanSelectedNode()
11681170
}
11691171
}
11701172

1171-
void RPCConsole::clearSelectedNode()
1173+
void RPCConsole::clearSelectedNode(const QModelIndex& peer)
11721174
{
1173-
ui->peerWidget->selectionModel()->clearSelection();
1174-
cachedNodeids.clear();
1175-
updateDetailWidget();
1175+
auto selection = ui->peerWidget->selectionModel();
1176+
selection->select(peer, QItemSelectionModel::Deselect | QItemSelectionModel::Rows);
11761177
}
11771178

11781179
void RPCConsole::showOrHideBanTableIfRequired()

src/qt/rpcconsole.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private Q_SLOTS:
9494
/** Hides ban table if no bans are present */
9595
void showOrHideBanTableIfRequired();
9696
/** clear the selected node */
97-
void clearSelectedNode();
97+
void clearSelectedNode(const QModelIndex& peer);
9898
/** show detailed information on ui about selected node */
9999
void updateDetailWidget();
100100

0 commit comments

Comments
 (0)