Skip to content

Commit

Permalink
qt: Hide peer detail view if multiple are selected
Browse files Browse the repository at this point in the history
Summary:
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.

This is a backport of [[bitcoin-core/gui#13 | core-gui#13]]

Test Plan:
`ninja all check-all`

Run `bitcoin-qt`, open menu `Window > Peer`. Select multiple peers.

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D10814
  • Loading branch information
promag authored and PiRK committed Jan 11, 2022
1 parent 891d5ad commit 45627ee
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 36 deletions.
51 changes: 20 additions & 31 deletions src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,9 +570,7 @@ RPCConsole::RPCConsole(interfaces::Node &node,
m_node.rpcSetTimerInterfaceIfUnset(rpcTimerInterface);

setTrafficGraphRange(INITIAL_TRAFFIC_GRAPH_MINS);

ui->detailWidget->hide();
ui->peerHeading->setText(tr("Select a peer to view detailed information."));
updateDetailWidget();

consoleFontSize =
settings.value(fontSizeSettingsKey, QFont().pointSize()).toInt();
Expand Down Expand Up @@ -737,7 +735,7 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height,
// node
connect(ui->peerWidget->selectionModel(),
&QItemSelectionModel::selectionChanged, this,
&RPCConsole::peerSelected);
&RPCConsole::updateDetailWidget);
// peer table signal handling - update peer details when new nodes are
// added to the model
connect(model->getPeerTableModel(), &PeerTableModel::layoutChanged,
Expand Down Expand Up @@ -1172,23 +1170,6 @@ void RPCConsole::updateTrafficStats(quint64 totalBytesIn,
ui->lblBytesOut->setText(GUIUtil::formatBytes(totalBytesOut));
}

void RPCConsole::peerSelected(const QItemSelection &selected,
const QItemSelection &deselected) {
Q_UNUSED(deselected);

if (!clientModel || !clientModel->getPeerTableModel() ||
selected.indexes().isEmpty()) {
return;
}

const CNodeCombinedStats *stats =
clientModel->getPeerTableModel()->getNodeStats(
selected.indexes().first().row());
if (stats) {
updateNodeDetail(stats);
}
}

void RPCConsole::peerLayoutAboutToChange() {
QModelIndexList selected =
ui->peerWidget->selectionModel()->selectedIndexes();
Expand All @@ -1206,7 +1187,6 @@ void RPCConsole::peerLayoutChanged() {
return;
}

const CNodeCombinedStats *stats = nullptr;
bool fUnselect = false;
bool fReselect = false;

Expand Down Expand Up @@ -1237,9 +1217,6 @@ void RPCConsole::peerLayoutChanged() {
fUnselect = true;
fReselect = true;
}

// get fresh stats on the detail node.
stats = clientModel->getPeerTableModel()->getNodeStats(detailNodeRow);
}

if (fUnselect && selectedRow >= 0) {
Expand All @@ -1254,12 +1231,25 @@ void RPCConsole::peerLayoutChanged() {
}
}

if (stats) {
updateNodeDetail(stats);
}
updateDetailWidget();
}

void RPCConsole::updateNodeDetail(const CNodeCombinedStats *stats) {
void RPCConsole::updateDetailWidget() {
QModelIndexList selected_rows;
auto selection_model = ui->peerWidget->selectionModel();
if (selection_model) {
selected_rows = selection_model->selectedRows();
}
if (!clientModel || !clientModel->getPeerTableModel() ||
selected_rows.size() != 1) {
ui->detailWidget->hide();
ui->peerHeading->setText(
tr("Select a peer to view detailed information."));
return;
}
const CNodeCombinedStats *stats =
clientModel->getPeerTableModel()->getNodeStats(
selected_rows.first().row());
// update the detail ui with latest node information
QString peerAddrDetails(QString::fromStdString(stats->nodeStats.addrName) +
" ");
Expand Down Expand Up @@ -1448,8 +1438,7 @@ void RPCConsole::unbanSelectedNode() {
void RPCConsole::clearSelectedNode() {
ui->peerWidget->selectionModel()->clearSelection();
cachedNodeids.clear();
ui->detailWidget->hide();
ui->peerHeading->setText(tr("Select a peer to view detailed information."));
updateDetailWidget();
}

void RPCConsole::showOrHideBanTableIfRequired() {
Expand Down
7 changes: 2 additions & 5 deletions src/qt/rpcconsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ private Q_SLOTS:
void showOrHideBanTableIfRequired();
/** clear the selected node */
void clearSelectedNode();
/** show detailed information on ui about selected node */
void updateDetailWidget();

public Q_SLOTS:
void clear(bool clearHistory = true);
Expand All @@ -122,9 +124,6 @@ public Q_SLOTS:
void browseHistory(int offset);
/** Scroll console view to end */
void scrollToEnd();
/** Handle selection of peer in peers list */
void peerSelected(const QItemSelection &selected,
const QItemSelection &deselected);
/** Handle selection caching before update */
void peerLayoutAboutToChange();
/** Handle updated peer information */
Expand All @@ -145,8 +144,6 @@ public Q_SLOTS:
private:
void startExecutor();
void setTrafficGraphRange(int mins);
/** show detailed information on ui about selected node */
void updateNodeDetail(const CNodeCombinedStats *stats);

enum ColumnWidths {
ADDRESS_COLUMN_WIDTH = 200,
Expand Down

0 comments on commit 45627ee

Please sign in to comment.