mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-08-30 22:41:11 +02:00
qt: Use PeerTableSortProxy for sorting peer table
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
#include <qt/guiconstants.h>
|
#include <qt/guiconstants.h>
|
||||||
#include <qt/guiutil.h>
|
#include <qt/guiutil.h>
|
||||||
#include <qt/peertablemodel.h>
|
#include <qt/peertablemodel.h>
|
||||||
|
#include <qt/peertablesortproxy.h>
|
||||||
|
|
||||||
#include <clientversion.h>
|
#include <clientversion.h>
|
||||||
#include <interfaces/handler.h>
|
#include <interfaces/handler.h>
|
||||||
@@ -38,7 +39,11 @@ ClientModel::ClientModel(interfaces::Node& node, OptionsModel *_optionsModel, QO
|
|||||||
{
|
{
|
||||||
cachedBestHeaderHeight = -1;
|
cachedBestHeaderHeight = -1;
|
||||||
cachedBestHeaderTime = -1;
|
cachedBestHeaderTime = -1;
|
||||||
|
|
||||||
peerTableModel = new PeerTableModel(m_node, this);
|
peerTableModel = new PeerTableModel(m_node, this);
|
||||||
|
m_peer_table_sort_proxy = new PeerTableSortProxy(this);
|
||||||
|
m_peer_table_sort_proxy->setSourceModel(peerTableModel);
|
||||||
|
|
||||||
banTableModel = new BanTableModel(m_node, this);
|
banTableModel = new BanTableModel(m_node, this);
|
||||||
|
|
||||||
QTimer* timer = new QTimer;
|
QTimer* timer = new QTimer;
|
||||||
@@ -184,6 +189,11 @@ PeerTableModel *ClientModel::getPeerTableModel()
|
|||||||
return peerTableModel;
|
return peerTableModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PeerTableSortProxy* ClientModel::peerTableSortProxy()
|
||||||
|
{
|
||||||
|
return m_peer_table_sort_proxy;
|
||||||
|
}
|
||||||
|
|
||||||
BanTableModel *ClientModel::getBanTableModel()
|
BanTableModel *ClientModel::getBanTableModel()
|
||||||
{
|
{
|
||||||
return banTableModel;
|
return banTableModel;
|
||||||
|
@@ -17,6 +17,7 @@ class BanTableModel;
|
|||||||
class CBlockIndex;
|
class CBlockIndex;
|
||||||
class OptionsModel;
|
class OptionsModel;
|
||||||
class PeerTableModel;
|
class PeerTableModel;
|
||||||
|
class PeerTableSortProxy;
|
||||||
enum class SynchronizationState;
|
enum class SynchronizationState;
|
||||||
|
|
||||||
namespace interfaces {
|
namespace interfaces {
|
||||||
@@ -54,6 +55,7 @@ public:
|
|||||||
interfaces::Node& node() const { return m_node; }
|
interfaces::Node& node() const { return m_node; }
|
||||||
OptionsModel *getOptionsModel();
|
OptionsModel *getOptionsModel();
|
||||||
PeerTableModel *getPeerTableModel();
|
PeerTableModel *getPeerTableModel();
|
||||||
|
PeerTableSortProxy* peerTableSortProxy();
|
||||||
BanTableModel *getBanTableModel();
|
BanTableModel *getBanTableModel();
|
||||||
|
|
||||||
//! Return number of connections, default is in- and outbound (total)
|
//! Return number of connections, default is in- and outbound (total)
|
||||||
@@ -96,6 +98,7 @@ private:
|
|||||||
std::unique_ptr<interfaces::Handler> m_handler_notify_header_tip;
|
std::unique_ptr<interfaces::Handler> m_handler_notify_header_tip;
|
||||||
OptionsModel *optionsModel;
|
OptionsModel *optionsModel;
|
||||||
PeerTableModel *peerTableModel;
|
PeerTableModel *peerTableModel;
|
||||||
|
PeerTableSortProxy* m_peer_table_sort_proxy{nullptr};
|
||||||
BanTableModel *banTableModel;
|
BanTableModel *banTableModel;
|
||||||
|
|
||||||
//! A thread to interact with m_node asynchronously
|
//! A thread to interact with m_node asynchronously
|
||||||
|
@@ -194,10 +194,7 @@ QVariant PeerTableModel::data(const QModelIndex &index, int role) const
|
|||||||
} // no default case, so the compiler can warn about missing cases
|
} // no default case, so the compiler can warn about missing cases
|
||||||
assert(false);
|
assert(false);
|
||||||
} else if (role == StatsRole) {
|
} else if (role == StatsRole) {
|
||||||
switch (index.column()) {
|
return QVariant::fromValue(rec);
|
||||||
case NetNodeId: return QVariant::fromValue(rec);
|
|
||||||
default: return QVariant();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
@@ -9,13 +9,14 @@
|
|||||||
#include <qt/rpcconsole.h>
|
#include <qt/rpcconsole.h>
|
||||||
#include <qt/forms/ui_debugwindow.h>
|
#include <qt/forms/ui_debugwindow.h>
|
||||||
|
|
||||||
#include <qt/bantablemodel.h>
|
|
||||||
#include <qt/clientmodel.h>
|
|
||||||
#include <qt/platformstyle.h>
|
|
||||||
#include <qt/walletmodel.h>
|
|
||||||
#include <chainparams.h>
|
#include <chainparams.h>
|
||||||
#include <interfaces/node.h>
|
#include <interfaces/node.h>
|
||||||
#include <netbase.h>
|
#include <netbase.h>
|
||||||
|
#include <qt/bantablemodel.h>
|
||||||
|
#include <qt/clientmodel.h>
|
||||||
|
#include <qt/peertablesortproxy.h>
|
||||||
|
#include <qt/platformstyle.h>
|
||||||
|
#include <qt/walletmodel.h>
|
||||||
#include <rpc/client.h>
|
#include <rpc/client.h>
|
||||||
#include <rpc/server.h>
|
#include <rpc/server.h>
|
||||||
#include <util/strencodings.h>
|
#include <util/strencodings.h>
|
||||||
@@ -606,7 +607,7 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_
|
|||||||
connect(model, &ClientModel::mempoolSizeChanged, this, &RPCConsole::setMempoolSize);
|
connect(model, &ClientModel::mempoolSizeChanged, this, &RPCConsole::setMempoolSize);
|
||||||
|
|
||||||
// set up peer table
|
// set up peer table
|
||||||
ui->peerWidget->setModel(model->getPeerTableModel());
|
ui->peerWidget->setModel(model->peerTableSortProxy());
|
||||||
ui->peerWidget->verticalHeader()->hide();
|
ui->peerWidget->verticalHeader()->hide();
|
||||||
ui->peerWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
ui->peerWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||||
ui->peerWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
|
ui->peerWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||||
@@ -643,10 +644,7 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_
|
|||||||
|
|
||||||
// peer table signal handling - update peer details when selecting new node
|
// peer table signal handling - update peer details when selecting new node
|
||||||
connect(ui->peerWidget->selectionModel(), &QItemSelectionModel::selectionChanged, this, &RPCConsole::updateDetailWidget);
|
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::updateDetailWidget);
|
||||||
connect(model->getPeerTableModel(), &PeerTableModel::layoutChanged, this, &RPCConsole::peerLayoutChanged);
|
|
||||||
// peer table signal handling - cache selected node ids
|
|
||||||
connect(model->getPeerTableModel(), &PeerTableModel::layoutAboutToBeChanged, this, &RPCConsole::peerLayoutAboutToChange);
|
|
||||||
|
|
||||||
// set up ban table
|
// set up ban table
|
||||||
ui->banlistWidget->setModel(model->getBanTableModel());
|
ui->banlistWidget->setModel(model->getBanTableModel());
|
||||||
@@ -1037,67 +1035,6 @@ void RPCConsole::updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut)
|
|||||||
ui->lblBytesOut->setText(GUIUtil::formatBytes(totalBytesOut));
|
ui->lblBytesOut->setText(GUIUtil::formatBytes(totalBytesOut));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RPCConsole::peerLayoutAboutToChange()
|
|
||||||
{
|
|
||||||
cachedNodeids.clear();
|
|
||||||
for (const QModelIndex& peer : GUIUtil::getEntryData(ui->peerWidget, PeerTableModel::NetNodeId)) {
|
|
||||||
const auto stats = peer.data(PeerTableModel::StatsRole).value<CNodeCombinedStats*>();
|
|
||||||
cachedNodeids.append(stats->nodeStats.nodeid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void RPCConsole::peerLayoutChanged()
|
|
||||||
{
|
|
||||||
if (!clientModel || !clientModel->getPeerTableModel())
|
|
||||||
return;
|
|
||||||
|
|
||||||
bool fUnselect = false;
|
|
||||||
bool fReselect = false;
|
|
||||||
|
|
||||||
if (cachedNodeids.empty()) // no node selected yet
|
|
||||||
return;
|
|
||||||
|
|
||||||
// find the currently selected row
|
|
||||||
int selectedRow = -1;
|
|
||||||
QModelIndexList selectedModelIndex = ui->peerWidget->selectionModel()->selectedIndexes();
|
|
||||||
if (!selectedModelIndex.isEmpty()) {
|
|
||||||
selectedRow = selectedModelIndex.first().row();
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if our detail node has a row in the table (it may not necessarily
|
|
||||||
// be at selectedRow since its position can change after a layout change)
|
|
||||||
int detailNodeRow = clientModel->getPeerTableModel()->getRowByNodeId(cachedNodeids.first());
|
|
||||||
|
|
||||||
if (detailNodeRow < 0)
|
|
||||||
{
|
|
||||||
// detail node disappeared from table (node disconnected)
|
|
||||||
fUnselect = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (detailNodeRow != selectedRow)
|
|
||||||
{
|
|
||||||
// detail node moved position
|
|
||||||
fUnselect = true;
|
|
||||||
fReselect = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fUnselect && selectedRow >= 0) {
|
|
||||||
clearSelectedNode();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fReselect)
|
|
||||||
{
|
|
||||||
for(int i = 0; i < cachedNodeids.size(); i++)
|
|
||||||
{
|
|
||||||
ui->peerWidget->selectRow(clientModel->getPeerTableModel()->getRowByNodeId(cachedNodeids.at(i)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
updateDetailWidget();
|
|
||||||
}
|
|
||||||
|
|
||||||
void RPCConsole::updateDetailWidget()
|
void RPCConsole::updateDetailWidget()
|
||||||
{
|
{
|
||||||
const QList<QModelIndex> selected_peers = GUIUtil::getEntryData(ui->peerWidget, PeerTableModel::NetNodeId);
|
const QList<QModelIndex> selected_peers = GUIUtil::getEntryData(ui->peerWidget, PeerTableModel::NetNodeId);
|
||||||
|
@@ -118,10 +118,6 @@ public Q_SLOTS:
|
|||||||
void browseHistory(int offset);
|
void browseHistory(int offset);
|
||||||
/** Scroll console view to end */
|
/** Scroll console view to end */
|
||||||
void scrollToEnd();
|
void scrollToEnd();
|
||||||
/** Handle selection caching before update */
|
|
||||||
void peerLayoutAboutToChange();
|
|
||||||
/** Handle updated peer information */
|
|
||||||
void peerLayoutChanged();
|
|
||||||
/** Disconnect a selected node on the Peers tab */
|
/** Disconnect a selected node on the Peers tab */
|
||||||
void disconnectSelectedNode();
|
void disconnectSelectedNode();
|
||||||
/** Ban a selected node on the Peers tab */
|
/** Ban a selected node on the Peers tab */
|
||||||
|
Reference in New Issue
Block a user