Skip to content

Commit addfdeb

Browse files
committed
Multiple Selection for peer and ban tables
Allows multiple selection and action for the nodes in the peer and ban tables in the Debug Window.
1 parent 4e57824 commit addfdeb

File tree

3 files changed

+55
-46
lines changed

3 files changed

+55
-46
lines changed

src/qt/guiutil.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -291,17 +291,11 @@ void copyEntryData(QAbstractItemView *view, int column, int role)
291291
}
292292
}
293293

294-
QVariant getEntryData(QAbstractItemView *view, int column, int role)
294+
QList<QModelIndex> getEntryData(QAbstractItemView *view, int column)
295295
{
296296
if(!view || !view->selectionModel())
297-
return QVariant();
298-
QModelIndexList selection = view->selectionModel()->selectedRows(column);
299-
300-
if(!selection.isEmpty()) {
301-
// Return first item
302-
return (selection.at(0).data(role));
303-
}
304-
return QVariant();
297+
return QList<QModelIndex>();
298+
return view->selectionModel()->selectedRows(column);
305299
}
306300

307301
QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir,

src/qt/guiutil.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,9 @@ namespace GUIUtil
6767
/** Return a field of the currently selected entry as a QString. Does nothing if nothing
6868
is selected.
6969
@param[in] column Data column to extract from the model
70-
@param[in] role Data role to extract from the model
7170
@see TransactionView::copyLabel, TransactionView::copyAmount, TransactionView::copyAddress
7271
*/
73-
QVariant getEntryData(QAbstractItemView *view, int column, int role);
72+
QList<QModelIndex> getEntryData(QAbstractItemView *view, int column);
7473

7574
void setClipboard(const QString& str);
7675

src/qt/rpcconsole.cpp

Lines changed: 51 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -469,19 +469,19 @@ void RPCConsole::setClientModel(ClientModel *model)
469469
ui->peerWidget->verticalHeader()->hide();
470470
ui->peerWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
471471
ui->peerWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
472-
ui->peerWidget->setSelectionMode(QAbstractItemView::SingleSelection);
472+
ui->peerWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
473473
ui->peerWidget->setContextMenuPolicy(Qt::CustomContextMenu);
474474
ui->peerWidget->setColumnWidth(PeerTableModel::Address, ADDRESS_COLUMN_WIDTH);
475475
ui->peerWidget->setColumnWidth(PeerTableModel::Subversion, SUBVERSION_COLUMN_WIDTH);
476476
ui->peerWidget->setColumnWidth(PeerTableModel::Ping, PING_COLUMN_WIDTH);
477477
ui->peerWidget->horizontalHeader()->setStretchLastSection(true);
478478

479479
// create peer table context menu actions
480-
QAction* disconnectAction = new QAction(tr("&Disconnect Node"), this);
481-
QAction* banAction1h = new QAction(tr("Ban Node for") + " " + tr("1 &hour"), this);
482-
QAction* banAction24h = new QAction(tr("Ban Node for") + " " + tr("1 &day"), this);
483-
QAction* banAction7d = new QAction(tr("Ban Node for") + " " + tr("1 &week"), this);
484-
QAction* banAction365d = new QAction(tr("Ban Node for") + " " + tr("1 &year"), this);
480+
QAction* disconnectAction = new QAction(tr("&Disconnect"), this);
481+
QAction* banAction1h = new QAction(tr("Ban for") + " " + tr("1 &hour"), this);
482+
QAction* banAction24h = new QAction(tr("Ban for") + " " + tr("1 &day"), this);
483+
QAction* banAction7d = new QAction(tr("Ban for") + " " + tr("1 &week"), this);
484+
QAction* banAction365d = new QAction(tr("Ban for") + " " + tr("1 &year"), this);
485485

486486
// create peer table context menu
487487
peersTableContextMenu = new QMenu();
@@ -527,7 +527,7 @@ void RPCConsole::setClientModel(ClientModel *model)
527527
ui->banlistWidget->horizontalHeader()->setStretchLastSection(true);
528528

529529
// create ban table context menu action
530-
QAction* unbanAction = new QAction(tr("&Unban Node"), this);
530+
QAction* unbanAction = new QAction(tr("&Unban"), this);
531531

532532
// create ban table context menu
533533
banTableContextMenu = new QMenu();
@@ -973,49 +973,65 @@ void RPCConsole::disconnectSelectedNode()
973973
{
974974
if(!g_connman)
975975
return;
976-
// Get currently selected peer address
977-
NodeId id = GUIUtil::getEntryData(ui->peerWidget, 0, PeerTableModel::NetNodeId).toInt();
978-
// Find the node, disconnect it and clear the selected node
979-
if(g_connman->DisconnectNode(id))
980-
clearSelectedNode();
976+
977+
// Get selected peer addresses
978+
QList<QModelIndex> nodes = GUIUtil::getEntryData(ui->peerWidget, 0);
979+
for(int i = 0; i < nodes.count(); i++)
980+
{
981+
// Get currently selected peer address
982+
NodeId id = nodes.at(i).data(PeerTableModel::NetNodeId).toInt();
983+
// Find the node, disconnect it and clear the selected node
984+
if(g_connman->DisconnectNode(id))
985+
clearSelectedNode();
986+
}
981987
}
982988

983989
void RPCConsole::banSelectedNode(int bantime)
984990
{
985991
if (!clientModel || !g_connman)
986992
return;
987-
988-
if(cachedNodeid == -1)
989-
return;
990-
991-
// Get currently selected peer address
992-
int detailNodeRow = clientModel->getPeerTableModel()->getRowByNodeId(cachedNodeid);
993-
if(detailNodeRow < 0)
994-
return;
995-
996-
// Find possible nodes, ban it and clear the selected node
997-
const CNodeCombinedStats *stats = clientModel->getPeerTableModel()->getNodeStats(detailNodeRow);
998-
if(stats) {
999-
g_connman->Ban(stats->nodeStats.addr, BanReasonManuallyAdded, bantime);
1000-
clearSelectedNode();
1001-
clientModel->getBanTableModel()->refresh();
993+
994+
// Get selected peer addresses
995+
QList<QModelIndex> nodes = GUIUtil::getEntryData(ui->peerWidget, 0);
996+
for(int i = 0; i < nodes.count(); i++)
997+
{
998+
// Get currently selected peer address
999+
NodeId id = nodes.at(i).data(PeerTableModel::NetNodeId).toInt();
1000+
1001+
// Get currently selected peer address
1002+
int detailNodeRow = clientModel->getPeerTableModel()->getRowByNodeId(id);
1003+
if(detailNodeRow < 0)
1004+
return;
1005+
1006+
// Find possible nodes, ban it and clear the selected node
1007+
const CNodeCombinedStats *stats = clientModel->getPeerTableModel()->getNodeStats(detailNodeRow);
1008+
if(stats) {
1009+
g_connman->Ban(stats->nodeStats.addr, BanReasonManuallyAdded, bantime);
1010+
}
10021011
}
1012+
clearSelectedNode();
1013+
clientModel->getBanTableModel()->refresh();
10031014
}
10041015

10051016
void RPCConsole::unbanSelectedNode()
10061017
{
10071018
if (!clientModel)
10081019
return;
10091020

1010-
// Get currently selected ban address
1011-
QString strNode = GUIUtil::getEntryData(ui->banlistWidget, 0, BanTableModel::Address).toString();
1012-
CSubNet possibleSubnet;
1013-
1014-
LookupSubNet(strNode.toStdString().c_str(), possibleSubnet);
1015-
if (possibleSubnet.IsValid() && g_connman)
1021+
// Get selected ban addresses
1022+
QList<QModelIndex> nodes = GUIUtil::getEntryData(ui->banlistWidget, 0);
1023+
for(int i = 0; i < nodes.count(); i++)
10161024
{
1017-
g_connman->Unban(possibleSubnet);
1018-
clientModel->getBanTableModel()->refresh();
1025+
// Get currently selected ban address
1026+
QString strNode = nodes.at(i).data(BanTableModel::Address).toString();
1027+
CSubNet possibleSubnet;
1028+
1029+
LookupSubNet(strNode.toStdString().c_str(), possibleSubnet);
1030+
if (possibleSubnet.IsValid() && g_connman)
1031+
{
1032+
g_connman->Unban(possibleSubnet);
1033+
clientModel->getBanTableModel()->refresh();
1034+
}
10191035
}
10201036
}
10211037

0 commit comments

Comments
 (0)