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);
55  ~PeerTableModel();
56  int getRowByNodeId(NodeId nodeid);
57  void startAutoRefresh();
58  void stopAutoRefresh();
59 
60  enum ColumnIndex {
61  NetNodeId = 0,
62  Address = 1,
63  Network = 2,
64  Ping = 3,
65  Sent = 4,
66  Received = 5,
67  Subversion = 6
68  };
69 
70  enum {
71  StatsRole = Qt::UserRole,
72  };
73 
76  int rowCount(const QModelIndex &parent) const override;
77  int columnCount(const QModelIndex &parent) const override;
78  QVariant data(const QModelIndex &index, int role) const override;
79  QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
80  QModelIndex index(int row, int column, const QModelIndex &parent) const override;
81  Qt::ItemFlags flags(const QModelIndex &index) const override;
82  void sort(int column, Qt::SortOrder order) override;
85 public Q_SLOTS:
86  void refresh();
87 
88 private:
90  const QStringList columns{tr("Peer Id"), tr("Address"), tr("Network"), tr("Ping"), tr("Sent"), tr("Received"), tr("User Agent")};
91  std::unique_ptr<PeerTablePriv> priv;
92  QTimer *timer;
93 };
94 
95 #endif // BITCOIN_QT_PEERTABLEMODEL_H
CNodeStateStats nodeStateStats
NodeLessThan(int nColumn, Qt::SortOrder fOrder)
Qt::SortOrder order
CNodeStats nodeStats
interfaces::Node & m_node
Qt model providing information about connected peers, similar to the "getpeerinfo" RPC call...
std::unique_ptr< PeerTablePriv > priv
Network
A network type.
Definition: netaddress.h:43
int64_t NodeId
Definition: net.h:83
int flags
Definition: bitcoin-tx.cpp:512
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:52