Bitcoin Core  24.1.0
P2P Digital Currency
transactionfilterproxy.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2021 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 <algorithm>
11 #include <cstdlib>
12 #include <optional>
13 
15  QSortFilterProxyModel(parent),
16  m_search_string(),
17  typeFilter(ALL_TYPES),
18  watchOnlyFilter(WatchOnlyFilter_All),
19  minAmount(0),
20  showInactive(true)
21 {
22 }
23 
24 bool TransactionFilterProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
25 {
26  QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
27 
28  int status = index.data(TransactionTableModel::StatusRole).toInt();
30  return false;
31 
32  int type = index.data(TransactionTableModel::TypeRole).toInt();
33  if (!(TYPE(type) & typeFilter))
34  return false;
35 
36  bool involvesWatchAddress = index.data(TransactionTableModel::WatchonlyRole).toBool();
37  if (involvesWatchAddress && watchOnlyFilter == WatchOnlyFilter_No)
38  return false;
39  if (!involvesWatchAddress && watchOnlyFilter == WatchOnlyFilter_Yes)
40  return false;
41 
42  QDateTime datetime = index.data(TransactionTableModel::DateRole).toDateTime();
43  if (dateFrom && datetime < *dateFrom) return false;
44  if (dateTo && datetime > *dateTo) return false;
45 
46  QString address = index.data(TransactionTableModel::AddressRole).toString();
47  QString label = index.data(TransactionTableModel::LabelRole).toString();
48  QString txid = index.data(TransactionTableModel::TxHashRole).toString();
49  if (!address.contains(m_search_string, Qt::CaseInsensitive) &&
50  ! label.contains(m_search_string, Qt::CaseInsensitive) &&
51  ! txid.contains(m_search_string, Qt::CaseInsensitive)) {
52  return false;
53  }
54 
55  qint64 amount = llabs(index.data(TransactionTableModel::AmountRole).toLongLong());
56  if (amount < minAmount)
57  return false;
58 
59  return true;
60 }
61 
62 void TransactionFilterProxy::setDateRange(const std::optional<QDateTime>& from, const std::optional<QDateTime>& to)
63 {
64  dateFrom = from;
65  dateTo = to;
66  invalidateFilter();
67 }
68 
69 void TransactionFilterProxy::setSearchString(const QString &search_string)
70 {
71  if (m_search_string == search_string) return;
72  m_search_string = search_string;
73  invalidateFilter();
74 }
75 
77 {
78  this->typeFilter = modes;
79  invalidateFilter();
80 }
81 
83 {
84  this->minAmount = minimum;
85  invalidateFilter();
86 }
87 
89 {
90  this->watchOnlyFilter = filter;
91  invalidateFilter();
92 }
93 
95 {
96  this->showInactive = _showInactive;
97  invalidateFilter();
98 }
std::optional< QDateTime > dateTo
Transaction status (TransactionRecord::Status)
void setTypeFilter(quint32 modes)
static quint32 TYPE(int type)
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
std::optional< QDateTime > dateFrom
TransactionFilterProxy(QObject *parent=nullptr)
Date and time this transaction was created.
void setWatchOnlyFilter(WatchOnlyFilter filter)
void setMinAmount(const CAmount &minimum)
void setShowInactive(bool showInactive)
Set whether to show conflicted transactions.
Label of address related to transaction.
void setSearchString(const QString &)
Conflicts with other transaction or mempool.
void setDateRange(const std::optional< QDateTime > &from, const std::optional< QDateTime > &to)
Filter transactions between date range.
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override