From 1b66f6e556631a1a2d89aefba70a79894bd14fcd Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Mon, 22 Feb 2021 09:55:10 +0200 Subject: qt: Drop PeerTablePriv class This commit does not change behavior. --- src/qt/peertablemodel.cpp | 61 ++++++++++++----------------------------------- src/qt/peertablemodel.h | 8 ++++--- 2 files changed, 20 insertions(+), 49 deletions(-) diff --git a/src/qt/peertablemodel.cpp b/src/qt/peertablemodel.cpp index de567aacb7..fe03365d76 100644 --- a/src/qt/peertablemodel.cpp +++ b/src/qt/peertablemodel.cpp @@ -14,52 +14,11 @@ #include #include -// private implementation -class PeerTablePriv -{ -public: - /** Local cache of peer information */ - QList 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(&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(); } diff --git a/src/qt/peertablemodel.h b/src/qt/peertablemodel.h index dc2802d4a9..0d841ebf28 100644 --- a/src/qt/peertablemodel.h +++ b/src/qt/peertablemodel.h @@ -8,10 +8,11 @@ #include // For CNodeStateStats #include -#include - #include +#include +#include #include +#include class PeerTablePriv; @@ -73,6 +74,8 @@ public Q_SLOTS: void refresh(); private: + //! Internal peer data structure. + QList 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 priv; QTimer *timer; }; -- cgit v1.2.3