Skip to content

Commit

Permalink
qt: Rework RPCConsole::clearSelectedNode()
Browse files Browse the repository at this point in the history
Only successfully disconnected peers are deselected from the selection.
  • Loading branch information
hebasto committed Dec 22, 2020
1 parent 6a01276 commit 5745711
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
19 changes: 10 additions & 9 deletions src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,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();
Expand Down Expand Up @@ -1124,8 +1124,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));
}
}
}

Expand All @@ -1149,10 +1150,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();
}

Expand All @@ -1177,11 +1179,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()
Expand Down
2 changes: 1 addition & 1 deletion src/qt/rpcconsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,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();

Expand Down

0 comments on commit 5745711

Please sign in to comment.