From b119ae0c82c6f36afdf3eefd89b687ab78a9e34a Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Wed, 1 Jul 2020 20:21:29 +0300 Subject: [PATCH] qt: Rework RPCConsole::clearSelectedNode() Only successfully disconnected peers are deselected from the selection. --- src/qt/rpcconsole.cpp | 19 ++++++++++--------- src/qt/rpcconsole.h | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 322612de300..0e4e20eac00 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -650,7 +650,7 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_ connect(unbanAction, &QAction::triggered, this, &RPCConsole::unbanSelectedNode); // ban table signal handling - clear peer details when clicking a peer in the ban table - connect(ui->banlistWidget, &QTableView::clicked, this, &RPCConsole::clearSelectedNode); + connect(ui->banlistWidget, &QTableView::clicked, ui->peerWidget->selectionModel(), &QItemSelectionModel::clearSelection); // ban table signal handling - ensure ban table is shown or hidden (if empty) connect(model->getBanTableModel(), &BanTableModel::layoutChanged, this, &RPCConsole::showOrHideBanTableIfRequired); showOrHideBanTableIfRequired(); @@ -1127,8 +1127,9 @@ void RPCConsole::disconnectSelectedNode() // Get currently selected peer address NodeId id = nodes.at(i).data().toLongLong(); // Find the node, disconnect it and clear the selected node - if(m_node.disconnectById(id)) - clearSelectedNode(); + if (m_node.disconnectById(id)) { + clearSelectedNode(nodes.at(i)); + } } } @@ -1152,10 +1153,11 @@ void RPCConsole::banSelectedNode(int bantime) const CNodeCombinedStats *stats = clientModel->getPeerTableModel()->getNodeStats(detailNodeRow); if (stats) { m_node.ban(stats->nodeStats.addr, bantime); - m_node.disconnectByAddress(stats->nodeStats.addr); + if (m_node.disconnectByAddress(stats->nodeStats.addr)) { + clearSelectedNode(nodes.at(i)); + } } } - clearSelectedNode(); clientModel->getBanTableModel()->refresh(); } @@ -1180,11 +1182,10 @@ void RPCConsole::unbanSelectedNode() } } -void RPCConsole::clearSelectedNode() +void RPCConsole::clearSelectedNode(const QModelIndex& peer) { - ui->peerWidget->selectionModel()->clearSelection(); - cachedNodeids.clear(); - updateDetailWidget(); + auto selection = ui->peerWidget->selectionModel(); + selection->select(peer, QItemSelectionModel::Deselect | QItemSelectionModel::Rows); } void RPCConsole::showOrHideBanTableIfRequired() diff --git a/src/qt/rpcconsole.h b/src/qt/rpcconsole.h index f0b40de3137..ea569ea076d 100644 --- a/src/qt/rpcconsole.h +++ b/src/qt/rpcconsole.h @@ -93,7 +93,7 @@ private Q_SLOTS: /** Hides ban table if no bans are present */ void showOrHideBanTableIfRequired(); /** clear the selected node */ - void clearSelectedNode(); + void clearSelectedNode(const QModelIndex& peer); /** show detailed information on ui about selected node */ void updateDetailWidget();