mirror of
https://github.com/monero-project/monero-gui.git
synced 2025-01-24 19:45:55 +00:00
History: filter by amount
This commit is contained in:
parent
10c2786fca
commit
0ac27e13a6
5 changed files with 48 additions and 52 deletions
3
main.cpp
3
main.cpp
|
@ -84,6 +84,9 @@ int main(int argc, char *argv[])
|
||||||
qmlRegisterUncreatableType<TransactionHistory>("moneroComponents.TransactionHistory", 1, 0, "TransactionHistory",
|
qmlRegisterUncreatableType<TransactionHistory>("moneroComponents.TransactionHistory", 1, 0, "TransactionHistory",
|
||||||
"TransactionHistory can't be instantiated directly");
|
"TransactionHistory can't be instantiated directly");
|
||||||
|
|
||||||
|
qmlRegisterUncreatableType<TransactionInfo>("moneroComponents.TransactionInfo", 1, 0, "TransactionInfo",
|
||||||
|
"TransactionHistory can't be instantiated directly");
|
||||||
|
|
||||||
qRegisterMetaType<PendingTransaction::Priority>();
|
qRegisterMetaType<PendingTransaction::Priority>();
|
||||||
qRegisterMetaType<TransactionInfo::Direction>();
|
qRegisterMetaType<TransactionInfo::Direction>();
|
||||||
qRegisterMetaType<TransactionHistoryModel::TransactionInfoRole>();
|
qRegisterMetaType<TransactionHistoryModel::TransactionInfoRole>();
|
||||||
|
|
|
@ -31,6 +31,7 @@ import QtQuick 2.0
|
||||||
import moneroComponents.Wallet 1.0
|
import moneroComponents.Wallet 1.0
|
||||||
import moneroComponents.WalletManager 1.0
|
import moneroComponents.WalletManager 1.0
|
||||||
import moneroComponents.TransactionHistory 1.0
|
import moneroComponents.TransactionHistory 1.0
|
||||||
|
import moneroComponents.TransactionInfo 1.0
|
||||||
import moneroComponents.TransactionHistoryModel 1.0
|
import moneroComponents.TransactionHistoryModel 1.0
|
||||||
|
|
||||||
import "../components"
|
import "../components"
|
||||||
|
@ -206,6 +207,10 @@ Rectangle {
|
||||||
if (amountToLine.text.length) {
|
if (amountToLine.text.length) {
|
||||||
model.amountToFilter = parseFloat(amountToLine.text)
|
model.amountToFilter = parseFloat(amountToLine.text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var directionFilter = transactionsModel.get(transactionTypeDropdown.currentIndex).value
|
||||||
|
console.log("Direction filter: " + directionFilter)
|
||||||
|
model.directionFilter = directionFilter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -240,9 +245,9 @@ Rectangle {
|
||||||
|
|
||||||
ListModel {
|
ListModel {
|
||||||
id: transactionsModel
|
id: transactionsModel
|
||||||
ListElement { column1: "ALL"; column2: "" }
|
ListElement { column1: "ALL"; column2: ""; value: TransactionInfo.Direction_Both }
|
||||||
ListElement { column1: "SENT"; column2: "" }
|
ListElement { column1: "SENT"; column2: ""; value: TransactionInfo.Direction_Out }
|
||||||
ListElement { column1: "RECEIVED"; column2: "" }
|
ListElement { column1: "RECEIVED"; column2: ""; value: TransactionInfo.Direction_In }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,8 @@ class TransactionInfo : public QObject
|
||||||
public:
|
public:
|
||||||
enum Direction {
|
enum Direction {
|
||||||
Direction_In = Bitmonero::TransactionInfo::Direction_In,
|
Direction_In = Bitmonero::TransactionInfo::Direction_In,
|
||||||
Direction_Out = Bitmonero::TransactionInfo::Direction_Out
|
Direction_Out = Bitmonero::TransactionInfo::Direction_Out,
|
||||||
|
Direction_Both // invalid direction value, used for filtering
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_ENUM(Direction)
|
Q_ENUM(Direction)
|
||||||
|
|
|
@ -112,6 +112,20 @@ void TransactionHistorySortFilterModel::setAmountToFilter(double value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int TransactionHistorySortFilterModel::directionFilter() const
|
||||||
|
{
|
||||||
|
return m_filterValues.value(TransactionHistoryModel::TransactionDirectionRole).value<TransactionInfo::Direction>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TransactionHistorySortFilterModel::setDirectionFilter(int value)
|
||||||
|
{
|
||||||
|
if (value != directionFilter()) {
|
||||||
|
m_filterValues[TransactionHistoryModel::TransactionDirectionRole] = QVariant::fromValue(value);
|
||||||
|
emit directionFilterChanged();
|
||||||
|
invalidateFilter();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void TransactionHistorySortFilterModel::sort(int column, Qt::SortOrder order)
|
void TransactionHistorySortFilterModel::sort(int column, Qt::SortOrder order)
|
||||||
{
|
{
|
||||||
|
@ -150,6 +164,7 @@ bool TransactionHistorySortFilterModel::filterAcceptsRow(int source_row, const Q
|
||||||
{
|
{
|
||||||
QDateTime from = QDateTime(dateFromFilter());
|
QDateTime from = QDateTime(dateFromFilter());
|
||||||
QDateTime to = QDateTime(dateToFilter());
|
QDateTime to = QDateTime(dateToFilter());
|
||||||
|
to = to.addDays(1); // including upperbound
|
||||||
QDateTime timestamp = data.toDateTime();
|
QDateTime timestamp = data.toDateTime();
|
||||||
bool matchFrom = from.isNull() || timestamp.isNull() || timestamp >= from;
|
bool matchFrom = from.isNull() || timestamp.isNull() || timestamp >= from;
|
||||||
bool matchTo = to.isNull() || timestamp.isNull() || timestamp <= to;
|
bool matchTo = to.isNull() || timestamp.isNull() || timestamp <= to;
|
||||||
|
@ -162,17 +177,26 @@ bool TransactionHistorySortFilterModel::filterAcceptsRow(int source_row, const Q
|
||||||
double to = amountToFilter();
|
double to = amountToFilter();
|
||||||
double amount = data.toDouble();
|
double amount = data.toDouble();
|
||||||
|
|
||||||
bool matchFrom = from < 0 || amount >= from;
|
bool matchFrom = from <= 0 || amount >= from;
|
||||||
bool matchTo = to < 0 || amount <= to;
|
bool matchTo = to <= 0 || amount <= to;
|
||||||
result = matchFrom && matchTo;
|
result = matchFrom && matchTo;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case TransactionHistoryModel::TransactionDirectionRole:
|
||||||
|
result = directionFilter() == TransactionInfo::Direction_Both ? true
|
||||||
|
: data.toInt() == directionFilter();
|
||||||
|
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!result) // stop the loop once filter doesn't match
|
|
||||||
|
if (!result) { // stop the loop once filter doesn't match
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,39 +207,3 @@ bool TransactionHistorySortFilterModel::lessThan(const QModelIndex &source_left,
|
||||||
{
|
{
|
||||||
return QSortFilterProxyModel::lessThan(source_left, source_right);
|
return QSortFilterProxyModel::lessThan(source_left, source_right);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant TransactionHistorySortFilterModel::filterValue(int role)
|
|
||||||
{
|
|
||||||
return m_filterValues.value(role);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TransactionHistorySortFilterModel::setFilterValue(int role, const QVariant &filterValue)
|
|
||||||
{
|
|
||||||
m_filterValues[role] = filterValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
QDate TransactionHistorySortFilterModel::dateFromToFilter(TransactionHistorySortFilterModel::ScopeIndex 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::ScopeIndex 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
#ifndef TRANSACTIONHISTORYSORTFILTERMODEL_H
|
#ifndef TRANSACTIONHISTORYSORTFILTERMODEL_H
|
||||||
#define TRANSACTIONHISTORYSORTFILTERMODEL_H
|
#define TRANSACTIONHISTORYSORTFILTERMODEL_H
|
||||||
|
|
||||||
|
#include "TransactionInfo.h"
|
||||||
|
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <QDate>
|
#include <QDate>
|
||||||
|
|
||||||
|
|
||||||
class TransactionHistory;
|
class TransactionHistory;
|
||||||
|
|
||||||
class TransactionHistorySortFilterModel: public QSortFilterProxyModel
|
class TransactionHistorySortFilterModel: public QSortFilterProxyModel
|
||||||
|
@ -17,6 +19,8 @@ class TransactionHistorySortFilterModel: public QSortFilterProxyModel
|
||||||
Q_PROPERTY(QDate dateToFilter READ dateToFilter WRITE setDateToFilter NOTIFY dateToFilterChanged)
|
Q_PROPERTY(QDate dateToFilter READ dateToFilter WRITE setDateToFilter NOTIFY dateToFilterChanged)
|
||||||
Q_PROPERTY(double amountFromFilter READ amountFromFilter WRITE setAmountFromFilter NOTIFY amountFromFilterChanged)
|
Q_PROPERTY(double amountFromFilter READ amountFromFilter WRITE setAmountFromFilter NOTIFY amountFromFilterChanged)
|
||||||
Q_PROPERTY(double amountToFilter READ amountToFilter WRITE setAmountToFilter NOTIFY amountToFilterChanged)
|
Q_PROPERTY(double amountToFilter READ amountToFilter WRITE setAmountToFilter NOTIFY amountToFilterChanged)
|
||||||
|
Q_PROPERTY(int directionFilter READ directionFilter WRITE setDirectionFilter NOTIFY directionFilterChanged)
|
||||||
|
|
||||||
Q_PROPERTY(TransactionHistory * transactionHistory READ transactionHistory)
|
Q_PROPERTY(TransactionHistory * transactionHistory READ transactionHistory)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -41,6 +45,9 @@ public:
|
||||||
double amountToFilter() const;
|
double amountToFilter() const;
|
||||||
void setAmountToFilter(double value);
|
void setAmountToFilter(double value);
|
||||||
|
|
||||||
|
//! filtering by direction
|
||||||
|
int directionFilter() const;
|
||||||
|
void setDirectionFilter(int value);
|
||||||
|
|
||||||
Q_INVOKABLE void sort(int column, Qt::SortOrder order);
|
Q_INVOKABLE void sort(int column, Qt::SortOrder order);
|
||||||
TransactionHistory * transactionHistory() const;
|
TransactionHistory * transactionHistory() const;
|
||||||
|
@ -51,6 +58,7 @@ signals:
|
||||||
void dateToFilterChanged();
|
void dateToFilterChanged();
|
||||||
void amountFromFilterChanged();
|
void amountFromFilterChanged();
|
||||||
void amountToFilterChanged();
|
void amountToFilterChanged();
|
||||||
|
void directionFilterChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// QSortFilterProxyModel overrides
|
// QSortFilterProxyModel overrides
|
||||||
|
@ -64,15 +72,6 @@ private:
|
||||||
To = 1
|
To = 1
|
||||||
};
|
};
|
||||||
|
|
||||||
QVariant filterValue(int role);
|
|
||||||
void setFilterValue(int role, const QVariant &filterValue);
|
|
||||||
QDate dateFromToFilter(ScopeIndex index) const;
|
|
||||||
void setDateFromToFilter(ScopeIndex index, const QDate &value);
|
|
||||||
// double amountFromToFilter(ScopeIndex index) const;
|
|
||||||
// void setAmountFromToFilter(ScopeIndex index, double value);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMap<int, QVariant> m_filterValues;
|
QMap<int, QVariant> m_filterValues;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue