aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCozz Lovan <cozzlovan@yahoo.com>2014-01-18 00:01:14 +0100
committerCozz Lovan <cozzlovan@yahoo.com>2014-01-19 18:21:54 +0100
commit4d901023b732efb492d89cebd8555c689ab7663e (patch)
tree68956b053435bc164a33389ee3fb466f1b8e0cd1 /src
parent8476d5d407645229faf3017b390f041ce0666247 (diff)
[Qt] Add sorting feature to the requested payments table
Diffstat (limited to 'src')
-rw-r--r--src/qt/forms/receivecoinsdialog.ui6
-rw-r--r--src/qt/receivecoinsdialog.cpp2
-rw-r--r--src/qt/recentrequeststablemodel.cpp28
-rw-r--r--src/qt/recentrequeststablemodel.h18
4 files changed, 52 insertions, 2 deletions
diff --git a/src/qt/forms/receivecoinsdialog.ui b/src/qt/forms/receivecoinsdialog.ui
index 8242763e77..7bf01224ee 100644
--- a/src/qt/forms/receivecoinsdialog.ui
+++ b/src/qt/forms/receivecoinsdialog.ui
@@ -207,7 +207,11 @@
</widget>
</item>
<item>
- <widget class="QTableView" name="recentRequestsView"/>
+ <widget class="QTableView" name="recentRequestsView">
+ <property name="sortingEnabled">
+ <bool>true</bool>
+ </property>
+ </widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
diff --git a/src/qt/receivecoinsdialog.cpp b/src/qt/receivecoinsdialog.cpp
index 075a16dabf..38dc88f63b 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 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;
+ }
+}
diff --git a/src/qt/recentrequeststablemodel.h b/src/qt/recentrequeststablemodel.h
index f939c76666..6b20402f78 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;