23 if (
order == Qt::DescendingOrder) {
24 std::swap(pLeft, pRight);
60 cachedNodeStats.clear();
64 cachedNodeStats.reserve(nodes_stats.size());
65 for (
const auto &node_stats : nodes_stats) {
67 stats.
nodeStats = std::get<0>(node_stats);
70 cachedNodeStats.append(stats);
74 if (sortColumn >= 0) {
77 std::stable_sort(cachedNodeStats.begin(), cachedNodeStats.end(),
86 std::pair<NodeId, int>(stats.nodeStats.nodeid, row++));
90 int size()
const {
return cachedNodeStats.size(); }
93 if (idx >= 0 && idx < cachedNodeStats.size()) {
94 return &cachedNodeStats[idx];
102 : QAbstractTableModel(parent),
m_node(node), timer(nullptr) {
103 columns << tr(
"NodeId") << tr(
"Node/Service") << tr(
"Ping") << tr(
"Sent")
104 << tr(
"Received") << tr(
"User Agent");
108 timer =
new QTimer(
this);
139 if (!index.isValid()) {
146 if (role == Qt::DisplayRole) {
147 switch (index.column()) {
164 }
else if (role == Qt::TextAlignmentRole) {
165 switch (index.column()) {
169 return QVariant(Qt::AlignRight | Qt::AlignVCenter);
180 if (orientation == Qt::Horizontal) {
181 if (role == Qt::DisplayRole && section <
columns.size()) {
189 if (!index.isValid()) {
190 return Qt::NoItemFlags;
193 Qt::ItemFlags retval = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
198 const QModelIndex &parent)
const {
203 return createIndex(row, column, data);
205 return QModelIndex();
209 return priv->index(idx);
213 Q_EMIT layoutAboutToBeChanged();
215 Q_EMIT layoutChanged();
219 std::map<NodeId, int>::iterator it =
priv->mapNodeRows.find(nodeid);
220 if (it ==
priv->mapNodeRows.end()) {
228 priv->sortColumn = column;
229 priv->sortOrder = order;
void refreshPeers(interfaces::Node &node)
Pull a full list of peers from vNodes into our cache.
std::vector< std::tuple< CNodeStats, bool, CNodeStateStats > > NodesStats
Get stats for connected nodes.
int getRowByNodeId(NodeId nodeid)
bool operator()(const CNodeCombinedStats &left, const CNodeCombinedStats &right) const
CNodeStateStats nodeStateStats
QVariant data(const QModelIndex &index, int role) const override
int rowCount(const QModelIndex &parent) const override
QString formatBytes(uint64_t bytes)
CNodeCombinedStats * index(int idx)
QModelIndex index(int row, int column, const QModelIndex &parent) const override
NodeLessThan(int nColumn, Qt::SortOrder fOrder)
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
Qt::ItemFlags flags(const QModelIndex &index) const override
Qt::SortOrder sortOrder
Order (ascending or descending) to sort nodes by.
bool fNodeStateStatsAvailable
interfaces::Node & m_node
QString formatPingTime(int64_t ping_usec)
QList< CNodeCombinedStats > cachedNodeStats
Local cache of peer information.
std::unique_ptr< PeerTablePriv > priv
const CNodeCombinedStats * getNodeStats(int idx)
static const int MODEL_UPDATE_DELAY
void sort(int column, Qt::SortOrder order) override
std::map< NodeId, int > mapNodeRows
Index of rows by node ID.
virtual bool getNodesStats(NodesStats &stats)=0
POD that contains various stats about a node.
PeerTableModel(interfaces::Node &node, QObject *parent)
int columnCount(const QModelIndex &parent) const override
Top-level interface for a bitcoin node (bitcoind process).