Skip to content

Commit 1077577

Browse files
committed
Fix auto-deselection of peers
1 parent addfdeb commit 1077577

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

src/qt/rpcconsole.cpp

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,6 @@ RPCConsole::RPCConsole(const PlatformStyle *_platformStyle, QWidget *parent) :
343343
ui(new Ui::RPCConsole),
344344
clientModel(0),
345345
historyPtr(0),
346-
cachedNodeid(-1),
347346
platformStyle(_platformStyle),
348347
peersTableContextMenu(0),
349348
banTableContextMenu(0),
@@ -514,7 +513,9 @@ void RPCConsole::setClientModel(ClientModel *model)
514513
this, SLOT(peerSelected(const QItemSelection &, const QItemSelection &)));
515514
// peer table signal handling - update peer details when new nodes are added to the model
516515
connect(model->getPeerTableModel(), SIGNAL(layoutChanged()), this, SLOT(peerLayoutChanged()));
517-
516+
// peer table signal handling - cache selected node ids
517+
connect(model->getPeerTableModel(), SIGNAL(layoutAboutToChange()), this, SLOT(peerLayoutAboutToChange()));
518+
518519
// set up ban table
519520
ui->banlistWidget->setModel(model->getBanTableModel());
520521
ui->banlistWidget->verticalHeader()->hide();
@@ -825,6 +826,17 @@ void RPCConsole::peerSelected(const QItemSelection &selected, const QItemSelecti
825826
updateNodeDetail(stats);
826827
}
827828

829+
void RPCConsole::peerLayoutAboutToChange()
830+
{
831+
QModelIndexList selected = ui->peerWidget->selectionModel()->selectedIndexes();
832+
cachedNodeids.clear();
833+
for(int i = 0; i < selected.size(); i++)
834+
{
835+
const CNodeCombinedStats *stats = clientModel->getPeerTableModel()->getNodeStats(selected.at(i).row());
836+
cachedNodeids.append(stats->nodeStats.nodeid);
837+
}
838+
}
839+
828840
void RPCConsole::peerLayoutChanged()
829841
{
830842
if (!clientModel || !clientModel->getPeerTableModel())
@@ -834,7 +846,7 @@ void RPCConsole::peerLayoutChanged()
834846
bool fUnselect = false;
835847
bool fReselect = false;
836848

837-
if (cachedNodeid == -1) // no node selected yet
849+
if (cachedNodeids.empty()) // no node selected yet
838850
return;
839851

840852
// find the currently selected row
@@ -846,7 +858,7 @@ void RPCConsole::peerLayoutChanged()
846858

847859
// check if our detail node has a row in the table (it may not necessarily
848860
// be at selectedRow since its position can change after a layout change)
849-
int detailNodeRow = clientModel->getPeerTableModel()->getRowByNodeId(cachedNodeid);
861+
int detailNodeRow = clientModel->getPeerTableModel()->getRowByNodeId(cachedNodeids.first());
850862

851863
if (detailNodeRow < 0)
852864
{
@@ -872,7 +884,10 @@ void RPCConsole::peerLayoutChanged()
872884

873885
if (fReselect)
874886
{
875-
ui->peerWidget->selectRow(detailNodeRow);
887+
for(int i = 0; i < cachedNodeids.size(); i++)
888+
{
889+
ui->peerWidget->selectRow(clientModel->getPeerTableModel()->getRowByNodeId(cachedNodeids.at(i)));
890+
}
876891
}
877892

878893
if (stats)
@@ -881,9 +896,6 @@ void RPCConsole::peerLayoutChanged()
881896

882897
void RPCConsole::updateNodeDetail(const CNodeCombinedStats *stats)
883898
{
884-
// Update cached nodeid
885-
cachedNodeid = stats->nodeStats.nodeid;
886-
887899
// update the detail ui with latest node information
888900
QString peerAddrDetails(QString::fromStdString(stats->nodeStats.addrName) + " ");
889901
peerAddrDetails += tr("(node id: %1)").arg(QString::number(stats->nodeStats.nodeid));
@@ -1038,7 +1050,7 @@ void RPCConsole::unbanSelectedNode()
10381050
void RPCConsole::clearSelectedNode()
10391051
{
10401052
ui->peerWidget->selectionModel()->clearSelection();
1041-
cachedNodeid = -1;
1053+
cachedNodeids.clear();
10421054
ui->detailWidget->hide();
10431055
ui->peerHeading->setText(tr("Select a peer to view detailed information."));
10441056
}

src/qt/rpcconsole.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ public Q_SLOTS:
9898
void scrollToEnd();
9999
/** Handle selection of peer in peers list */
100100
void peerSelected(const QItemSelection &selected, const QItemSelection &deselected);
101+
/** Handle selection caching before update */
102+
void peerLayoutAboutToChange();
101103
/** Handle updated peer information */
102104
void peerLayoutChanged();
103105
/** Disconnect a selected node on the Peers tab */
@@ -135,7 +137,7 @@ public Q_SLOTS:
135137
ClientModel *clientModel;
136138
QStringList history;
137139
int historyPtr;
138-
NodeId cachedNodeid;
140+
QList<NodeId> cachedNodeids;
139141
const PlatformStyle *platformStyle;
140142
RPCTimerInterface *rpcTimerInterface;
141143
QMenu *peersTableContextMenu;

0 commit comments

Comments
 (0)