aboutsummaryrefslogtreecommitdiff
path: root/src/qt/bantablemodel.cpp
diff options
context:
space:
mode:
authorPhilip Kaufmann <phil.kaufmann@t-online.de>2015-06-26 14:58:15 +0200
committerJonas Schnelli <jonas.schnelli@include7.ch>2015-09-16 16:50:19 +0200
commit65abe91ce4c3c9b26afa5d1af38bd1bfe81546c4 (patch)
tree24de51e29dabd14f819f6476d4b29655b62d3397 /src/qt/bantablemodel.cpp
parent51654deff2661732c5e2a2aa8ac1f632f5880f45 (diff)
downloadbitcoin-65abe91ce4c3c9b26afa5d1af38bd1bfe81546c4.tar.xz
[Qt] add sorting for bantable
Diffstat (limited to 'src/qt/bantablemodel.cpp')
-rw-r--r--src/qt/bantablemodel.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/qt/bantablemodel.cpp b/src/qt/bantablemodel.cpp
index 6074cd2f07..04840b0526 100644
--- a/src/qt/bantablemodel.cpp
+++ b/src/qt/bantablemodel.cpp
@@ -14,6 +14,24 @@
#include <QDebug>
#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
class BanTablePriv
@@ -43,6 +61,10 @@ public:
banEntry.bantil = banentry.second;
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