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"
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
),
25 watchOnlyFilter(WatchOnlyFilter_All
),
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
)
46 if(!(TYPE(type
) & typeFilter
))
48 if (involvesWatchAddress
&& watchOnlyFilter
== WatchOnlyFilter_No
)
50 if (!involvesWatchAddress
&& watchOnlyFilter
== WatchOnlyFilter_Yes
)
52 if(datetime
< dateFrom
|| datetime
> dateTo
)
54 if (!address
.contains(addrPrefix
, Qt::CaseInsensitive
) && !label
.contains(addrPrefix
, Qt::CaseInsensitive
))
56 if(amount
< minAmount
)
62 void TransactionFilterProxy::setDateRange(const QDateTime
&from
, const QDateTime
&to
)
64 this->dateFrom
= from
;
69 void TransactionFilterProxy::setAddressPrefix(const QString
&_addrPrefix
)
71 this->addrPrefix
= _addrPrefix
;
75 void TransactionFilterProxy::setTypeFilter(quint32 modes
)
77 this->typeFilter
= modes
;
81 void TransactionFilterProxy::setMinAmount(const CAmount
& minimum
)
83 this->minAmount
= minimum
;
87 void TransactionFilterProxy::setWatchOnlyFilter(WatchOnlyFilter filter
)
89 this->watchOnlyFilter
= filter
;
93 void TransactionFilterProxy::setLimit(int limit
)
95 this->limitRows
= limit
;
98 void TransactionFilterProxy::setShowInactive(bool _showInactive
)
100 this->showInactive
= _showInactive
;
104 int TransactionFilterProxy::rowCount(const QModelIndex
&parent
) const
108 return std::min(QSortFilterProxyModel::rowCount(parent
), limitRows
);
112 return QSortFilterProxyModel::rowCount(parent
);