23 if (
order == Qt::DescendingOrder)
24 std::swap(pLeft, pRight);
62 cachedNodeStats.clear();
66 cachedNodeStats.reserve(nodes_stats.size());
67 for (
const auto& node_stats : nodes_stats)
70 stats.
nodeStats = std::get<0>(node_stats);
73 cachedNodeStats.append(stats);
85 mapNodeRows.insert(std::pair<NodeId, int>(stats.nodeStats.nodeid, row++));
90 return cachedNodeStats.size();
95 if (idx >= 0 && idx < cachedNodeStats.size())
96 return &cachedNodeStats[idx];
103 QAbstractTableModel(parent),
107 columns << tr(
"NodeId") << tr(
"Node/Service") << tr(
"Ping") << tr(
"Sent") << tr(
"Received") << tr(
"User Agent");
111 timer =
new QTimer(
this);
153 if (role == Qt::DisplayRole) {
154 switch(index.column())
170 }
else if (role == Qt::TextAlignmentRole) {
171 switch (index.column()) {
175 return QVariant(Qt::AlignRight | Qt::AlignVCenter);
186 if(orientation == Qt::Horizontal)
188 if(role == Qt::DisplayRole && section <
columns.size())
198 if (!index.isValid())
return Qt::NoItemFlags;
200 Qt::ItemFlags retval = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
210 return createIndex(row, column, data);
211 return QModelIndex();
216 return priv->index(idx);
221 Q_EMIT layoutAboutToBeChanged();
223 Q_EMIT layoutChanged();
228 std::map<NodeId, int>::iterator
it =
priv->mapNodeRows.find(nodeid);
229 if (it ==
priv->mapNodeRows.end())
237 priv->sortColumn = column;
238 priv->sortOrder = order;
void refreshPeers(interfaces::Node &node)
Pull a full list of peers from vNodes into our cache.
int getRowByNodeId(NodeId nodeid)
CNodeStateStats nodeStateStats
int sortColumn
Column to sort nodes by (default to unsorted)
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
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
std::vector< std::tuple< CNodeStats, bool, CNodeStateStats >> NodesStats
Get stats for connected nodes.
const CNodeCombinedStats * getNodeStats(int idx)
bool operator()(const CNodeCombinedStats &left, const CNodeCombinedStats &right) const
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
PeerTableModel(interfaces::Node &node, QObject *parent)
int columnCount(const QModelIndex &parent) const override
Top-level interface for a bitcoin node (bitcoind process).