From ac142488b44b5aba71c9b1a1d88043d0724fa685 Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Fri, 19 Aug 2016 15:38:04 -0400 Subject: [PATCH] gui: add NodeID to the peer table --- src/qt/guiutil.cpp | 8 ++++---- src/qt/guiutil.h | 2 +- src/qt/peertablemodel.cpp | 8 ++++++-- src/qt/peertablemodel.h | 7 ++++--- src/qt/rpcconsole.cpp | 6 +++--- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 96e78cd38..e5e046bfc 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -343,17 +343,17 @@ void copyEntryData(QAbstractItemView *view, int column, int role) } } -QString getEntryData(QAbstractItemView *view, int column, int role) +QVariant getEntryData(QAbstractItemView *view, int column, int role) { if(!view || !view->selectionModel()) - return QString(); + return QVariant(); QModelIndexList selection = view->selectionModel()->selectedRows(column); if(!selection.isEmpty()) { // Return first item - return (selection.at(0).data(role).toString()); + return (selection.at(0).data(role)); } - return QString(); + return QVariant(); } QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h index b6fe794b0..7e5c984c5 100644 --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -78,7 +78,7 @@ namespace GUIUtil @param[in] role Data role to extract from the model @see TransactionView::copyLabel, TransactionView::copyAmount, TransactionView::copyAddress */ - QString getEntryData(QAbstractItemView *view, int column, int role); + QVariant getEntryData(QAbstractItemView *view, int column, int role); void setClipboard(const QString& str); diff --git a/src/qt/peertablemodel.cpp b/src/qt/peertablemodel.cpp index 3829696e0..d6dc96b8a 100644 --- a/src/qt/peertablemodel.cpp +++ b/src/qt/peertablemodel.cpp @@ -24,6 +24,8 @@ bool NodeLessThan::operator()(const CNodeCombinedStats &left, const CNodeCombine switch(column) { + case PeerTableModel::NetNodeId: + return pLeft->nodeid < pRight->nodeid; case PeerTableModel::Address: return pLeft->addrName.compare(pRight->addrName) < 0; case PeerTableModel::Subversion: @@ -114,8 +116,8 @@ PeerTableModel::PeerTableModel(ClientModel *parent) : clientModel(parent), timer(0) { - columns << tr("Node/Service") << tr("User Agent") << tr("Ping Time"); - priv.reset(new PeerTablePriv()); + columns << tr("NodeId") << tr("Node/Service") << tr("User Agent") << tr("Ping Time"); + priv = new PeerTablePriv(); // default to unsorted priv->sortColumn = -1; @@ -165,6 +167,8 @@ QVariant PeerTableModel::data(const QModelIndex &index, int role) const if (role == Qt::DisplayRole) { switch(index.column()) { + case NetNodeId: + return rec->nodeStats.nodeid; case Address: return QString::fromStdString(rec->nodeStats.addrName); case Subversion: diff --git a/src/qt/peertablemodel.h b/src/qt/peertablemodel.h index 8227b5ec7..af34b147b 100644 --- a/src/qt/peertablemodel.h +++ b/src/qt/peertablemodel.h @@ -53,9 +53,10 @@ public: void stopAutoRefresh(); enum ColumnIndex { - Address = 0, - Subversion = 1, - Ping = 2 + NetNodeId = 0, + Address = 1, + Subversion = 2, + Ping = 3 }; /** @name Methods overridden from QAbstractTableModel diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 97a469a58..3a0075f3c 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -972,7 +972,7 @@ void RPCConsole::showBanTableContextMenu(const QPoint& point) void RPCConsole::disconnectSelectedNode() { // Get currently selected peer address - QString strNode = GUIUtil::getEntryData(ui->peerWidget, 0, PeerTableModel::Address); + QString strNode = GUIUtil::getEntryData(ui->peerWidget, 0, PeerTableModel::Address).toString(); // Find the node, disconnect it and clear the selected node if (CNode *bannedNode = FindNode(strNode.toStdString())) { bannedNode->fDisconnect = true; @@ -986,7 +986,7 @@ void RPCConsole::banSelectedNode(int bantime) return; // Get currently selected peer address - QString strNode = GUIUtil::getEntryData(ui->peerWidget, 0, PeerTableModel::Address); + QString strNode = GUIUtil::getEntryData(ui->peerWidget, 0, PeerTableModel::Address).toString(); // Find possible nodes, ban it and clear the selected node if (FindNode(strNode.toStdString())) { std::string nStr = strNode.toStdString(); @@ -1010,7 +1010,7 @@ void RPCConsole::unbanSelectedNode() return; // Get currently selected ban address - QString strNode = GUIUtil::getEntryData(ui->banlistWidget, 0, BanTableModel::Address); + QString strNode = GUIUtil::getEntryData(ui->banlistWidget, 0, BanTableModel::Address).toString(); CSubNet possibleSubnet; LookupSubNet(strNode.toStdString().c_str(), possibleSubnet);