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