1111
1212#include < utility>
1313
14- #include < QDebug>
1514#include < QList>
1615#include < QTimer>
1716
18- bool NodeLessThan::operator ()(const CNodeCombinedStats &left, const CNodeCombinedStats &right) const
19- {
20- const CNodeStats *pLeft = &(left.nodeStats );
21- const CNodeStats *pRight = &(right.nodeStats );
22-
23- if (order == Qt::DescendingOrder)
24- std::swap (pLeft, pRight);
25-
26- switch (static_cast <PeerTableModel::ColumnIndex>(column)) {
27- case PeerTableModel::NetNodeId:
28- return pLeft->nodeid < pRight->nodeid ;
29- case PeerTableModel::Address:
30- return pLeft->addrName .compare (pRight->addrName ) < 0 ;
31- case PeerTableModel::ConnectionType:
32- return pLeft->m_conn_type < pRight->m_conn_type ;
33- case PeerTableModel::Network:
34- return pLeft->m_network < pRight->m_network ;
35- case PeerTableModel::Ping:
36- return pLeft->m_min_ping_time < pRight->m_min_ping_time ;
37- case PeerTableModel::Sent:
38- return pLeft->nSendBytes < pRight->nSendBytes ;
39- case PeerTableModel::Received:
40- return pLeft->nRecvBytes < pRight->nRecvBytes ;
41- case PeerTableModel::Subversion:
42- return pLeft->cleanSubVer .compare (pRight->cleanSubVer ) < 0 ;
43- } // no default case, so the compiler can warn about missing cases
44- assert (false );
45- }
46-
4717// private implementation
4818class PeerTablePriv
4919{
5020public:
5121 /* * Local cache of peer information */
5222 QList<CNodeCombinedStats> cachedNodeStats;
53- /* * Column to sort nodes by (default to unsorted) */
54- int sortColumn{-1 };
55- /* * Order (ascending or descending) to sort nodes by */
56- Qt::SortOrder sortOrder;
57- /* * Index of rows by node ID */
58- std::map<NodeId, int > mapNodeRows;
5923
6024 /* * Pull a full list of peers from vNodes into our cache */
6125 void refreshPeers (interfaces::Node& node)
6226 {
63- {
6427 cachedNodeStats.clear ();
6528
6629 interfaces::Node::NodesStats nodes_stats;
@@ -74,17 +37,6 @@ class PeerTablePriv
7437 stats.nodeStateStats = std::get<2 >(node_stats);
7538 cachedNodeStats.append (stats);
7639 }
77- }
78-
79- if (sortColumn >= 0 )
80- // sort cacheNodeStats (use stable sort to prevent rows jumping around unnecessarily)
81- std::stable_sort (cachedNodeStats.begin (), cachedNodeStats.end (), NodeLessThan (sortColumn, sortOrder));
82-
83- // build index map
84- mapNodeRows.clear ();
85- int row = 0 ;
86- for (const CNodeCombinedStats& stats : cachedNodeStats)
87- mapNodeRows.insert (std::pair<NodeId, int >(stats.nodeStats .nodeid , row++));
8840 }
8941
9042 int size () const
@@ -194,10 +146,7 @@ QVariant PeerTableModel::data(const QModelIndex &index, int role) const
194146 } // no default case, so the compiler can warn about missing cases
195147 assert (false );
196148 } else if (role == StatsRole) {
197- switch (index.column ()) {
198- case NetNodeId: return QVariant::fromValue (rec);
199- default : return QVariant ();
200- }
149+ return QVariant::fromValue (rec);
201150 }
202151
203152 return QVariant ();
@@ -239,19 +188,3 @@ void PeerTableModel::refresh()
239188 priv->refreshPeers (m_node);
240189 Q_EMIT layoutChanged ();
241190}
242-
243- int PeerTableModel::getRowByNodeId (NodeId nodeid)
244- {
245- std::map<NodeId, int >::iterator it = priv->mapNodeRows .find (nodeid);
246- if (it == priv->mapNodeRows .end ())
247- return -1 ;
248-
249- return it->second ;
250- }
251-
252- void PeerTableModel::sort (int column, Qt::SortOrder order)
253- {
254- priv->sortColumn = column;
255- priv->sortOrder = order;
256- refresh ();
257- }
0 commit comments