diff --git a/src/qt/forms/receivecoinsdialog.ui b/src/qt/forms/receivecoinsdialog.ui
index 8242763e7..7bf01224e 100644
--- a/src/qt/forms/receivecoinsdialog.ui
+++ b/src/qt/forms/receivecoinsdialog.ui
@@ -207,7 +207,11 @@
-
-
+
+
+ true
+
+
-
diff --git a/src/qt/receivecoinsdialog.cpp b/src/qt/receivecoinsdialog.cpp
index 075a16dab..38dc88f63 100644
--- a/src/qt/receivecoinsdialog.cpp
+++ b/src/qt/receivecoinsdialog.cpp
@@ -55,6 +55,8 @@ void ReceiveCoinsDialog::setModel(WalletModel *model)
ui->recentRequestsView->horizontalHeader()->setSectionResizeMode(RecentRequestsTableModel::Message, QHeaderView::Stretch);
#endif
ui->recentRequestsView->horizontalHeader()->resizeSection(RecentRequestsTableModel::Amount, 100);
+
+ model->getRecentRequestsTableModel()->sort(RecentRequestsTableModel::Date, Qt::DescendingOrder);
}
}
diff --git a/src/qt/recentrequeststablemodel.cpp b/src/qt/recentrequeststablemodel.cpp
index 70614f9ea..74b43f1d2 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;
+ }
+}
diff --git a/src/qt/recentrequeststablemodel.h b/src/qt/recentrequeststablemodel.h
index f939c7666..6b20402f7 100644
--- a/src/qt/recentrequeststablemodel.h
+++ b/src/qt/recentrequeststablemodel.h
@@ -41,6 +41,18 @@ public:
)
};
+class RecentRequestEntryLessThan
+{
+public:
+ RecentRequestEntryLessThan(int nColumn, Qt::SortOrder fOrder):
+ column(nColumn), order(fOrder) {}
+ bool operator()(RecentRequestEntry &left, RecentRequestEntry &right ) const;
+
+private:
+ int column;
+ Qt::SortOrder order;
+};
+
/** Model for list of recently generated payment requests / bitcoin URIs.
* Part of wallet model.
*/
@@ -56,7 +68,8 @@ public:
Date = 0,
Label = 1,
Message = 2,
- Amount = 3
+ Amount = 3,
+ NUMBER_OF_COLUMNS
};
/** @name Methods overridden from QAbstractTableModel
@@ -76,6 +89,9 @@ public:
void addNewRequest(const std::string &recipient);
void addNewRequest(RecentRequestEntry &recipient);
+public slots:
+ void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
+
private:
WalletModel *walletModel;
QStringList columns;