Merge #10114: [tests] sync_with_ping should assert that ping hasn't timed out
[bitcoinplatinum.git] / src / qt / transactionfilterproxy.cpp
blob44e4ef8238419997a34e076962c0a1014771310a
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 "transactionfilterproxy.h"
7 #include "transactiontablemodel.h"
8 #include "transactionrecord.h"
10 #include <cstdlib>
12 #include <QDateTime>
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);
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)
32 bool TransactionFilterProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
34 QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
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();
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;
59 return true;
62 void TransactionFilterProxy::setDateRange(const QDateTime &from, const QDateTime &to)
64 this->dateFrom = from;
65 this->dateTo = to;
66 invalidateFilter();
69 void TransactionFilterProxy::setAddressPrefix(const QString &_addrPrefix)
71 this->addrPrefix = _addrPrefix;
72 invalidateFilter();
75 void TransactionFilterProxy::setTypeFilter(quint32 modes)
77 this->typeFilter = modes;
78 invalidateFilter();
81 void TransactionFilterProxy::setMinAmount(const CAmount& minimum)
83 this->minAmount = minimum;
84 invalidateFilter();
87 void TransactionFilterProxy::setWatchOnlyFilter(WatchOnlyFilter filter)
89 this->watchOnlyFilter = filter;
90 invalidateFilter();
93 void TransactionFilterProxy::setLimit(int limit)
95 this->limitRows = limit;
98 void TransactionFilterProxy::setShowInactive(bool _showInactive)
100 this->showInactive = _showInactive;
101 invalidateFilter();
104 int TransactionFilterProxy::rowCount(const QModelIndex &parent) const
106 if(limitRows != -1)
108 return std::min(QSortFilterProxyModel::rowCount(parent), limitRows);
110 else
112 return QSortFilterProxyModel::rowCount(parent);