Skip to content

Commit e059726

Browse files
author
Philip Kaufmann
committed
[Qt] deselect peer when switching away from peers tab in RPC console
1 parent 7211ada commit e059726

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

src/qt/rpcconsole.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -485,10 +485,10 @@ void RPCConsole::startExecutor()
485485

486486
void RPCConsole::on_tabWidget_currentChanged(int index)
487487
{
488-
if(ui->tabWidget->widget(index) == ui->tab_console)
489-
{
488+
if (ui->tabWidget->widget(index) == ui->tab_console)
490489
ui->lineEdit->setFocus();
491-
}
490+
else if (ui->tabWidget->widget(index) != ui->tab_peers)
491+
clearSelectedNode();
492492
}
493493

494494
void RPCConsole::on_openDebugLogfileButton_clicked()
@@ -558,12 +558,11 @@ void RPCConsole::peerLayoutChanged()
558558
return;
559559

560560
// find the currently selected row
561-
int selectedRow;
561+
int selectedRow = -1;
562562
QModelIndexList selectedModelIndex = ui->peerWidget->selectionModel()->selectedIndexes();
563-
if (selectedModelIndex.isEmpty())
564-
selectedRow = -1;
565-
else
563+
if (!selectedModelIndex.isEmpty()) {
566564
selectedRow = selectedModelIndex.first().row();
565+
}
567566

568567
// check if our detail node has a row in the table (it may not necessarily
569568
// be at selectedRow since its position can change after a layout change)
@@ -573,9 +572,6 @@ void RPCConsole::peerLayoutChanged()
573572
{
574573
// detail node dissapeared from table (node disconnected)
575574
fUnselect = true;
576-
cachedNodeid = -1;
577-
ui->detailWidget->hide();
578-
ui->peerHeading->setText(tr("Select a peer to view detailed information."));
579575
}
580576
else
581577
{
@@ -590,10 +586,8 @@ void RPCConsole::peerLayoutChanged()
590586
stats = clientModel->getPeerTableModel()->getNodeStats(detailNodeRow);
591587
}
592588

593-
if (fUnselect && selectedRow >= 0)
594-
{
595-
ui->peerWidget->selectionModel()->select(QItemSelection(selectedModelIndex.first(), selectedModelIndex.last()),
596-
QItemSelectionModel::Deselect);
589+
if (fUnselect && selectedRow >= 0) {
590+
clearSelectedNode();
597591
}
598592

599593
if (fReselect)
@@ -694,6 +688,14 @@ void RPCConsole::disconnectSelectedNode()
694688
// Find the node, disconnect it and clear the selected node
695689
if (CNode *bannedNode = FindNode(strNode.toStdString())) {
696690
bannedNode->CloseSocketDisconnect();
697-
ui->peerWidget->selectionModel()->clearSelection();
691+
clearSelectedNode();
698692
}
699693
}
694+
695+
void RPCConsole::clearSelectedNode()
696+
{
697+
ui->peerWidget->selectionModel()->clearSelection();
698+
cachedNodeid = -1;
699+
ui->detailWidget->hide();
700+
ui->peerHeading->setText(tr("Select a peer to view detailed information."));
701+
}

src/qt/rpcconsole.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public slots:
7676
void peerSelected(const QItemSelection &selected, const QItemSelection &deselected);
7777
/** Handle updated peer information */
7878
void peerLayoutChanged();
79-
/** Disconnect a selected node on the Peers tab */
79+
/** Disconnect a selected node on the Peers tab */
8080
void disconnectSelectedNode();
8181

8282
signals:
@@ -90,6 +90,8 @@ public slots:
9090
void setTrafficGraphRange(int mins);
9191
/** show detailed information on ui about selected node */
9292
void updateNodeDetail(const CNodeCombinedStats *stats);
93+
/** clear the selected node */
94+
void clearSelectedNode();
9395

9496
enum ColumnWidths
9597
{

0 commit comments

Comments
 (0)