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.
5 #include "transactionfilterproxy.h"
7 #include "transactiontablemodel.h"
8 #include "transactionrecord.h"
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),
24 typeFilter(ALL_TYPES),
31 bool TransactionFilterProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
33 QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
35 int type = index.data(TransactionTableModel::TypeRole).toInt();
36 QDateTime datetime = index.data(TransactionTableModel::DateRole).toDateTime();
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)
44 if(!(TYPE(type) & typeFilter))
46 if(datetime < dateFrom || datetime > dateTo)
48 if (!address.contains(addrPrefix, Qt::CaseInsensitive) && !label.contains(addrPrefix, Qt::CaseInsensitive))
50 if(amount < minAmount)
56 void TransactionFilterProxy::setDateRange(const QDateTime &from, const QDateTime &to)
58 this->dateFrom = from;
63 void TransactionFilterProxy::setAddressPrefix(const QString &addrPrefix)
65 this->addrPrefix = addrPrefix;
69 void TransactionFilterProxy::setTypeFilter(quint32 modes)
71 this->typeFilter = modes;
75 void TransactionFilterProxy::setMinAmount(qint64 minimum)
77 this->minAmount = minimum;
81 void TransactionFilterProxy::setLimit(int limit)
83 this->limitRows = limit;
86 void TransactionFilterProxy::setShowInactive(bool showInactive)
88 this->showInactive = showInactive;
92 int TransactionFilterProxy::rowCount(const QModelIndex &parent) const
96 return std::min(QSortFilterProxyModel::rowCount(parent), limitRows);
100 return QSortFilterProxyModel::rowCount(parent);