18 : QAbstractTableModel(parent),
22 timer =
new QTimer(
this);
44 if (parent.isValid()) {
52 if (parent.isValid()) {
66 if (role == Qt::DisplayRole) {
94 }
else if (role == Qt::TextAlignmentRole) {
98 return QVariant(Qt::AlignRight | Qt::AlignVCenter);
104 return QVariant(Qt::AlignCenter);
108 return QVariant(Qt::AlignRight | Qt::AlignVCenter);
114 return QVariant::fromValue(rec);
122 if(orientation == Qt::Horizontal)
124 if(role == Qt::DisplayRole && section <
columns.size())
134 if (!
index.isValid())
return Qt::NoItemFlags;
136 Qt::ItemFlags retval = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
148 return QModelIndex();
156 new_peers_data.reserve(nodes_stats.size());
157 for (
const auto& node_stats : nodes_stats) {
158 const CNodeCombinedStats stats{std::get<0>(node_stats), std::get<2>(node_stats), std::get<1>(node_stats)};
159 new_peers_data.append(stats);
168 if (i < new_peers_data.size() &&
m_peers_data.at(i).nodeStats.nodeid == new_peers_data.at(i).nodeStats.nodeid) {
173 beginRemoveRows(QModelIndex(), i, i);
180 beginInsertRows(QModelIndex(),
m_peers_data.size(), new_peers_data.size() - 1);
187 const auto top_left =
index(0, 0);
189 Q_EMIT dataChanged(top_left, bottom_right);
ConnectionType m_conn_type
std::chrono::microseconds m_min_ping_time
std::chrono::seconds m_connected
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Qt::ItemFlags flags(const QModelIndex &index) const override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
interfaces::Node & m_node
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
QList< CNodeCombinedStats > m_peers_data
Internal peer data structure.
const QStringList columns
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
PeerTableModel(interfaces::Node &node, QObject *parent)
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Top-level interface for a bitcoin node (bitcoind process).
std::vector< std::tuple< CNodeStats, bool, CNodeStateStats > > NodesStats
Get stats for connected nodes.
virtual bool getNodesStats(NodesStats &stats)=0
static constexpr auto MODEL_UPDATE_DELAY
QString NetworkToQString(Network net)
Convert enum Network to QString.
QString formatBytes(uint64_t bytes)
QString formatPingTime(std::chrono::microseconds ping_time)
Format a CNodeStats.m_last_ping_time into a user-readable string or display N/A, if 0.
QString ConnectionTypeToQString(ConnectionType conn_type, bool prepend_direction)
Convert enum ConnectionType to QString.
QString FormatPeerAge(std::chrono::seconds time_connected)
Convert peer connection time to a QString denominated in the most relevant unit.