]> Git Repo - VerusCoin.git/blob - src/qt/transactionfilterproxy.cpp
Merge pull request #4940
[VerusCoin.git] / src / qt / transactionfilterproxy.cpp
1 // Copyright (c) 2011-2013 The Bitcoin developers
2 // Distributed under the MIT/X11 software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5 #include "transactionfilterproxy.h"
6
7 #include "transactiontablemodel.h"
8 #include "transactionrecord.h"
9
10 #include <cstdlib>
11
12 #include <QDateTime>
13
14 // Earliest date that can be represented (far in the past)
15 const QDateTime TransactionFilterProxy::MIN_DATE = QDateTime::fromTime_t(0);
16 // Last date that can be represented (far in the future)
17 const QDateTime TransactionFilterProxy::MAX_DATE = QDateTime::fromTime_t(0xFFFFFFFF);
18
19 TransactionFilterProxy::TransactionFilterProxy(QObject *parent) :
20     QSortFilterProxyModel(parent),
21     dateFrom(MIN_DATE),
22     dateTo(MAX_DATE),
23     addrPrefix(),
24     typeFilter(ALL_TYPES),
25     watchOnlyFilter(WatchOnlyFilter_All),
26     minAmount(0),
27     limitRows(-1),
28     showInactive(true)
29 {
30 }
31
32 bool TransactionFilterProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
33 {
34     QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
35
36     int type = index.data(TransactionTableModel::TypeRole).toInt();
37     QDateTime datetime = index.data(TransactionTableModel::DateRole).toDateTime();
38     bool involvesWatchAddress = index.data(TransactionTableModel::WatchonlyRole).toBool();
39     QString address = index.data(TransactionTableModel::AddressRole).toString();
40     QString label = index.data(TransactionTableModel::LabelRole).toString();
41     qint64 amount = llabs(index.data(TransactionTableModel::AmountRole).toLongLong());
42     int status = index.data(TransactionTableModel::StatusRole).toInt();
43
44     if(!showInactive && status == TransactionStatus::Conflicted)
45         return false;
46     if(!(TYPE(type) & typeFilter))
47         return false;
48     if (involvesWatchAddress && watchOnlyFilter == WatchOnlyFilter_No)
49         return false;
50     if (!involvesWatchAddress && watchOnlyFilter == WatchOnlyFilter_Yes)
51         return false;
52     if(datetime < dateFrom || datetime > dateTo)
53         return false;
54     if (!address.contains(addrPrefix, Qt::CaseInsensitive) && !label.contains(addrPrefix, Qt::CaseInsensitive))
55         return false;
56     if(amount < minAmount)
57         return false;
58
59     return true;
60 }
61
62 void TransactionFilterProxy::setDateRange(const QDateTime &from, const QDateTime &to)
63 {
64     this->dateFrom = from;
65     this->dateTo = to;
66     invalidateFilter();
67 }
68
69 void TransactionFilterProxy::setAddressPrefix(const QString &addrPrefix)
70 {
71     this->addrPrefix = addrPrefix;
72     invalidateFilter();
73 }
74
75 void TransactionFilterProxy::setTypeFilter(quint32 modes)
76 {
77     this->typeFilter = modes;
78     invalidateFilter();
79 }
80
81 void TransactionFilterProxy::setMinAmount(const CAmount& minimum)
82 {
83     this->minAmount = minimum;
84     invalidateFilter();
85 }
86
87 void TransactionFilterProxy::setWatchOnlyFilter(WatchOnlyFilter filter)
88 {
89     this->watchOnlyFilter = filter;
90     invalidateFilter();
91 }
92
93 void TransactionFilterProxy::setLimit(int limit)
94 {
95     this->limitRows = limit;
96 }
97
98 void TransactionFilterProxy::setShowInactive(bool showInactive)
99 {
100     this->showInactive = showInactive;
101     invalidateFilter();
102 }
103
104 int TransactionFilterProxy::rowCount(const QModelIndex &parent) const
105 {
106     if(limitRows != -1)
107     {
108         return std::min(QSortFilterProxyModel::rowCount(parent), limitRows);
109     }
110     else
111     {
112         return QSortFilterProxyModel::rowCount(parent);
113     }
114 }
This page took 0.030553 seconds and 4 git commands to generate.