Bitcoin Core  22.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 <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  limitRows(-1),
21  showInactive(true)
22 {
23 }
24 
25 bool TransactionFilterProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
26 {
27  QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
28 
29  int status = index.data(TransactionTableModel::StatusRole).toInt();
31  return false;
32 
33  int type = index.data(TransactionTableModel::TypeRole).toInt();
34  if (!(TYPE(type) & typeFilter))
35  return false;
36 
37  bool involvesWatchAddress = index.data(TransactionTableModel::WatchonlyRole).toBool();
38  if (involvesWatchAddress && watchOnlyFilter == WatchOnlyFilter_No)
39  return false;
40  if (!involvesWatchAddress && watchOnlyFilter == WatchOnlyFilter_Yes)
41  return false;
42 
43  QDateTime datetime = index.data(TransactionTableModel::DateRole).toDateTime();
44  if (dateFrom && datetime < *dateFrom) return false;
45  if (dateTo && datetime > *dateTo) return false;
46 
47  QString address = index.data(TransactionTableModel::AddressRole).toString();
48  QString label = index.data(TransactionTableModel::LabelRole).toString();
49  QString txid = index.data(TransactionTableModel::TxHashRole).toString();
50  if (!address.contains(m_search_string, Qt::CaseInsensitive) &&
51  ! label.contains(m_search_string, Qt::CaseInsensitive) &&
52  ! txid.contains(m_search_string, Qt::CaseInsensitive)) {
53  return false;
54  }
55 
56  qint64 amount = llabs(index.data(TransactionTableModel::AmountRole).toLongLong());
57  if (amount < minAmount)
58  return false;
59 
60  return true;
61 }
62 
63 void TransactionFilterProxy::setDateRange(const std::optional<QDateTime>& from, const std::optional<QDateTime>& to)
64 {
65  dateFrom = from;
66  dateTo = to;
67  invalidateFilter();
68 }
69 
70 void TransactionFilterProxy::setSearchString(const QString &search_string)
71 {
72  if (m_search_string == search_string) return;
73  m_search_string = search_string;
74  invalidateFilter();
75 }
76 
78 {
79  this->typeFilter = modes;
80  invalidateFilter();
81 }
82 
84 {
85  this->minAmount = minimum;
86  invalidateFilter();
87 }
88 
90 {
91  this->watchOnlyFilter = filter;
92  invalidateFilter();
93 }
94 
96 {
97  this->limitRows = limit;
98 }
99 
101 {
102  this->showInactive = _showInactive;
103  invalidateFilter();
104 }
105 
106 int TransactionFilterProxy::rowCount(const QModelIndex &parent) const
107 {
108  if(limitRows != -1)
109  {
110  return std::min(QSortFilterProxyModel::rowCount(parent), limitRows);
111  }
112  else
113  {
114  return QSortFilterProxyModel::rowCount(parent);
115  }
116 }
transactiontablemodel.h
TransactionFilterProxy::setDateRange
void setDateRange(const std::optional< QDateTime > &from, const std::optional< QDateTime > &to)
Filter transactions between date range.
Definition: transactionfilterproxy.cpp:63
TransactionTableModel::AddressRole
@ AddressRole
Address of transaction.
Definition: transactiontablemodel.h:58
TransactionFilterProxy::setSearchString
void setSearchString(const QString &)
Definition: transactionfilterproxy.cpp:70
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:32
TransactionFilterProxy::filterAcceptsRow
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override
Definition: transactionfilterproxy.cpp:25
TransactionFilterProxy::setShowInactive
void setShowInactive(bool showInactive)
Set whether to show conflicted transactions.
Definition: transactionfilterproxy.cpp:100
TransactionFilterProxy::showInactive
bool showInactive
Definition: transactionfilterproxy.h:64
TransactionTableModel::AmountRole
@ AmountRole
Net amount of transaction.
Definition: transactiontablemodel.h:62
TransactionFilterProxy::setMinAmount
void setMinAmount(const CAmount &minimum)
Definition: transactionfilterproxy.cpp:83
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:95
TransactionFilterProxy::TYPE
static quint32 TYPE(int type)
Definition: transactionfilterproxy.h:26
TransactionTableModel::StatusRole
@ StatusRole
Transaction status (TransactionRecord::Status)
Definition: transactiontablemodel.h:74
TransactionFilterProxy::limitRows
int limitRows
Definition: transactionfilterproxy.h:63
TransactionFilterProxy::typeFilter
quint32 typeFilter
Definition: transactionfilterproxy.h:60
TransactionFilterProxy::setTypeFilter
void setTypeFilter(quint32 modes)
Definition: transactionfilterproxy.cpp:77
TransactionFilterProxy::setWatchOnlyFilter
void setWatchOnlyFilter(WatchOnlyFilter filter)
Definition: transactionfilterproxy.cpp:89
TransactionFilterProxy::m_search_string
QString m_search_string
Definition: transactionfilterproxy.h:59
TransactionFilterProxy::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: transactionfilterproxy.cpp:106
transactionrecord.h
TransactionFilterProxy::WatchOnlyFilter_Yes
@ WatchOnlyFilter_Yes
Definition: transactionfilterproxy.h:31
TransactionFilterProxy::TransactionFilterProxy
TransactionFilterProxy(QObject *parent=nullptr)
Definition: transactionfilterproxy.cpp:14
TransactionFilterProxy::WatchOnlyFilter
WatchOnlyFilter
Definition: transactionfilterproxy.h:28
TransactionFilterProxy::dateFrom
std::optional< QDateTime > dateFrom
Definition: transactionfilterproxy.h:57
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:61
TransactionTableModel::LabelRole
@ LabelRole
Label of address related to transaction.
Definition: transactiontablemodel.h:60
TransactionFilterProxy::minAmount
CAmount minAmount
Definition: transactionfilterproxy.h:62
TransactionFilterProxy::dateTo
std::optional< QDateTime > dateTo
Definition: transactionfilterproxy.h:58