mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 02:33:24 -03:00
qt: Use PeerTableModel::StatsRole
This change prevents direct calls to the PeerTableModel object that is a layer violation.
This commit is contained in:
parent
35007edf9c
commit
49c604077c
1 changed files with 7 additions and 21 deletions
|
@ -1018,11 +1018,9 @@ void RPCConsole::updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut)
|
|||
|
||||
void RPCConsole::peerLayoutAboutToChange()
|
||||
{
|
||||
QModelIndexList selected = ui->peerWidget->selectionModel()->selectedIndexes();
|
||||
cachedNodeids.clear();
|
||||
for(int i = 0; i < selected.size(); i++)
|
||||
{
|
||||
const CNodeCombinedStats *stats = clientModel->getPeerTableModel()->getNodeStats(selected.at(i).row());
|
||||
for (const QModelIndex& peer : GUIUtil::getEntryData(ui->peerWidget, PeerTableModel::NetNodeId)) {
|
||||
const auto stats = peer.data(PeerTableModel::StatsRole).value<CNodeCombinedStats*>();
|
||||
cachedNodeids.append(stats->nodeStats.nodeid);
|
||||
}
|
||||
}
|
||||
|
@ -1081,15 +1079,13 @@ void RPCConsole::peerLayoutChanged()
|
|||
|
||||
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) {
|
||||
const QList<QModelIndex> selected_peers = GUIUtil::getEntryData(ui->peerWidget, PeerTableModel::NetNodeId);
|
||||
if (!clientModel || !clientModel->getPeerTableModel() || selected_peers.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());
|
||||
const auto stats = selected_peers.first().data(PeerTableModel::StatsRole).value<CNodeCombinedStats*>();
|
||||
// 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));
|
||||
|
@ -1202,19 +1198,9 @@ void RPCConsole::banSelectedNode(int bantime)
|
|||
if (!clientModel)
|
||||
return;
|
||||
|
||||
// Get selected peer addresses
|
||||
QList<QModelIndex> nodes = GUIUtil::getEntryData(ui->peerWidget, PeerTableModel::NetNodeId);
|
||||
for(int i = 0; i < nodes.count(); i++)
|
||||
{
|
||||
// Get currently selected peer address
|
||||
NodeId id = nodes.at(i).data().toLongLong();
|
||||
|
||||
// Get currently selected peer address
|
||||
int detailNodeRow = clientModel->getPeerTableModel()->getRowByNodeId(id);
|
||||
if (detailNodeRow < 0) return;
|
||||
|
||||
for (const QModelIndex& peer : GUIUtil::getEntryData(ui->peerWidget, PeerTableModel::NetNodeId)) {
|
||||
// Find possible nodes, ban it and clear the selected node
|
||||
const CNodeCombinedStats *stats = clientModel->getPeerTableModel()->getNodeStats(detailNodeRow);
|
||||
const auto stats = peer.data(PeerTableModel::StatsRole).value<CNodeCombinedStats*>();
|
||||
if (stats) {
|
||||
m_node.ban(stats->nodeStats.addr, bantime);
|
||||
m_node.disconnectByAddress(stats->nodeStats.addr);
|
||||
|
|
Loading…
Add table
Reference in a new issue