1 // Copyright (c) 2011-2017 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 QString txid
= index
.data(TransactionTableModel::TxIDRole
).toString();
40 qint64 amount
= llabs(index
.data(TransactionTableModel::AmountRole
).toLongLong());
41 int status
= index
.data(TransactionTableModel::StatusRole
).toInt();
43 if(!showInactive
&& status
== TransactionStatus::Conflicted
)
45 if(!(TYPE(type
) & typeFilter
))
47 if (involvesWatchAddress
&& watchOnlyFilter
== WatchOnlyFilter_No
)
49 if (!involvesWatchAddress
&& watchOnlyFilter
== WatchOnlyFilter_Yes
)
51 if(datetime
< dateFrom
|| datetime
> dateTo
)
53 if (!address
.contains(m_search_string
, Qt::CaseInsensitive
) &&
54 ! label
.contains(m_search_string
, Qt::CaseInsensitive
) &&
55 ! txid
.contains(m_search_string
, Qt::CaseInsensitive
)) {
58 if(amount
< minAmount
)
64 void TransactionFilterProxy::setDateRange(const QDateTime
&from
, const QDateTime
&to
)
66 this->dateFrom
= from
;
71 void TransactionFilterProxy::setSearchString(const QString
&search_string
)
73 if (m_search_string
== search_string
) return;
74 m_search_string
= search_string
;
78 void TransactionFilterProxy::setTypeFilter(quint32 modes
)
80 this->typeFilter
= modes
;
84 void TransactionFilterProxy::setMinAmount(const CAmount
& minimum
)
86 this->minAmount
= minimum
;
90 void TransactionFilterProxy::setWatchOnlyFilter(WatchOnlyFilter filter
)
92 this->watchOnlyFilter
= filter
;
96 void TransactionFilterProxy::setLimit(int limit
)
98 this->limitRows
= limit
;
101 void TransactionFilterProxy::setShowInactive(bool _showInactive
)
103 this->showInactive
= _showInactive
;
107 int TransactionFilterProxy::rowCount(const QModelIndex
&parent
) const
111 return std::min(QSortFilterProxyModel::rowCount(parent
), limitRows
);
115 return QSortFilterProxyModel::rowCount(parent
);