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>
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
),
22 typeFilter(ALL_TYPES
),
23 watchOnlyFilter(WatchOnlyFilter_All
),
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
)
44 if(!(TYPE(type
) & typeFilter
))
46 if (involvesWatchAddress
&& watchOnlyFilter
== WatchOnlyFilter_No
)
48 if (!involvesWatchAddress
&& watchOnlyFilter
== WatchOnlyFilter_Yes
)
50 if(datetime
< dateFrom
|| datetime
> dateTo
)
52 if (!address
.contains(addrPrefix
, Qt::CaseInsensitive
) && !label
.contains(addrPrefix
, Qt::CaseInsensitive
))
54 if(amount
< minAmount
)
60 void TransactionFilterProxy::setDateRange(const QDateTime
&from
, const QDateTime
&to
)
62 this->dateFrom
= from
;
67 void TransactionFilterProxy::setAddressPrefix(const QString
&_addrPrefix
)
69 this->addrPrefix
= _addrPrefix
;
73 void TransactionFilterProxy::setTypeFilter(quint32 modes
)
75 this->typeFilter
= modes
;
79 void TransactionFilterProxy::setMinAmount(const CAmount
& minimum
)
81 this->minAmount
= minimum
;
85 void TransactionFilterProxy::setWatchOnlyFilter(WatchOnlyFilter filter
)
87 this->watchOnlyFilter
= filter
;
91 void TransactionFilterProxy::setLimit(int limit
)
93 this->limitRows
= limit
;
96 void TransactionFilterProxy::setShowInactive(bool _showInactive
)
98 this->showInactive
= _showInactive
;
102 int TransactionFilterProxy::rowCount(const QModelIndex
&parent
) const
106 return std::min(QSortFilterProxyModel::rowCount(parent
), limitRows
);
110 return QSortFilterProxyModel::rowCount(parent
);