Remove includes in .cpp files for things the corresponding .h file already included
[bitcoinplatinum.git] / src / qt / transactionfilterproxy.cpp
blobbc4504a93b94b4f6f8572add349acbcc93d25532
1 // Copyright (c) 2011-2016 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.
5 #include <qt/transactionfilterproxy.h>
7 #include <qt/transactiontablemodel.h>
8 #include <qt/transactionrecord.h>
10 #include <cstdlib>
12 // Earliest date that can be represented (far in the past)
13 const QDateTime TransactionFilterProxy::MIN_DATE = QDateTime::fromTime_t(0);
14 // Last date that can be represented (far in the future)
15 const QDateTime TransactionFilterProxy::MAX_DATE = QDateTime::fromTime_t(0xFFFFFFFF);
17 TransactionFilterProxy::TransactionFilterProxy(QObject *parent) :
18 QSortFilterProxyModel(parent),
19 dateFrom(MIN_DATE),
20 dateTo(MAX_DATE),
21 addrPrefix(),
22 typeFilter(ALL_TYPES),
23 watchOnlyFilter(WatchOnlyFilter_All),
24 minAmount(0),
25 limitRows(-1),
26 showInactive(true)
30 bool TransactionFilterProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
32 QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
34 int type = index.data(TransactionTableModel::TypeRole).toInt();
35 QDateTime datetime = index.data(TransactionTableModel::DateRole).toDateTime();
36 bool involvesWatchAddress = index.data(TransactionTableModel::WatchonlyRole).toBool();
37 QString address = index.data(TransactionTableModel::AddressRole).toString();
38 QString label = index.data(TransactionTableModel::LabelRole).toString();
39 qint64 amount = llabs(index.data(TransactionTableModel::AmountRole).toLongLong());
40 int status = index.data(TransactionTableModel::StatusRole).toInt();
42 if(!showInactive && status == TransactionStatus::Conflicted)
43 return false;
44 if(!(TYPE(type) & typeFilter))
45 return false;
46 if (involvesWatchAddress && watchOnlyFilter == WatchOnlyFilter_No)
47 return false;
48 if (!involvesWatchAddress && watchOnlyFilter == WatchOnlyFilter_Yes)
49 return false;
50 if(datetime < dateFrom || datetime > dateTo)
51 return false;
52 if (!address.contains(addrPrefix, Qt::CaseInsensitive) && !label.contains(addrPrefix, Qt::CaseInsensitive))
53 return false;
54 if(amount < minAmount)
55 return false;
57 return true;
60 void TransactionFilterProxy::setDateRange(const QDateTime &from, const QDateTime &to)
62 this->dateFrom = from;
63 this->dateTo = to;
64 invalidateFilter();
67 void TransactionFilterProxy::setAddressPrefix(const QString &_addrPrefix)
69 this->addrPrefix = _addrPrefix;
70 invalidateFilter();
73 void TransactionFilterProxy::setTypeFilter(quint32 modes)
75 this->typeFilter = modes;
76 invalidateFilter();
79 void TransactionFilterProxy::setMinAmount(const CAmount& minimum)
81 this->minAmount = minimum;
82 invalidateFilter();
85 void TransactionFilterProxy::setWatchOnlyFilter(WatchOnlyFilter filter)
87 this->watchOnlyFilter = filter;
88 invalidateFilter();
91 void TransactionFilterProxy::setLimit(int limit)
93 this->limitRows = limit;
96 void TransactionFilterProxy::setShowInactive(bool _showInactive)
98 this->showInactive = _showInactive;
99 invalidateFilter();
102 int TransactionFilterProxy::rowCount(const QModelIndex &parent) const
104 if(limitRows != -1)
106 return std::min(QSortFilterProxyModel::rowCount(parent), limitRows);
108 else
110 return QSortFilterProxyModel::rowCount(parent);