12 #include "validation.h" 24 if (
order == Qt::DescendingOrder)
25 std::swap(pLeft, pRight);
63 cachedNodeStats.clear();
64 std::vector<CNodeStats> vstats;
67 #if QT_VERSION >= 0x040700 68 cachedNodeStats.reserve(vstats.size());
78 cachedNodeStats.append(stats);
88 stats.fNodeStateStatsAvailable =
GetNodeStateStats(stats.nodeStats.nodeid, stats.nodeStateStats);
94 qStableSort(cachedNodeStats.begin(), cachedNodeStats.end(),
NodeLessThan(sortColumn, sortOrder));
100 mapNodeRows.insert(std::pair<NodeId, int>(stats.nodeStats.nodeid, row++));
105 return cachedNodeStats.size();
110 if (idx >= 0 && idx < cachedNodeStats.size())
111 return &cachedNodeStats[idx];
118 QAbstractTableModel(parent),
122 columns << tr(
"NodeId") << tr(
"Node/Service") << tr(
"Ping") << tr(
"Sent") << tr(
"Received") << tr(
"User Agent");
125 priv->sortColumn = -1;
128 timer =
new QTimer(
this);
130 timer->setInterval(MODEL_UPDATE_DELAY);
170 if (role == Qt::DisplayRole) {
171 switch(index.column())
186 }
else if (role == Qt::TextAlignmentRole) {
187 switch (index.column()) {
191 return QVariant(Qt::AlignRight | Qt::AlignVCenter);
202 if(orientation == Qt::Horizontal)
204 if(role == Qt::DisplayRole && section <
columns.size())
217 Qt::ItemFlags retval = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
227 return createIndex(row, column, data);
228 return QModelIndex();
233 return priv->index(idx);
238 Q_EMIT layoutAboutToBeChanged();
239 priv->refreshPeers();
240 Q_EMIT layoutChanged();
245 std::map<NodeId, int>::iterator it =
priv->mapNodeRows.find(nodeid);
246 if (it ==
priv->mapNodeRows.end())
254 priv->sortColumn = column;
255 priv->sortOrder = order;
QVariant data(const QModelIndex &index, int role) const
int getRowByNodeId(NodeId nodeid)
bool operator()(const CNodeCombinedStats &left, const CNodeCombinedStats &right) const
CNodeStateStats nodeStateStats
#define TRY_LOCK(cs, name)
void refreshPeers()
Pull a full list of peers from vNodes into our cache.
int sortColumn
Column to sort nodes by.
bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats)
Get statistics from node state.
CCriticalSection cs_main
Global state.
QString formatBytes(uint64_t bytes)
CNodeCombinedStats * index(int idx)
NodeLessThan(int nColumn, Qt::SortOrder fOrder)
Qt::ItemFlags flags(const QModelIndex &index) const
Qt::SortOrder sortOrder
Order (ascending or descending) to sort nodes by.
int columnCount(const QModelIndex &parent) const
bool fNodeStateStatsAvailable
QList< CNodeCombinedStats > cachedNodeStats
Local cache of peer information.
std::unique_ptr< PeerTablePriv > priv
const CNodeCombinedStats * getNodeStats(int idx)
QModelIndex index(int row, int column, const QModelIndex &parent) const
Model for Raven network client.
QString formatPingTime(double dPingTime)
std::map< NodeId, int > mapNodeRows
Index of rows by node ID.
std::unique_ptr< CConnman > g_connman
void sort(int column, Qt::SortOrder order)
PeerTableModel(ClientModel *parent=0)
int rowCount(const QModelIndex &parent) const
QVariant headerData(int section, Qt::Orientation orientation, int role) const