From 648d6f04fb437db427435f0253c8c8db3b3bfcf2 Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Fri, 20 Nov 2020 09:37:59 +0100 Subject: [PATCH] Merge bitcoin-core/gui#13: Hide peer detail view if multiple are selected MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 76277cc77dea39b53e09ee1c440cd37270826201 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 76277cc77dea39b53e09ee1c440cd37270826201. hebasto: ACK 76277cc77dea39b53e09ee1c440cd37270826201, tested on Linux Mint 20 (Qt 5.12.8). Tree-SHA512: 16c9cfd6ccb7077a9f31917a6cb3532e32d17d21f735e43bf4720fb0c8bb1bd539d42569c105df4b551f5dccb4acaeedb6bb2362620a9cb9267a602d9d065b9f --- src/qt/rpcconsole.cpp | 38 ++++++++++++++------------------------ src/qt/rpcconsole.h | 6 ++---- 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 9a05ddb62b..44b51d61d0 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -510,8 +510,7 @@ RPCConsole::RPCConsole(interfaces::Node& node, QWidget* parent, Qt::WindowFlags m_node.rpcSetTimerInterfaceIfUnset(rpcTimerInterface); setTrafficGraphRange(INITIAL_TRAFFIC_GRAPH_SETTING); - - ui->peerHeading->setText(tr("Select a peer to view detailed information.")); + updateDetailWidget(); setFontSize(settings.value(fontSizeSettingsKey, QFontInfo(QFontDatabase::systemFont(QFontDatabase::FixedFont)).pointSize()).toInt()); @@ -660,7 +659,7 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_ connect(disconnectAction, &QAction::triggered, this, &RPCConsole::disconnectSelectedNode); // peer table signal handling - update peer details when selecting new node - connect(ui->peerWidget->selectionModel(), &QItemSelectionModel::selectionChanged, this, &RPCConsole::peerSelected); + connect(ui->peerWidget->selectionModel(), &QItemSelectionModel::selectionChanged, this, &RPCConsole::updateDetailWidget); // peer table signal handling - update peer details when new nodes are added to the model connect(model->getPeerTableModel(), &PeerTableModel::layoutChanged, this, &RPCConsole::peerLayoutChanged); // peer table signal handling - cache selected node ids @@ -1154,18 +1153,6 @@ void RPCConsole::setTrafficGraphRange(TrafficGraphData::GraphRange range) ui->lblGraphRange->setText(GUIUtil::formatDurationStr(TrafficGraphData::RangeMinutes[range] * 60)); } -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(); @@ -1182,7 +1169,6 @@ void RPCConsole::peerLayoutChanged() if (!clientModel || !clientModel->getPeerTableModel()) return; - const CNodeCombinedStats *stats = nullptr; bool fUnselect = false; bool fReselect = false; @@ -1213,9 +1199,6 @@ void RPCConsole::peerLayoutChanged() fUnselect = true; fReselect = true; } - - // get fresh stats on the detail node. - stats = clientModel->getPeerTableModel()->getNodeStats(detailNodeRow); } if (fUnselect && selectedRow >= 0) { @@ -1230,12 +1213,20 @@ 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) + " "); peerAddrDetails += tr("(peer id: %1)").arg(QString::number(stats->nodeStats.nodeid)); @@ -1442,8 +1433,7 @@ 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() diff --git a/src/qt/rpcconsole.h b/src/qt/rpcconsole.h index 79af6df9a3..1d7fccc304 100644 --- a/src/qt/rpcconsole.h +++ b/src/qt/rpcconsole.h @@ -99,6 +99,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); @@ -132,8 +134,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 */ @@ -158,8 +158,6 @@ private: void setTrafficGraphRange(TrafficGraphData::GraphRange range); /** Build parameter list for restart */ void buildParameterlist(QString arg); - /** show detailed information on ui about selected node */ - void updateNodeDetail(const CNodeCombinedStats *stats); /** Set required icons for buttons inside the dialog */ void setButtonIcons(); /** Reload some themes related widgets */