Browse Source

[Qt] Add sorting feature to the requested payments table

pull/1/head
Cozz Lovan 9 years ago
parent
commit
4d901023b7
  1. 6
      src/qt/forms/receivecoinsdialog.ui
  2. 2
      src/qt/receivecoinsdialog.cpp
  3. 28
      src/qt/recentrequeststablemodel.cpp
  4. 18
      src/qt/recentrequeststablemodel.h

6
src/qt/forms/receivecoinsdialog.ui

@ -207,7 +207,11 @@ @@ -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">

2
src/qt/receivecoinsdialog.cpp

@ -55,6 +55,8 @@ void ReceiveCoinsDialog::setModel(WalletModel *model) @@ -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);
}
}

28
src/qt/recentrequeststablemodel.cpp

@ -175,3 +175,31 @@ void RecentRequestsTableModel::addNewRequest(RecentRequestEntry &recipient) @@ -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;
}
}

18
src/qt/recentrequeststablemodel.h

@ -41,6 +41,18 @@ public: @@ -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: @@ -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: @@ -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;

Loading…
Cancel
Save