diff options
author | Cozz Lovan <cozzlovan@yahoo.com> | 2014-01-18 00:01:14 +0100 |
---|---|---|
committer | Cozz Lovan <cozzlovan@yahoo.com> | 2014-01-19 18:21:54 +0100 |
commit | 4d901023b732efb492d89cebd8555c689ab7663e (patch) | |
tree | 68956b053435bc164a33389ee3fb466f1b8e0cd1 /src/qt/recentrequeststablemodel.cpp | |
parent | 8476d5d407645229faf3017b390f041ce0666247 (diff) |
[Qt] Add sorting feature to the requested payments table
Diffstat (limited to 'src/qt/recentrequeststablemodel.cpp')
-rw-r--r-- | src/qt/recentrequeststablemodel.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/qt/recentrequeststablemodel.cpp b/src/qt/recentrequeststablemodel.cpp index 70614f9eae..74b43f1d24 100644 --- a/src/qt/recentrequeststablemodel.cpp +++ b/src/qt/recentrequeststablemodel.cpp @@ -175,3 +175,31 @@ void RecentRequestsTableModel::addNewRequest(RecentRequestEntry &recipient) list.prepend(recipient); endInsertRows(); } + +void RecentRequestsTableModel::sort(int column, Qt::SortOrder order) +{ + qSort(list.begin(), list.end(), RecentRequestEntryLessThan(column, order)); + emit dataChanged(index(0, 0, QModelIndex()), index(list.size() - 1, NUMBER_OF_COLUMNS - 1, QModelIndex())); +} + +bool RecentRequestEntryLessThan::operator()(RecentRequestEntry &left, RecentRequestEntry &right) const +{ + RecentRequestEntry *pLeft = &left; + RecentRequestEntry *pRight = &right; + if (order == Qt::DescendingOrder) + std::swap(pLeft, pRight); + + switch(column) + { + case RecentRequestsTableModel::Date: + return pLeft->date.toTime_t() < pRight->date.toTime_t(); + case RecentRequestsTableModel::Label: + return pLeft->recipient.label < pRight->recipient.label; + case RecentRequestsTableModel::Message: + return pLeft->recipient.message < pRight->recipient.message; + case RecentRequestsTableModel::Amount: + return pLeft->recipient.amount < pRight->recipient.amount; + default: + return pLeft->id < pRight->id; + } +} |