Browse Source

[Qt] add sorting for bantable

0.13
Philip Kaufmann 10 years ago committed by Jonas Schnelli
parent
commit
65abe91ce4
  1. 22
      src/qt/bantablemodel.cpp
  2. 14
      src/qt/bantablemodel.h

22
src/qt/bantablemodel.cpp

@ -14,6 +14,24 @@
#include <QDebug> #include <QDebug>
#include <QList> #include <QList>
bool BannedNodeLessThan::operator()(const CCombinedBan& left, const CCombinedBan& right) const
{
const CCombinedBan* pLeft = &left;
const CCombinedBan* pRight = &right;
if (order == Qt::DescendingOrder)
std::swap(pLeft, pRight);
switch(column)
{
case BanTableModel::Address:
return pLeft->subnet.ToString().compare(pRight->subnet.ToString()) < 0;
case BanTableModel::Bantime:
return pLeft->bantil < pRight->bantil;
}
return false;
}
// private implementation // private implementation
class BanTablePriv class BanTablePriv
@ -43,6 +61,10 @@ public:
banEntry.bantil = banentry.second; banEntry.bantil = banentry.second;
cachedBanlist.append(banEntry); cachedBanlist.append(banEntry);
} }
if (sortColumn >= 0)
// sort cachedBanlist (use stable sort to prevent rows jumping around unneceesarily)
qStableSort(cachedBanlist.begin(), cachedBanlist.end(), BannedNodeLessThan(sortColumn, sortOrder));
} }
int size() const int size() const

14
src/qt/bantablemodel.h

@ -18,6 +18,18 @@ struct CCombinedBan {
int64_t bantil; int64_t bantil;
}; };
class BannedNodeLessThan
{
public:
BannedNodeLessThan(int nColumn, Qt::SortOrder fOrder) :
column(nColumn), order(fOrder) {}
bool operator()(const CCombinedBan& left, const CCombinedBan& right) const;
private:
int column;
Qt::SortOrder order;
};
/** /**
Qt model providing information about connected peers, similar to the Qt model providing information about connected peers, similar to the
"getpeerinfo" RPC call. Used by the rpc console UI. "getpeerinfo" RPC call. Used by the rpc console UI.
@ -33,7 +45,7 @@ public:
enum ColumnIndex { enum ColumnIndex {
Address = 0, Address = 0,
Bantime = 1, Bantime = 1
}; };
/** @name Methods overridden from QAbstractTableModel /** @name Methods overridden from QAbstractTableModel

Loading…
Cancel
Save