mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 18:53:23 -03:00
qt: Drop PeerTablePriv class
This commit does not change behavior.
This commit is contained in:
parent
efb7e5aa96
commit
1b66f6e556
2 changed files with 20 additions and 49 deletions
|
@ -14,52 +14,11 @@
|
|||
#include <QList>
|
||||
#include <QTimer>
|
||||
|
||||
// private implementation
|
||||
class PeerTablePriv
|
||||
{
|
||||
public:
|
||||
/** Local cache of peer information */
|
||||
QList<CNodeCombinedStats> cachedNodeStats;
|
||||
|
||||
/** Pull a full list of peers from vNodes into our cache */
|
||||
void refreshPeers(interfaces::Node& node)
|
||||
{
|
||||
cachedNodeStats.clear();
|
||||
|
||||
interfaces::Node::NodesStats nodes_stats;
|
||||
node.getNodesStats(nodes_stats);
|
||||
cachedNodeStats.reserve(nodes_stats.size());
|
||||
for (const auto& node_stats : nodes_stats)
|
||||
{
|
||||
CNodeCombinedStats stats;
|
||||
stats.nodeStats = std::get<0>(node_stats);
|
||||
stats.fNodeStateStatsAvailable = std::get<1>(node_stats);
|
||||
stats.nodeStateStats = std::get<2>(node_stats);
|
||||
cachedNodeStats.append(stats);
|
||||
}
|
||||
}
|
||||
|
||||
int size() const
|
||||
{
|
||||
return cachedNodeStats.size();
|
||||
}
|
||||
|
||||
CNodeCombinedStats *index(int idx)
|
||||
{
|
||||
if (idx >= 0 && idx < cachedNodeStats.size())
|
||||
return &cachedNodeStats[idx];
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
PeerTableModel::PeerTableModel(interfaces::Node& node, QObject* parent) :
|
||||
QAbstractTableModel(parent),
|
||||
m_node(node),
|
||||
timer(nullptr)
|
||||
{
|
||||
priv.reset(new PeerTablePriv());
|
||||
|
||||
// set up timer for auto refresh
|
||||
timer = new QTimer(this);
|
||||
connect(timer, &QTimer::timeout, this, &PeerTableModel::refresh);
|
||||
|
@ -89,7 +48,7 @@ int PeerTableModel::rowCount(const QModelIndex& parent) const
|
|||
if (parent.isValid()) {
|
||||
return 0;
|
||||
}
|
||||
return priv->size();
|
||||
return m_peers_data.size();
|
||||
}
|
||||
|
||||
int PeerTableModel::columnCount(const QModelIndex& parent) const
|
||||
|
@ -175,16 +134,26 @@ Qt::ItemFlags PeerTableModel::flags(const QModelIndex &index) const
|
|||
QModelIndex PeerTableModel::index(int row, int column, const QModelIndex& parent) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
CNodeCombinedStats *data = priv->index(row);
|
||||
|
||||
if (data)
|
||||
return createIndex(row, column, data);
|
||||
if (0 <= row && row < rowCount() && 0 <= column && column < columnCount()) {
|
||||
return createIndex(row, column, const_cast<CNodeCombinedStats*>(&m_peers_data[row]));
|
||||
}
|
||||
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
void PeerTableModel::refresh()
|
||||
{
|
||||
interfaces::Node::NodesStats nodes_stats;
|
||||
m_node.getNodesStats(nodes_stats);
|
||||
decltype(m_peers_data) new_peers_data;
|
||||
new_peers_data.reserve(nodes_stats.size());
|
||||
for (const auto& node_stats : nodes_stats) {
|
||||
const CNodeCombinedStats stats{std::get<0>(node_stats), std::get<2>(node_stats), std::get<1>(node_stats)};
|
||||
new_peers_data.append(stats);
|
||||
}
|
||||
|
||||
Q_EMIT layoutAboutToBeChanged();
|
||||
priv->refreshPeers(m_node);
|
||||
m_peers_data.swap(new_peers_data);
|
||||
Q_EMIT layoutChanged();
|
||||
}
|
||||
|
|
|
@ -8,10 +8,11 @@
|
|||
#include <net_processing.h> // For CNodeStateStats
|
||||
#include <net.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
#include <QList>
|
||||
#include <QModelIndex>
|
||||
#include <QStringList>
|
||||
#include <QVariant>
|
||||
|
||||
class PeerTablePriv;
|
||||
|
||||
|
@ -73,6 +74,8 @@ public Q_SLOTS:
|
|||
void refresh();
|
||||
|
||||
private:
|
||||
//! Internal peer data structure.
|
||||
QList<CNodeCombinedStats> m_peers_data{};
|
||||
interfaces::Node& m_node;
|
||||
const QStringList columns{
|
||||
/*: Title of Peers Table column which contains a
|
||||
|
@ -99,7 +102,6 @@ private:
|
|||
/*: Title of Peers Table column which contains the peer's
|
||||
User Agent string. */
|
||||
tr("User Agent")};
|
||||
std::unique_ptr<PeerTablePriv> priv;
|
||||
QTimer *timer;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue