Bitcoin ABC  0.24.7
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  Ping = 2,
63  Sent = 3,
64  Received = 4,
66  };
67 
70  int rowCount(const QModelIndex &parent) const override;
71  int columnCount(const QModelIndex &parent) const override;
72  QVariant data(const QModelIndex &index, int role) const override;
73  QVariant headerData(int section, Qt::Orientation orientation,
74  int role) const override;
75  QModelIndex index(int row, int column,
76  const QModelIndex &parent) const override;
77  Qt::ItemFlags flags(const QModelIndex &index) const override;
78  void sort(int column, Qt::SortOrder order) override;
81 public Q_SLOTS:
82  void refresh();
83 
84 private:
86  QStringList columns;
87  std::unique_ptr<PeerTablePriv> priv;
88  QTimer *timer;
89 };
90 
91 #endif // BITCOIN_QT_PEERTABLEMODEL_H
PeerTableModel::Received
@ Received
Definition: peertablemodel.h:64
interfaces
Definition: dummywallet.cpp:12
PeerTableModel::PeerTableModel
PeerTableModel(interfaces::Node &node, QObject *parent)
Definition: peertablemodel.cpp:101
PeerTableModel::NetNodeId
@ NetNodeId
Definition: peertablemodel.h:60
PeerTableModel::data
QVariant data(const QModelIndex &index, int role) const override
Definition: peertablemodel.cpp:138
PeerTableModel::headerData
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
Definition: peertablemodel.cpp:178
CNodeCombinedStats::nodeStats
CNodeStats nodeStats
Definition: peertablemodel.h:27
NodeLessThan::NodeLessThan
NodeLessThan(int nColumn, Qt::SortOrder fOrder)
Definition: peertablemodel.h:34
PeerTableModel::columns
QStringList columns
Definition: peertablemodel.h:86
NodeLessThan::operator()
bool operator()(const CNodeCombinedStats &left, const CNodeCombinedStats &right) const
Definition: peertablemodel.cpp:18
PeerTableModel::index
QModelIndex index(int row, int column, const QModelIndex &parent) const override
Definition: peertablemodel.cpp:197
PeerTableModel::Subversion
@ Subversion
Definition: peertablemodel.h:65
NodeLessThan::column
int column
Definition: peertablemodel.h:40
PeerTablePriv
Definition: peertablemodel.cpp:46
PeerTableModel::Address
@ Address
Definition: peertablemodel.h:61
PeerTableModel::priv
std::unique_ptr< PeerTablePriv > priv
Definition: peertablemodel.h:87
PeerTableModel::flags
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: peertablemodel.cpp:188
PeerTableModel::m_node
interfaces::Node & m_node
Definition: peertablemodel.h:85
CNodeCombinedStats::fNodeStateStatsAvailable
bool fNodeStateStatsAvailable
Definition: peertablemodel.h:29
PeerTableModel::~PeerTableModel
~PeerTableModel()
Definition: peertablemodel.cpp:116
CNodeCombinedStats
Definition: peertablemodel.h:26
NodeLessThan::order
Qt::SortOrder order
Definition: peertablemodel.h:41
PeerTableModel
Qt model providing information about connected peers, similar to the "getpeerinfo" RPC call.
Definition: peertablemodel.h:48
net_processing.h
PeerTableModel::getNodeStats
const CNodeCombinedStats * getNodeStats(int idx)
Definition: peertablemodel.cpp:208
interfaces::Node
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:55
PeerTableModel::Ping
@ Ping
Definition: peertablemodel.h:62
PeerTableModel::refresh
void refresh()
Definition: peertablemodel.cpp:212
PeerTableModel::Sent
@ Sent
Definition: peertablemodel.h:63
PeerTableModel::startAutoRefresh
void startAutoRefresh()
Definition: peertablemodel.cpp:120
CNodeStats
POD that contains various stats about a node.
Definition: net.h:757
NodeLessThan
Definition: peertablemodel.h:32
PeerTableModel::sort
void sort(int column, Qt::SortOrder order) override
Definition: peertablemodel.cpp:227
NodeId
int64_t NodeId
Definition: nodeid.h:10
PeerTableModel::getRowByNodeId
int getRowByNodeId(NodeId nodeid)
Definition: peertablemodel.cpp:218
CNodeStateStats
Definition: net_processing.h:238
net.h
PeerTableModel::stopAutoRefresh
void stopAutoRefresh()
Definition: peertablemodel.cpp:124
PeerTableModel::timer
QTimer * timer
Definition: peertablemodel.h:88
PeerTableModel::columnCount
int columnCount(const QModelIndex &parent) const override
Definition: peertablemodel.cpp:133
PeerTableModel::ColumnIndex
ColumnIndex
Definition: peertablemodel.h:59
PeerTableModel::rowCount
int rowCount(const QModelIndex &parent) const override
Definition: peertablemodel.cpp:128
CNodeCombinedStats::nodeStateStats
CNodeStateStats nodeStateStats
Definition: peertablemodel.h:28