Skip to content

Commit 0a03c82

Browse files
committed
qt: Rework RPCConsole::clearSelectedNode()
Only successfully disconnected peers are deselected from the selection.
1 parent 79734b7 commit 0a03c82

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
@@ -649,7 +649,7 @@ void RPCConsole::setClientModel(ClientModel *model)
649649
connect(unbanAction, &QAction::triggered, this, &RPCConsole::unbanSelectedNode);
650650

651651
// ban table signal handling - clear peer details when clicking a peer in the ban table
652-
connect(ui->banlistWidget, &QTableView::clicked, this, &RPCConsole::clearSelectedNode);
652+
connect(ui->banlistWidget, &QTableView::clicked, ui->peerWidget->selectionModel(), &QItemSelectionModel::clearSelection);
653653
// ban table signal handling - ensure ban table is shown or hidden (if empty)
654654
connect(model->getBanTableModel(), &BanTableModel::layoutChanged, this, &RPCConsole::showOrHideBanTableIfRequired);
655655
showOrHideBanTableIfRequired();
@@ -1118,8 +1118,9 @@ void RPCConsole::disconnectSelectedNode()
11181118
// Get currently selected peer address
11191119
NodeId id = nodes.at(i).data().toLongLong();
11201120
// Find the node, disconnect it and clear the selected node
1121-
if(m_node.disconnectById(id))
1122-
clearSelectedNode();
1121+
if (m_node.disconnectById(id)) {
1122+
clearSelectedNode(nodes.at(i));
1123+
}
11231124
}
11241125
}
11251126

@@ -1143,10 +1144,11 @@ void RPCConsole::banSelectedNode(int bantime)
11431144
const CNodeCombinedStats *stats = clientModel->getPeerTableModel()->getNodeStats(detailNodeRow);
11441145
if (stats) {
11451146
m_node.ban(stats->nodeStats.addr, BanReasonManuallyAdded, bantime);
1146-
m_node.disconnectByAddress(stats->nodeStats.addr);
1147+
if (m_node.disconnectByAddress(stats->nodeStats.addr)) {
1148+
clearSelectedNode(nodes.at(i));
1149+
}
11471150
}
11481151
}
1149-
clearSelectedNode();
11501152
clientModel->getBanTableModel()->refresh();
11511153
}
11521154

@@ -1171,11 +1173,10 @@ void RPCConsole::unbanSelectedNode()
11711173
}
11721174
}
11731175

1174-
void RPCConsole::clearSelectedNode()
1176+
void RPCConsole::clearSelectedNode(const QModelIndex& peer)
11751177
{
1176-
ui->peerWidget->selectionModel()->clearSelection();
1177-
cachedNodeids.clear();
1178-
updateDetailWidget();
1178+
auto selection = ui->peerWidget->selectionModel();
1179+
selection->select(peer, QItemSelectionModel::Deselect | QItemSelectionModel::Rows);
11791180
}
11801181

11811182
void RPCConsole::showOrHideBanTableIfRequired()

src/qt/rpcconsole.h

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

0 commit comments

Comments
 (0)