Skip to content

Commit

Permalink
refactor: Drop unused PeerTableModel::sort()
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed Dec 22, 2020
1 parent 4a92de3 commit 6a01276
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 56 deletions.
43 changes: 0 additions & 43 deletions src/qt/peertablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,15 @@

#include <utility>

#include <QDebug>
#include <QList>
#include <QTimer>

bool NodeLessThan::operator()(const CNodeCombinedStats &left, const CNodeCombinedStats &right) const
{
const CNodeStats *pLeft = &(left.nodeStats);
const CNodeStats *pRight = &(right.nodeStats);

if (order == Qt::DescendingOrder)
std::swap(pLeft, pRight);

switch(column)
{
case PeerTableModel::NetNodeId:
return pLeft->nodeid < pRight->nodeid;
case PeerTableModel::Address:
return pLeft->addrName.compare(pRight->addrName) < 0;
case PeerTableModel::Subversion:
return pLeft->cleanSubVer.compare(pRight->cleanSubVer) < 0;
case PeerTableModel::Ping:
return pLeft->m_min_ping_usec < pRight->m_min_ping_usec;
case PeerTableModel::Sent:
return pLeft->nSendBytes < pRight->nSendBytes;
case PeerTableModel::Received:
return pLeft->nRecvBytes < pRight->nRecvBytes;
}

return false;
}

// private implementation
class PeerTablePriv
{
public:
/** Local cache of peer information */
QList<CNodeCombinedStats> cachedNodeStats;
/** Column to sort nodes by (default to unsorted) */
int sortColumn{-1};
/** Order (ascending or descending) to sort nodes by */
Qt::SortOrder sortOrder;
/** Index of rows by node ID */
std::map<NodeId, int> mapNodeRows;

Expand All @@ -74,10 +42,6 @@ class PeerTablePriv
}
}

if (sortColumn >= 0)
// sort cacheNodeStats (use stable sort to prevent rows jumping around unnecessarily)
std::stable_sort(cachedNodeStats.begin(), cachedNodeStats.end(), NodeLessThan(sortColumn, sortOrder));

// build index map
mapNodeRows.clear();
int row = 0;
Expand Down Expand Up @@ -246,10 +210,3 @@ int PeerTableModel::getRowByNodeId(NodeId nodeid)

return it->second;
}

void PeerTableModel::sort(int column, Qt::SortOrder order)
{
priv->sortColumn = column;
priv->sortOrder = order;
refresh();
}
13 changes: 0 additions & 13 deletions src/qt/peertablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,6 @@ struct CNodeCombinedStats {
bool fNodeStateStatsAvailable;
};

class NodeLessThan
{
public:
NodeLessThan(int nColumn, Qt::SortOrder fOrder) :
column(nColumn), order(fOrder) {}
bool operator()(const CNodeCombinedStats &left, const CNodeCombinedStats &right) const;

private:
int column;
Qt::SortOrder order;
};

/**
Qt model providing information about connected peers, similar to the
"getpeerinfo" RPC call. Used by the rpc console UI.
Expand Down Expand Up @@ -74,7 +62,6 @@ class PeerTableModel : public QAbstractTableModel
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
QModelIndex index(int row, int column, const QModelIndex &parent) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
void sort(int column, Qt::SortOrder order) override;
/*@}*/

public Q_SLOTS:
Expand Down

0 comments on commit 6a01276

Please sign in to comment.