Line data Source code
1 : // Copyright (c) 2011-2013 The Bitcoin Core developers
2 : // Distributed under the MIT 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 0 : const QDateTime TransactionFilterProxy::MIN_DATE = QDateTime::fromTime_t(0);
16 : // Last date that can be represented (far in the future)
17 0 : const QDateTime TransactionFilterProxy::MAX_DATE = QDateTime::fromTime_t(0xFFFFFFFF);
18 :
19 0 : 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 0 : showInactive(true)
29 : {
30 0 : }
31 :
32 0 : bool TransactionFilterProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
33 : {
34 0 : QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
35 :
36 0 : int type = index.data(TransactionTableModel::TypeRole).toInt();
37 0 : QDateTime datetime = index.data(TransactionTableModel::DateRole).toDateTime();
38 0 : bool involvesWatchAddress = index.data(TransactionTableModel::WatchonlyRole).toBool();
39 0 : QString address = index.data(TransactionTableModel::AddressRole).toString();
40 0 : QString label = index.data(TransactionTableModel::LabelRole).toString();
41 0 : qint64 amount = llabs(index.data(TransactionTableModel::AmountRole).toLongLong());
42 0 : int status = index.data(TransactionTableModel::StatusRole).toInt();
43 :
44 0 : if(!showInactive && status == TransactionStatus::Conflicted)
45 : return false;
46 0 : if(!(TYPE(type) & typeFilter))
47 : return false;
48 0 : if (involvesWatchAddress && watchOnlyFilter == WatchOnlyFilter_No)
49 : return false;
50 0 : if (!involvesWatchAddress && watchOnlyFilter == WatchOnlyFilter_Yes)
51 : return false;
52 0 : if(datetime < dateFrom || datetime > dateTo)
53 : return false;
54 0 : if (!address.contains(addrPrefix, Qt::CaseInsensitive) && !label.contains(addrPrefix, Qt::CaseInsensitive))
55 : return false;
56 0 : if(amount < minAmount)
57 : return false;
58 :
59 0 : return true;
60 : }
61 :
62 0 : void TransactionFilterProxy::setDateRange(const QDateTime &from, const QDateTime &to)
63 : {
64 0 : this->dateFrom = from;
65 0 : this->dateTo = to;
66 0 : invalidateFilter();
67 0 : }
68 :
69 0 : void TransactionFilterProxy::setAddressPrefix(const QString &addrPrefix)
70 : {
71 0 : this->addrPrefix = addrPrefix;
72 0 : invalidateFilter();
73 0 : }
74 :
75 0 : void TransactionFilterProxy::setTypeFilter(quint32 modes)
76 : {
77 0 : this->typeFilter = modes;
78 0 : invalidateFilter();
79 0 : }
80 :
81 0 : void TransactionFilterProxy::setMinAmount(const CAmount& minimum)
82 : {
83 0 : this->minAmount = minimum;
84 0 : invalidateFilter();
85 0 : }
86 :
87 0 : void TransactionFilterProxy::setWatchOnlyFilter(WatchOnlyFilter filter)
88 : {
89 0 : this->watchOnlyFilter = filter;
90 0 : invalidateFilter();
91 0 : }
92 :
93 0 : void TransactionFilterProxy::setLimit(int limit)
94 : {
95 0 : this->limitRows = limit;
96 0 : }
97 :
98 0 : void TransactionFilterProxy::setShowInactive(bool showInactive)
99 : {
100 0 : this->showInactive = showInactive;
101 0 : invalidateFilter();
102 0 : }
103 :
104 0 : int TransactionFilterProxy::rowCount(const QModelIndex &parent) const
105 : {
106 0 : if(limitRows != -1)
107 : {
108 0 : return std::min(QSortFilterProxyModel::rowCount(parent), limitRows);
109 : }
110 : else
111 : {
112 0 : return QSortFilterProxyModel::rowCount(parent);
113 : }
114 0 : }
|