Bitcoin Core  0.20.99
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 
33 {
34 public:
35  NodeLessThan(int nColumn, Qt::SortOrder fOrder) :
36  column(nColumn), order(fOrder) {}
37  bool operator()(const CNodeCombinedStats &left, const CNodeCombinedStats &right) const;
38 
39 private:
40  int column;
41  Qt::SortOrder order;
42 };
43 
48 class PeerTableModel : public QAbstractTableModel
49 {
50  Q_OBJECT
51 
52 public:
53  explicit PeerTableModel(interfaces::Node& node, QObject* parent);
54  ~PeerTableModel();
55  const CNodeCombinedStats *getNodeStats(int idx);
56  int getRowByNodeId(NodeId nodeid);
57  void startAutoRefresh();
58  void stopAutoRefresh();
59 
60  enum ColumnIndex {
61  NetNodeId = 0,
62  Address = 1,
63  Ping = 2,
64  Sent = 3,
65  Received = 4,
66  Subversion = 5
67  };
68 
71  int rowCount(const QModelIndex &parent) const override;
72  int columnCount(const QModelIndex &parent) const override;
73  QVariant data(const QModelIndex &index, int role) const override;
74  QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
75  QModelIndex index(int row, int column, const QModelIndex &parent) const override;
76  Qt::ItemFlags flags(const QModelIndex &index) const override;
77  void sort(int column, Qt::SortOrder order) override;
80 public Q_SLOTS:
81  void refresh();
82 
83 private:
85  QStringList columns;
86  std::unique_ptr<PeerTablePriv> priv;
87  QTimer *timer;
88 };
89 
90 #endif // BITCOIN_QT_PEERTABLEMODEL_H
CNodeStateStats nodeStateStats
QStringList columns
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
int64_t NodeId
Definition: net.h:90
int flags
Definition: bitcoin-tx.cpp:509
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:43