Bitcoin ABC  0.26.3
P2P Digital Currency
peertablemodel.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2016 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.h>
9 #include <net_processing.h> // For CNodeStateStats
10 
11 #include <QAbstractTableModel>
12 #include <QStringList>
13 
14 #include <memory>
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 
32 class NodeLessThan {
33 public:
34  NodeLessThan(int nColumn, Qt::SortOrder fOrder)
35  : column(nColumn), order(fOrder) {}
36  bool operator()(const CNodeCombinedStats &left,
37  const CNodeCombinedStats &right) const;
38 
39 private:
40  int column;
41  Qt::SortOrder order;
42 };
43 
48 class PeerTableModel : public QAbstractTableModel {
49  Q_OBJECT
50 
51 public:
52  explicit PeerTableModel(interfaces::Node &node, QObject *parent);
54  const CNodeCombinedStats *getNodeStats(int idx);
55  int getRowByNodeId(NodeId nodeid);
56  void startAutoRefresh();
57  void stopAutoRefresh();
58 
59  enum ColumnIndex {
60  NetNodeId = 0,
61  Address = 1,
62  Network = 2,
63  Ping = 3,
64  Sent = 4,
65  Received = 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,
75  int role) const override;
76  QModelIndex index(int row, int column,
77  const QModelIndex &parent) const override;
78  Qt::ItemFlags flags(const QModelIndex &index) const override;
79  void sort(int column, Qt::SortOrder order) override;
82 public Q_SLOTS:
83  void refresh();
84 
85 private:
87  const QStringList columns{tr("Peer Id"), tr("Address"), tr("Network"),
88  tr("Ping"), tr("Sent"), tr("Received"),
89  tr("User Agent")};
90  std::unique_ptr<PeerTablePriv> priv;
91  QTimer *timer;
92 };
93 
94 #endif // BITCOIN_QT_PEERTABLEMODEL_H
bool operator()(const CNodeCombinedStats &left, const CNodeCombinedStats &right) const
NodeLessThan(int nColumn, Qt::SortOrder fOrder)
Qt::SortOrder order
Qt model providing information about connected peers, similar to the "getpeerinfo" RPC call.
QVariant data(const QModelIndex &index, int role) const override
int columnCount(const QModelIndex &parent) const override
Qt::ItemFlags flags(const QModelIndex &index) const override
interfaces::Node & m_node
QModelIndex index(int row, int column, const QModelIndex &parent) const override
void sort(int column, Qt::SortOrder order) override
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
const CNodeCombinedStats * getNodeStats(int idx)
const QStringList columns
PeerTableModel(interfaces::Node &node, QObject *parent)
int getRowByNodeId(NodeId nodeid)
int rowCount(const QModelIndex &parent) const override
std::unique_ptr< PeerTablePriv > priv
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:57
Definition: init.h:28
Network
A network type.
Definition: netaddress.h:45
int64_t NodeId
Definition: nodeid.h:10
CNodeStateStats nodeStateStats
CNodeStats nodeStats
POD that contains various stats about a node.
Definition: net.h:272