Bitcoin Core  21.99.0
P2P Digital Currency
peertablemodel.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2020 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_QT_PEERTABLEMODEL_H
6 #define BITCOIN_QT_PEERTABLEMODEL_H
7 
8 #include <net_processing.h> // For CNodeStateStats
9 #include <net.h>
10 
11 #include <memory>
12 
13 #include <QAbstractTableModel>
14 #include <QStringList>
15 
16 class PeerTablePriv;
17 
18 namespace interfaces {
19 class Node;
20 }
21 
22 QT_BEGIN_NAMESPACE
23 class QTimer;
24 QT_END_NAMESPACE
25 
30 };
31 Q_DECLARE_METATYPE(CNodeCombinedStats*)
32 
34 {
35 public:
36  NodeLessThan(int nColumn, Qt::SortOrder fOrder) :
37  column(nColumn), order(fOrder) {}
38  bool operator()(const CNodeCombinedStats &left, const CNodeCombinedStats &right) const;
39 
40 private:
41  int column;
42  Qt::SortOrder order;
43 };
44 
49 class PeerTableModel : public QAbstractTableModel
50 {
51  Q_OBJECT
52 
53 public:
54  explicit PeerTableModel(interfaces::Node& node, QObject* parent);
56  int getRowByNodeId(NodeId nodeid);
57  void startAutoRefresh();
58  void stopAutoRefresh();
59 
60  enum ColumnIndex {
61  NetNodeId = 0,
69  };
70 
71  enum {
72  StatsRole = Qt::UserRole,
73  };
74 
77  int rowCount(const QModelIndex &parent) const override;
78  int columnCount(const QModelIndex &parent) const override;
79  QVariant data(const QModelIndex &index, int role) const override;
80  QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
81  QModelIndex index(int row, int column, const QModelIndex &parent) const override;
82  Qt::ItemFlags flags(const QModelIndex &index) const override;
83  void sort(int column, Qt::SortOrder order) override;
86 public Q_SLOTS:
87  void refresh();
88 
89 private:
91  const QStringList columns{tr("Peer Id"), tr("Address"), tr("Type"), tr("Network"), tr("Ping"), tr("Sent"), tr("Received"), tr("User Agent")};
92  std::unique_ptr<PeerTablePriv> priv;
93  QTimer *timer;
94 };
95 
96 #endif // BITCOIN_QT_PEERTABLEMODEL_H
PeerTableModel::Received
@ Received
Definition: peertablemodel.h:67
NodeId
int64_t NodeId
Definition: net.h:90
interfaces
Definition: dummywallet.cpp:10
PeerTableModel::PeerTableModel
PeerTableModel(interfaces::Node &node, QObject *parent)
Definition: peertablemodel.cpp:104
PeerTableModel::NetNodeId
@ NetNodeId
Definition: peertablemodel.h:61
PeerTableModel::data
QVariant data(const QModelIndex &index, int role) const override
Definition: peertablemodel.cpp:151
PeerTableModel::headerData
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
Definition: peertablemodel.cpp:206
CNodeCombinedStats::nodeStats
CNodeStats nodeStats
Definition: peertablemodel.h:27
NodeLessThan::NodeLessThan
NodeLessThan(int nColumn, Qt::SortOrder fOrder)
Definition: peertablemodel.h:36
PeerTableModel::index
QModelIndex index(int row, int column, const QModelIndex &parent) const override
Definition: peertablemodel.cpp:226
PeerTableModel::Subversion
@ Subversion
Definition: peertablemodel.h:68
NodeLessThan::column
int column
Definition: peertablemodel.h:41
PeerTablePriv
Definition: peertablemodel.cpp:48
PeerTableModel::Address
@ Address
Definition: peertablemodel.h:62
PeerTableModel::priv
std::unique_ptr< PeerTablePriv > priv
Definition: peertablemodel.h:92
PeerTableModel::flags
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: peertablemodel.cpp:218
PeerTableModel::m_node
interfaces::Node & m_node
Definition: peertablemodel.h:90
CNodeCombinedStats::fNodeStateStatsAvailable
bool fNodeStateStatsAvailable
Definition: peertablemodel.h:29
PeerTableModel::~PeerTableModel
~PeerTableModel()
Definition: peertablemodel.cpp:120
CNodeCombinedStats
Definition: peertablemodel.h:26
NodeLessThan::order
Qt::SortOrder order
Definition: peertablemodel.h:42
PeerTableModel
Qt model providing information about connected peers, similar to the "getpeerinfo" RPC call.
Definition: peertablemodel.h:49
net_processing.h
interfaces::Node
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:53
PeerTableModel::Ping
@ Ping
Definition: peertablemodel.h:65
PeerTableModel::refresh
void refresh()
Definition: peertablemodel.cpp:236
PeerTableModel::StatsRole
@ StatsRole
Definition: peertablemodel.h:72
PeerTableModel::columns
const QStringList columns
Definition: peertablemodel.h:91
PeerTableModel::Sent
@ Sent
Definition: peertablemodel.h:66
PeerTableModel::startAutoRefresh
void startAutoRefresh()
Definition: peertablemodel.cpp:125
NodeLessThan
Definition: peertablemodel.h:33
PeerTableModel::sort
void sort(int column, Qt::SortOrder order) override
Definition: peertablemodel.cpp:252
node
Definition: interfaces.cpp:66
PeerTableModel::getRowByNodeId
int getRowByNodeId(NodeId nodeid)
Definition: peertablemodel.cpp:243
PeerTableModel::Network
@ Network
Definition: peertablemodel.h:64
CNodeStateStats
Definition: net_processing.h:29
PeerTableModel::stopAutoRefresh
void stopAutoRefresh()
Definition: peertablemodel.cpp:130
CNodeStats
Definition: net.h:241
PeerTableModel::timer
QTimer * timer
Definition: peertablemodel.h:93
PeerTableModel::ConnectionType
@ ConnectionType
Definition: peertablemodel.h:63
PeerTableModel::columnCount
int columnCount(const QModelIndex &parent) const override
Definition: peertablemodel.cpp:143
PeerTableModel::ColumnIndex
ColumnIndex
Definition: peertablemodel.h:60
PeerTableModel::rowCount
int rowCount(const QModelIndex &parent) const override
Definition: peertablemodel.cpp:135
CNodeCombinedStats::nodeStateStats
CNodeStateStats nodeStateStats
Definition: peertablemodel.h:28