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
  • Loading branch information
promag committed Jun 29, 2020
1 parent 4946400 commit df2987a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 28 deletions.
37 changes: 13 additions & 24 deletions src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,7 @@ RPCConsole::RPCConsole(interfaces::Node& node, const PlatformStyle *_platformSty
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();
clear();
Expand Down Expand Up @@ -625,7 +623,7 @@ void RPCConsole::setClientModel(ClientModel *model)
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
Expand Down Expand Up @@ -1017,18 +1015,6 @@ void RPCConsole::updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut)
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 @@ -1045,7 +1031,6 @@ void RPCConsole::peerLayoutChanged()
if (!clientModel || !clientModel->getPeerTableModel())
return;

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

Expand Down Expand Up @@ -1078,7 +1063,6 @@ void RPCConsole::peerLayoutChanged()
}

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

if (fUnselect && selectedRow >= 0) {
Expand All @@ -1092,13 +1076,19 @@ void RPCConsole::peerLayoutChanged()
ui->peerWidget->selectRow(clientModel->getPeerTableModel()->getRowByNodeId(cachedNodeids.at(i)));
}
}

if (stats)
updateNodeDetail(stats);
}

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("(node id: %1)").arg(QString::number(stats->nodeStats.nodeid));
Expand Down Expand Up @@ -1251,8 +1241,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()
Expand Down
6 changes: 2 additions & 4 deletions src/qt/rpcconsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,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 @@ -115,8 +117,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 @@ -137,8 +137,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
{
Expand Down

0 comments on commit df2987a

Please sign in to comment.