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 Jul 1, 2020
1 parent 79734b7 commit 0a03c82
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 @@ -649,7 +649,7 @@ void RPCConsole::setClientModel(ClientModel *model)
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 @@ -1118,8 +1118,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 @@ -1143,10 +1144,11 @@ void RPCConsole::banSelectedNode(int bantime)
const CNodeCombinedStats *stats = clientModel->getPeerTableModel()->getNodeStats(detailNodeRow);
if (stats) {
m_node.ban(stats->nodeStats.addr, BanReasonManuallyAdded, bantime);
m_node.disconnectByAddress(stats->nodeStats.addr);
if (m_node.disconnectByAddress(stats->nodeStats.addr)) {
clearSelectedNode(nodes.at(i));
}
}
}
clearSelectedNode();
clientModel->getBanTableModel()->refresh();
}

Expand All @@ -1171,11 +1173,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 @@ -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();

Expand Down

0 comments on commit 0a03c82

Please sign in to comment.