mirror of
https://github.com/monero-project/monero-gui.git
synced 2025-01-24 19:45:55 +00:00
History: filtering by paymentId and date
This commit is contained in:
parent
e3cea8582f
commit
9b09e83ba0
4 changed files with 125 additions and 22 deletions
|
@ -42,7 +42,11 @@ Rectangle {
|
||||||
color: "#F0EEEE"
|
color: "#F0EEEE"
|
||||||
|
|
||||||
onModelChanged: {
|
onModelChanged: {
|
||||||
console.log("model.rowCount: " + model.rowCount())
|
if (typeof model !== 'undefined') {
|
||||||
|
// setup date filter scope according to real transactions
|
||||||
|
fromDatePicker.currentDate = model.transactionHistory.firstDateTime
|
||||||
|
toDatePicker.currentDate = model.transactionHistory.lastDateTime
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -107,6 +111,8 @@ Rectangle {
|
||||||
anchors.leftMargin: 17
|
anchors.leftMargin: 17
|
||||||
anchors.rightMargin: 17
|
anchors.rightMargin: 17
|
||||||
anchors.topMargin: 5
|
anchors.topMargin: 5
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter by description input (not implemented yet)
|
// Filter by description input (not implemented yet)
|
||||||
|
@ -154,6 +160,9 @@ Rectangle {
|
||||||
anchors.leftMargin: 17
|
anchors.leftMargin: 17
|
||||||
anchors.topMargin: 5
|
anchors.topMargin: 5
|
||||||
z: 2
|
z: 2
|
||||||
|
onCurrentDateChanged: {
|
||||||
|
console.log("CurrentDate: " + currentDate)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DateTo picker
|
// DateTo picker
|
||||||
|
@ -188,6 +197,12 @@ Rectangle {
|
||||||
shadowPressedColor: "#2D002F"
|
shadowPressedColor: "#2D002F"
|
||||||
releasedColor: "#6B0072"
|
releasedColor: "#6B0072"
|
||||||
pressedColor: "#4D0051"
|
pressedColor: "#4D0051"
|
||||||
|
onClicked: {
|
||||||
|
// Apply filter here;
|
||||||
|
model.paymentIdFilter = paymentIdLine.text
|
||||||
|
model.dateFromFilter = fromDatePicker.currentDate
|
||||||
|
model.dateToFilter = toDatePicker.currentDate
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckBox {
|
CheckBox {
|
||||||
|
@ -373,21 +388,6 @@ Rectangle {
|
||||||
model.sort(0, desc ? Qt.DescendingOrder : Qt.AscendingOrder)
|
model.sort(0, desc ? Qt.DescendingOrder : Qt.AscendingOrder)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
ListModel {
|
|
||||||
id: testModel
|
|
||||||
ListElement { paymentId: "faef56b9acf67a7dba75ec01f403497049d7cff111628edfe7b57278554dc798"; address: "faef56b9acf67a7dba75ec01f403497049d7cff111628edfe7b57278554dc798"; date: "Jan 12, 2014"; time: "12:23 <font size='2'>AM</font>"; amount: "0.<font size='2'>000709159241</font>"; balance: "19301.<font size='2'>870709159241</font>"; description: "Client from Australia"; out: false }
|
|
||||||
ListElement { paymentId: "faef56b9acf67a7dba75ec01f403497049d7cff111628edfe7b57278554dc798"; address: "faef56b9acf67a7dba75ec01f403497049d7cff111628edfe7b57278554dc798"; date: "Jan 12, 2014"; time: "12:23 <font size='2'>AM</font>"; amount: "0.<font size='2'>000709159241</font>"; balance: "19301.<font size='2'>870709159241</font>"; description: ""; out: true }
|
|
||||||
ListElement { paymentId: "faef56b9acf67a7dba75ec01f403497049d7cff111628edfe7b57278554dc798"; address: "faef56b9acf67a7dba75ec01f403497049d7cff111628edfe7b57278554dc798"; date: "Jan 12, 2014"; time: "12:23 <font size='2'>AM</font>"; amount: "0.<font size='2'>000709159241</font>"; balance: "19301.<font size='2'>870709159241</font>"; description: ""; out: true }
|
|
||||||
ListElement { paymentId: ""; address: "faef56b9acf67a7dba75ec01f403497049d7cff111628edfe7b57278554dc798"; date: "Jan 12, 2014"; time: "12:23 <font size='2'>AM</font>"; amount: "0.<font size='2'>000709159241</font>"; balance: "19301.<font size='2'>870709159241</font>"; description: ""; out: false }
|
|
||||||
ListElement { paymentId: ""; address: "faef56b9acf67a7dba75ec01f403497049d7cff111628edfe7b57278554dc798"; date: "Jan 12, 2014"; time: "12:23 <font size='2'>AM</font>"; amount: "0.<font size='2'>000709159241</font>"; balance: "19301.<font size='2'>870709159241</font>"; description: "Client from Australia"; out: false }
|
|
||||||
ListElement { paymentId: "faef56b9acf67a7dba75ec01f403497049d7cff111628edfe7b57278554dc798"; address: "faef56b9acf67a7dba75ec01f403497049d7cff111628edfe7b57278554dc798"; date: "Jan 12, 2014"; time: "12:23 <font size='2'>AM</font>"; amount: "0.<font size='2'>000709159241</font>"; balance: "19301.<font size='2'>870709159241</font>"; description: ""; out: false }
|
|
||||||
ListElement { paymentId: ""; address: "faef56b9acf67a7dba75ec01f403497049d7cff111628edfe7b57278554dc798"; date: "Jan 12, 2014"; time: "12:23 <font size='2'>AM</font>"; amount: "0.<font size='2'>000709159241</font>"; balance: "19301.<font size='2'>870709159241</font>"; description: ""; out: false }
|
|
||||||
ListElement { paymentId: "faef56b9acf67a7dba75ec01f403497049d7cff111628edfe7b57278554dc798"; address: "faef56b9acf67a7dba75ec01f403497049d7cff111628edfe7b57278554dc798"; date: "Jan 12, 2014"; time: "12:23 <font size='2'>AM</font>"; amount: "0.<font size='2'>000709159241</font>"; balance: "19301.<font size='2'>870709159241</font>"; description: ""; out: false }
|
|
||||||
ListElement { paymentId: "faef56b9acf67a7dba75ec01f403497049d7cff111628edfe7b57278554dc798"; address: "faef56b9acf67a7dba75ec01f403497049d7cff111628edfe7b57278554dc798"; date: "Jan 12, 2014"; time: "12:23 <font size='2'>AM</font>"; amount: "0.<font size='2'>000709159241</font>"; balance: "19301.<font size='2'>870709159241</font>"; description: "Client from Australia"; out: false }
|
|
||||||
ListElement { paymentId: "faef56b9acf67a7dba75ec01f403497049d7cff111628edfe7b57278554dc798"; address: "faef56b9acf67a7dba75ec01f403497049d7cff111628edfe7b57278554dc798"; date: "Jan 12, 2014"; time: "12:23 <font size='2'>AM</font>"; amount: "0.<font size='2'>000709159241</font>"; balance: "19301.<font size='2'>870709159241</font>"; description: ""; out: false }
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
Scroll {
|
Scroll {
|
||||||
id: flickableScroll
|
id: flickableScroll
|
||||||
|
|
|
@ -30,7 +30,7 @@ class Wallet : public QObject
|
||||||
Q_PROPERTY(quint64 unlockedBalance READ unlockedBalance)
|
Q_PROPERTY(quint64 unlockedBalance READ unlockedBalance)
|
||||||
Q_PROPERTY(TransactionHistory * history READ history)
|
Q_PROPERTY(TransactionHistory * history READ history)
|
||||||
Q_PROPERTY(QString paymentId READ paymentId WRITE setPaymentId)
|
Q_PROPERTY(QString paymentId READ paymentId WRITE setPaymentId)
|
||||||
Q_PROPERTY(TransactionHistorySortFilterModel * historyModel READ historyModel)
|
Q_PROPERTY(TransactionHistorySortFilterModel * historyModel READ historyModel NOTIFY historyModelChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -151,6 +151,7 @@ signals:
|
||||||
void moneySpent(const QString &txId, quint64 amount);
|
void moneySpent(const QString &txId, quint64 amount);
|
||||||
void moneyReceived(const QString &txId, quint64 amount);
|
void moneyReceived(const QString &txId, quint64 amount);
|
||||||
void newBlock(quint64 height);
|
void newBlock(quint64 height);
|
||||||
|
void historyModelChanged() const;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -6,17 +6,49 @@
|
||||||
TransactionHistorySortFilterModel::TransactionHistorySortFilterModel(QObject *parent)
|
TransactionHistorySortFilterModel::TransactionHistorySortFilterModel(QObject *parent)
|
||||||
: QSortFilterProxyModel(parent)
|
: QSortFilterProxyModel(parent)
|
||||||
{
|
{
|
||||||
|
setDynamicSortFilter(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString TransactionHistorySortFilterModel::paymentIdFilter() const
|
QString TransactionHistorySortFilterModel::paymentIdFilter() const
|
||||||
{
|
{
|
||||||
|
return m_filterValues.value(TransactionHistoryModel::TransactionPaymentIdRole).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransactionHistorySortFilterModel::setPaymentIdFilter(const QString &arg)
|
void TransactionHistorySortFilterModel::setPaymentIdFilter(const QString &arg)
|
||||||
{
|
{
|
||||||
|
if (paymentIdFilter() != arg) {
|
||||||
|
m_filterValues[TransactionHistoryModel::TransactionPaymentIdRole] = arg;
|
||||||
|
emit paymentIdFilterChanged();
|
||||||
|
invalidateFilter();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QDate TransactionHistorySortFilterModel::dateFromFilter() const
|
||||||
|
{
|
||||||
|
return dateFromToFilter(From);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TransactionHistorySortFilterModel::setDateFromFilter(const QDate &date)
|
||||||
|
{
|
||||||
|
if (date != dateFromFilter()) {
|
||||||
|
setDateFromToFilter(From, date);
|
||||||
|
emit dateFromFilterChanged();
|
||||||
|
invalidateFilter();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QDate TransactionHistorySortFilterModel::dateToFilter() const
|
||||||
|
{
|
||||||
|
return dateFromToFilter(To);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TransactionHistorySortFilterModel::setDateToFilter(const QDate &date)
|
||||||
|
{
|
||||||
|
if (date != dateToFilter()) {
|
||||||
|
setDateFromToFilter(To, date);
|
||||||
|
emit dateFromFilterChanged();
|
||||||
|
invalidateFilter();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransactionHistorySortFilterModel::sort(int column, Qt::SortOrder order)
|
void TransactionHistorySortFilterModel::sort(int column, Qt::SortOrder order)
|
||||||
|
@ -24,6 +56,12 @@ void TransactionHistorySortFilterModel::sort(int column, Qt::SortOrder order)
|
||||||
QSortFilterProxyModel::sort(column, order);
|
QSortFilterProxyModel::sort(column, order);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TransactionHistory *TransactionHistorySortFilterModel::transactionHistory() const
|
||||||
|
{
|
||||||
|
const TransactionHistoryModel * model = static_cast<const TransactionHistoryModel*> (sourceModel());
|
||||||
|
return model->transactionHistory();
|
||||||
|
}
|
||||||
|
|
||||||
bool TransactionHistorySortFilterModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
|
bool TransactionHistorySortFilterModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -38,11 +76,27 @@ bool TransactionHistorySortFilterModel::filterAcceptsRow(int source_row, const Q
|
||||||
|
|
||||||
bool result = true;
|
bool result = true;
|
||||||
|
|
||||||
|
// iterating through filters
|
||||||
for (int role : m_filterValues.keys()) {
|
for (int role : m_filterValues.keys()) {
|
||||||
if (m_filterValues.contains(role)) {
|
if (m_filterValues.contains(role)) {
|
||||||
QVariant data = sourceModel()->data(index, role);
|
QVariant data = sourceModel()->data(index, role);
|
||||||
result = data.toString().contains(m_filterValues.value(role).toString());
|
switch (role) {
|
||||||
if (result)
|
case TransactionHistoryModel::TransactionPaymentIdRole:
|
||||||
|
result = data.toString().contains(paymentIdFilter());
|
||||||
|
break;
|
||||||
|
case TransactionHistoryModel::TransactionTimeStampRole:
|
||||||
|
{
|
||||||
|
QDateTime from = QDateTime(dateFromFilter());
|
||||||
|
QDateTime to = QDateTime(dateToFilter());
|
||||||
|
QDateTime timestamp = data.toDateTime();
|
||||||
|
bool matchFrom = from.isNull() || timestamp.isNull() || timestamp >= from;
|
||||||
|
bool matchTo = to.isNull() || timestamp.isNull() || timestamp <= to;
|
||||||
|
result = matchFrom && matchTo;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!result) // stop the loop once filter doesn't match
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,3 +118,26 @@ void TransactionHistorySortFilterModel::setFilterValue(int role, const QVariant
|
||||||
{
|
{
|
||||||
m_filterValues[role] = filterValue;
|
m_filterValues[role] = filterValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QDate TransactionHistorySortFilterModel::dateFromToFilter(TransactionHistorySortFilterModel::DateScopeIndex index) const
|
||||||
|
{
|
||||||
|
int role = TransactionHistoryModel::TransactionTimeStampRole;
|
||||||
|
if (!m_filterValues.contains(role)) {
|
||||||
|
return QDate();
|
||||||
|
}
|
||||||
|
return m_filterValues.value(role).toList().at(index).toDate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TransactionHistorySortFilterModel::setDateFromToFilter(TransactionHistorySortFilterModel::DateScopeIndex index, const QDate &value)
|
||||||
|
{
|
||||||
|
QVariantList scopeFilter;
|
||||||
|
int role = TransactionHistoryModel::TransactionTimeStampRole;
|
||||||
|
if (m_filterValues.contains(role)) {
|
||||||
|
scopeFilter = m_filterValues.value(role).toList();
|
||||||
|
}
|
||||||
|
while (scopeFilter.size() < 2) {
|
||||||
|
scopeFilter.append(QDate());
|
||||||
|
}
|
||||||
|
scopeFilter[index] = QVariant::fromValue(value);
|
||||||
|
m_filterValues[role] = scopeFilter;
|
||||||
|
}
|
||||||
|
|
|
@ -5,18 +5,36 @@
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
#include <QDate>
|
||||||
|
|
||||||
|
class TransactionHistory;
|
||||||
|
|
||||||
class TransactionHistorySortFilterModel: public QSortFilterProxyModel
|
class TransactionHistorySortFilterModel: public QSortFilterProxyModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QString paymentIdFilter READ paymentIdFilter WRITE setPaymentIdFilter NOTIFY paymentIdFilterChanged)
|
||||||
|
Q_PROPERTY(QDate dateFromFilter READ dateFromFilter WRITE setDateFromFilter NOTIFY dateFromFilterChanged)
|
||||||
|
Q_PROPERTY(QDate dateToFilter READ dateToFilter WRITE setDateToFilter NOTIFY dateToFilterChanged)
|
||||||
|
Q_PROPERTY(TransactionHistory * transactionHistory READ transactionHistory)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TransactionHistorySortFilterModel(QObject * parent = nullptr);
|
TransactionHistorySortFilterModel(QObject * parent = nullptr);
|
||||||
QString paymentIdFilter() const;
|
QString paymentIdFilter() const;
|
||||||
void setPaymentIdFilter(const QString &arg);
|
void setPaymentIdFilter(const QString &arg);
|
||||||
|
QDate dateFromFilter() const;
|
||||||
|
void setDateFromFilter(const QDate &date);
|
||||||
|
QDate dateToFilter() const;
|
||||||
|
void setDateToFilter(const QDate &date);
|
||||||
|
|
||||||
|
|
||||||
Q_INVOKABLE void sort(int column, Qt::SortOrder order);
|
Q_INVOKABLE void sort(int column, Qt::SortOrder order);
|
||||||
|
TransactionHistory * transactionHistory() const;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void paymentIdFilterChanged();
|
||||||
|
void dateFromFilterChanged();
|
||||||
|
void dateToFilterChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// QSortFilterProxyModel overrides
|
// QSortFilterProxyModel overrides
|
||||||
virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
|
virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
|
||||||
|
@ -24,8 +42,15 @@ protected:
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
enum DateScopeIndex {
|
||||||
|
From = 0,
|
||||||
|
To = 1
|
||||||
|
};
|
||||||
|
|
||||||
QVariant filterValue(int role);
|
QVariant filterValue(int role);
|
||||||
void setFilterValue(int role, const QVariant &filterValue);
|
void setFilterValue(int role, const QVariant &filterValue);
|
||||||
|
QDate dateFromToFilter(DateScopeIndex index) const;
|
||||||
|
void setDateFromToFilter(DateScopeIndex index, const QDate &value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMap<int, QVariant> m_filterValues;
|
QMap<int, QVariant> m_filterValues;
|
||||||
|
|
Loading…
Reference in a new issue