Skip to content

Commit f0a8406

Browse files
committed
qt: Drop PeerTablePriv class
This commit does not change behavior.
1 parent 6e5b4b3 commit f0a8406

File tree

2 files changed

+23
-48
lines changed

2 files changed

+23
-48
lines changed

src/qt/peertablemodel.cpp

Lines changed: 18 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -14,52 +14,12 @@
1414
#include <QList>
1515
#include <QTimer>
1616

17-
// private implementation
18-
class PeerTablePriv
19-
{
20-
public:
21-
/** Local cache of peer information */
22-
QList<CNodeCombinedStats> cachedNodeStats;
23-
24-
/** Pull a full list of peers from vNodes into our cache */
25-
void refreshPeers(interfaces::Node& node)
26-
{
27-
cachedNodeStats.clear();
28-
29-
interfaces::Node::NodesStats nodes_stats;
30-
node.getNodesStats(nodes_stats);
31-
cachedNodeStats.reserve(nodes_stats.size());
32-
for (const auto& node_stats : nodes_stats)
33-
{
34-
CNodeCombinedStats stats;
35-
stats.nodeStats = std::get<0>(node_stats);
36-
stats.fNodeStateStatsAvailable = std::get<1>(node_stats);
37-
stats.nodeStateStats = std::get<2>(node_stats);
38-
cachedNodeStats.append(stats);
39-
}
40-
}
41-
42-
int size() const
43-
{
44-
return cachedNodeStats.size();
45-
}
46-
47-
CNodeCombinedStats *index(int idx)
48-
{
49-
if (idx >= 0 && idx < cachedNodeStats.size())
50-
return &cachedNodeStats[idx];
51-
52-
return nullptr;
53-
}
54-
};
55-
5617
PeerTableModel::PeerTableModel(interfaces::Node& node, QObject* parent) :
5718
QAbstractTableModel(parent),
5819
m_node(node),
5920
timer(nullptr)
6021
{
6122
columns << tr("NodeId") << tr("Node/Service") << tr("Ping") << tr("Sent") << tr("Received") << tr("User Agent");
62-
priv.reset(new PeerTablePriv());
6323

6424
// set up timer for auto refresh
6525
timer = new QTimer(this);
@@ -88,7 +48,7 @@ void PeerTableModel::stopAutoRefresh()
8848
int PeerTableModel::rowCount(const QModelIndex& parent) const
8949
{
9050
Q_UNUSED(parent);
91-
return priv->size();
51+
return m_peers_data.size();
9252
}
9353

9454
int PeerTableModel::columnCount(const QModelIndex& parent) const
@@ -173,16 +133,29 @@ Qt::ItemFlags PeerTableModel::flags(const QModelIndex &index) const
173133
QModelIndex PeerTableModel::index(int row, int column, const QModelIndex& parent) const
174134
{
175135
Q_UNUSED(parent);
176-
CNodeCombinedStats *data = priv->index(row);
177136

178-
if (data)
179-
return createIndex(row, column, data);
137+
if (0 <= row && row < rowCount() && 0 <= column && column < columnCount()) {
138+
return createIndex(row, column, const_cast<CNodeCombinedStats*>(&m_peers_data[row]));
139+
}
140+
180141
return QModelIndex();
181142
}
182143

183144
void PeerTableModel::refresh()
184145
{
146+
interfaces::Node::NodesStats nodes_stats;
147+
m_node.getNodesStats(nodes_stats);
148+
decltype(m_peers_data) new_peers_data;
149+
new_peers_data.reserve(nodes_stats.size());
150+
for (const auto& node_stats : nodes_stats) {
151+
CNodeCombinedStats stats;
152+
stats.nodeStats = std::get<0>(node_stats);
153+
stats.fNodeStateStatsAvailable = std::get<1>(node_stats);
154+
stats.nodeStateStats = std::get<2>(node_stats);
155+
new_peers_data.append(stats);
156+
}
157+
185158
Q_EMIT layoutAboutToBeChanged();
186-
priv->refreshPeers(m_node);
159+
m_peers_data.swap(new_peers_data);
187160
Q_EMIT layoutChanged();
188161
}

src/qt/peertablemodel.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
#include <net_processing.h> // For CNodeStateStats
99
#include <net.h>
1010

11-
#include <memory>
12-
1311
#include <QAbstractTableModel>
12+
#include <QList>
13+
#include <QModelIndex>
1414
#include <QStringList>
15+
#include <QVariant>
1516

1617
class PeerTablePriv;
1718

@@ -72,9 +73,10 @@ public Q_SLOTS:
7273
void refresh();
7374

7475
private:
76+
//! Internal peer data structure.
77+
QList<CNodeCombinedStats> m_peers_data{};
7578
interfaces::Node& m_node;
7679
QStringList columns;
77-
std::unique_ptr<PeerTablePriv> priv;
7880
QTimer *timer;
7981
};
8082

0 commit comments

Comments
 (0)