Skip to content

Commit 0946638

Browse files
committed
Merge bitcoin-core#13: Hide peer detail view if multiple are selected
76277cc qt: Hide peer detail view if multiple are selected (João Barbosa) Pull request description: Currently if multiple peers are selected the peer detail view shows the first new selected peer. With this PR the peer detail view is hidden when multiple peers are selected. It is also a slight refactor to simplify and remove duplicate code. ACKs for top commit: jonasschnelli: Tested ACK 76277cc. hebasto: ACK 76277cc, tested on Linux Mint 20 (Qt 5.12.8). Tree-SHA512: 16c9cfd6ccb7077a9f31917a6cb3532e32d17d21f735e43bf4720fb0c8bb1bd539d42569c105df4b551f5dccb4acaeedb6bb2362620a9cb9267a602d9d065b9f
2 parents c45e1d9 + 76277cc commit 0946638

File tree

2 files changed

+16
-29
lines changed

2 files changed

+16
-29
lines changed

src/qt/rpcconsole.cpp

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,7 @@ RPCConsole::RPCConsole(interfaces::Node& node, const PlatformStyle *_platformSty
487487
m_node.rpcSetTimerInterfaceIfUnset(rpcTimerInterface);
488488

489489
setTrafficGraphRange(INITIAL_TRAFFIC_GRAPH_MINS);
490-
491-
ui->detailWidget->hide();
492-
ui->peerHeading->setText(tr("Select a peer to view detailed information."));
490+
updateDetailWidget();
493491

494492
consoleFontSize = settings.value(fontSizeSettingsKey, QFont().pointSize()).toInt();
495493
clear();
@@ -620,7 +618,7 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_
620618
connect(disconnectAction, &QAction::triggered, this, &RPCConsole::disconnectSelectedNode);
621619

622620
// peer table signal handling - update peer details when selecting new node
623-
connect(ui->peerWidget->selectionModel(), &QItemSelectionModel::selectionChanged, this, &RPCConsole::peerSelected);
621+
connect(ui->peerWidget->selectionModel(), &QItemSelectionModel::selectionChanged, this, &RPCConsole::updateDetailWidget);
624622
// peer table signal handling - update peer details when new nodes are added to the model
625623
connect(model->getPeerTableModel(), &PeerTableModel::layoutChanged, this, &RPCConsole::peerLayoutChanged);
626624
// peer table signal handling - cache selected node ids
@@ -1015,18 +1013,6 @@ void RPCConsole::updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut)
10151013
ui->lblBytesOut->setText(GUIUtil::formatBytes(totalBytesOut));
10161014
}
10171015

1018-
void RPCConsole::peerSelected(const QItemSelection &selected, const QItemSelection &deselected)
1019-
{
1020-
Q_UNUSED(deselected);
1021-
1022-
if (!clientModel || !clientModel->getPeerTableModel() || selected.indexes().isEmpty())
1023-
return;
1024-
1025-
const CNodeCombinedStats *stats = clientModel->getPeerTableModel()->getNodeStats(selected.indexes().first().row());
1026-
if (stats)
1027-
updateNodeDetail(stats);
1028-
}
1029-
10301016
void RPCConsole::peerLayoutAboutToChange()
10311017
{
10321018
QModelIndexList selected = ui->peerWidget->selectionModel()->selectedIndexes();
@@ -1043,7 +1029,6 @@ void RPCConsole::peerLayoutChanged()
10431029
if (!clientModel || !clientModel->getPeerTableModel())
10441030
return;
10451031

1046-
const CNodeCombinedStats *stats = nullptr;
10471032
bool fUnselect = false;
10481033
bool fReselect = false;
10491034

@@ -1074,9 +1059,6 @@ void RPCConsole::peerLayoutChanged()
10741059
fUnselect = true;
10751060
fReselect = true;
10761061
}
1077-
1078-
// get fresh stats on the detail node.
1079-
stats = clientModel->getPeerTableModel()->getNodeStats(detailNodeRow);
10801062
}
10811063

10821064
if (fUnselect && selectedRow >= 0) {
@@ -1091,12 +1073,20 @@ void RPCConsole::peerLayoutChanged()
10911073
}
10921074
}
10931075

1094-
if (stats)
1095-
updateNodeDetail(stats);
1076+
updateDetailWidget();
10961077
}
10971078

1098-
void RPCConsole::updateNodeDetail(const CNodeCombinedStats *stats)
1079+
void RPCConsole::updateDetailWidget()
10991080
{
1081+
QModelIndexList selected_rows;
1082+
auto selection_model = ui->peerWidget->selectionModel();
1083+
if (selection_model) selected_rows = selection_model->selectedRows();
1084+
if (!clientModel || !clientModel->getPeerTableModel() || selected_rows.size() != 1) {
1085+
ui->detailWidget->hide();
1086+
ui->peerHeading->setText(tr("Select a peer to view detailed information."));
1087+
return;
1088+
}
1089+
const CNodeCombinedStats *stats = clientModel->getPeerTableModel()->getNodeStats(selected_rows.first().row());
11001090
// update the detail ui with latest node information
11011091
QString peerAddrDetails(QString::fromStdString(stats->nodeStats.addrName) + " ");
11021092
peerAddrDetails += tr("(node id: %1)").arg(QString::number(stats->nodeStats.nodeid));
@@ -1254,8 +1244,7 @@ void RPCConsole::clearSelectedNode()
12541244
{
12551245
ui->peerWidget->selectionModel()->clearSelection();
12561246
cachedNodeids.clear();
1257-
ui->detailWidget->hide();
1258-
ui->peerHeading->setText(tr("Select a peer to view detailed information."));
1247+
updateDetailWidget();
12591248
}
12601249

12611250
void RPCConsole::showOrHideBanTableIfRequired()

src/qt/rpcconsole.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ private Q_SLOTS:
9595
void showOrHideBanTableIfRequired();
9696
/** clear the selected node */
9797
void clearSelectedNode();
98+
/** show detailed information on ui about selected node */
99+
void updateDetailWidget();
98100

99101
public Q_SLOTS:
100102
void clear(bool clearHistory = true);
@@ -116,8 +118,6 @@ public Q_SLOTS:
116118
void browseHistory(int offset);
117119
/** Scroll console view to end */
118120
void scrollToEnd();
119-
/** Handle selection of peer in peers list */
120-
void peerSelected(const QItemSelection &selected, const QItemSelection &deselected);
121121
/** Handle selection caching before update */
122122
void peerLayoutAboutToChange();
123123
/** Handle updated peer information */
@@ -138,8 +138,6 @@ public Q_SLOTS:
138138
private:
139139
void startExecutor();
140140
void setTrafficGraphRange(int mins);
141-
/** show detailed information on ui about selected node */
142-
void updateNodeDetail(const CNodeCombinedStats *stats);
143141

144142
enum ColumnWidths
145143
{

0 commit comments

Comments
 (0)