Bitcoin Core  21.99.0
P2P Digital Currency
transactionfilterproxy.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2018 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.
4 
6 
8 #include <qt/transactionrecord.h>
9 
10 #include <cstdlib>
11 
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);
16 
18  QSortFilterProxyModel(parent),
19  dateFrom(MIN_DATE),
20  dateTo(MAX_DATE),
21  m_search_string(),
22  typeFilter(ALL_TYPES),
23  watchOnlyFilter(WatchOnlyFilter_All),
24  minAmount(0),
25  limitRows(-1),
26  showInactive(true)
27 {
28 }
29 
30 bool TransactionFilterProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
31 {
32  QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
33 
34  int status = index.data(TransactionTableModel::StatusRole).toInt();
36  return false;
37 
38  int type = index.data(TransactionTableModel::TypeRole).toInt();
39  if (!(TYPE(type) & typeFilter))
40  return false;
41 
42  bool involvesWatchAddress = index.data(TransactionTableModel::WatchonlyRole).toBool();
43  if (involvesWatchAddress && watchOnlyFilter == WatchOnlyFilter_No)
44  return false;
45  if (!involvesWatchAddress && watchOnlyFilter == WatchOnlyFilter_Yes)
46  return false;
47 
48  QDateTime datetime = index.data(TransactionTableModel::DateRole).toDateTime();
49  if (datetime < dateFrom || datetime > dateTo)
50  return false;
51 
52  QString address = index.data(TransactionTableModel::AddressRole).toString();
53  QString label = index.data(TransactionTableModel::LabelRole).toString();
54  QString txid = index.data(TransactionTableModel::TxHashRole).toString();
55  if (!address.contains(m_search_string, Qt::CaseInsensitive) &&
56  ! label.contains(m_search_string, Qt::CaseInsensitive) &&
57  ! txid.contains(m_search_string, Qt::CaseInsensitive)) {
58  return false;
59  }
60 
61  qint64 amount = llabs(index.data(TransactionTableModel::AmountRole).toLongLong());
62  if (amount < minAmount)
63  return false;
64 
65  return true;
66 }
67 
68 void TransactionFilterProxy::setDateRange(const QDateTime &from, const QDateTime &to)
69 {
70  this->dateFrom = from;
71  this->dateTo = to;
72  invalidateFilter();
73 }
74 
75 void TransactionFilterProxy::setSearchString(const QString &search_string)
76 {
77  if (m_search_string == search_string) return;
78  m_search_string = search_string;
79  invalidateFilter();
80 }
81 
83 {
84  this->typeFilter = modes;
85  invalidateFilter();
86 }
87 
89 {
90  this->minAmount = minimum;
91  invalidateFilter();
92 }
93 
95 {
96  this->watchOnlyFilter = filter;
97  invalidateFilter();
98 }
99 
101 {
102  this->limitRows = limit;
103 }
104 
106 {
107  this->showInactive = _showInactive;
108  invalidateFilter();
109 }
110 
111 int TransactionFilterProxy::rowCount(const QModelIndex &parent) const
112 {
113  if(limitRows != -1)
114  {
115  return std::min(QSortFilterProxyModel::rowCount(parent), limitRows);
116  }
117  else
118  {
119  return QSortFilterProxyModel::rowCount(parent);
120  }
121 }
transactiontablemodel.h
TransactionTableModel::AddressRole
@ AddressRole
Address of transaction.
Definition: transactiontablemodel.h:58
TransactionFilterProxy::setSearchString
void setSearchString(const QString &)
Definition: transactionfilterproxy.cpp:75
TransactionFilterProxy::dateTo
QDateTime dateTo
Definition: transactionfilterproxy.h:59
TransactionTableModel::WatchonlyRole
@ WatchonlyRole
Watch-only boolean.
Definition: transactiontablemodel.h:52
TransactionStatus::Conflicted
@ Conflicted
Conflicts with other transaction or mempool.
Definition: transactionrecord.h:37
TransactionFilterProxy::WatchOnlyFilter_No
@ WatchOnlyFilter_No
Definition: transactionfilterproxy.h:34
TransactionFilterProxy::MIN_DATE
static const QDateTime MIN_DATE
Earliest date that can be represented (far in the past)
Definition: transactionfilterproxy.h:22
TransactionFilterProxy::filterAcceptsRow
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override
Definition: transactionfilterproxy.cpp:30
TransactionFilterProxy::setShowInactive
void setShowInactive(bool showInactive)
Set whether to show conflicted transactions.
Definition: transactionfilterproxy.cpp:105
TransactionFilterProxy::showInactive
bool showInactive
Definition: transactionfilterproxy.h:65
TransactionTableModel::AmountRole
@ AmountRole
Net amount of transaction.
Definition: transactiontablemodel.h:62
TransactionFilterProxy::setMinAmount
void setMinAmount(const CAmount &minimum)
Definition: transactionfilterproxy.cpp:88
transactionfilterproxy.h
CAmount
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
TransactionFilterProxy::setLimit
void setLimit(int limit)
Set maximum number of rows returned, -1 if unlimited.
Definition: transactionfilterproxy.cpp:100
TransactionFilterProxy::TYPE
static quint32 TYPE(int type)
Definition: transactionfilterproxy.h:28
TransactionTableModel::StatusRole
@ StatusRole
Transaction status (TransactionRecord::Status)
Definition: transactiontablemodel.h:74
TransactionFilterProxy::limitRows
int limitRows
Definition: transactionfilterproxy.h:64
TransactionFilterProxy::typeFilter
quint32 typeFilter
Definition: transactionfilterproxy.h:61
TransactionFilterProxy::setTypeFilter
void setTypeFilter(quint32 modes)
Definition: transactionfilterproxy.cpp:82
TransactionFilterProxy::setWatchOnlyFilter
void setWatchOnlyFilter(WatchOnlyFilter filter)
Definition: transactionfilterproxy.cpp:94
TransactionFilterProxy::MAX_DATE
static const QDateTime MAX_DATE
Last date that can be represented (far in the future)
Definition: transactionfilterproxy.h:24
TransactionFilterProxy::m_search_string
QString m_search_string
Definition: transactionfilterproxy.h:60
TransactionFilterProxy::setDateRange
void setDateRange(const QDateTime &from, const QDateTime &to)
Definition: transactionfilterproxy.cpp:68
TransactionFilterProxy::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: transactionfilterproxy.cpp:111
transactionrecord.h
TransactionFilterProxy::WatchOnlyFilter_Yes
@ WatchOnlyFilter_Yes
Definition: transactionfilterproxy.h:33
TransactionFilterProxy::TransactionFilterProxy
TransactionFilterProxy(QObject *parent=nullptr)
Definition: transactionfilterproxy.cpp:17
TransactionFilterProxy::WatchOnlyFilter
WatchOnlyFilter
Definition: transactionfilterproxy.h:30
TransactionTableModel::TxHashRole
@ TxHashRole
Transaction hash.
Definition: transactiontablemodel.h:64
TransactionTableModel::DateRole
@ DateRole
Date and time this transaction was created.
Definition: transactiontablemodel.h:50
TransactionTableModel::TypeRole
@ TypeRole
Type of transaction.
Definition: transactiontablemodel.h:48
TransactionFilterProxy::watchOnlyFilter
WatchOnlyFilter watchOnlyFilter
Definition: transactionfilterproxy.h:62
TransactionTableModel::LabelRole
@ LabelRole
Label of address related to transaction.
Definition: transactiontablemodel.h:60
TransactionFilterProxy::minAmount
CAmount minAmount
Definition: transactionfilterproxy.h:63
TransactionFilterProxy::dateFrom
QDateTime dateFrom
Definition: transactionfilterproxy.h:58