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
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
25bool 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
63void TransactionFilterProxy::setDateRange(const std::optional<QDateTime>& from, const std::optional<QDateTime>& to)
64{
65 dateFrom = from;
66 dateTo = to;
67 invalidateFilter();
68}
69
70void 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
106int 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}
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
std::optional< QDateTime > dateFrom
void setMinAmount(const CAmount &minimum)
void setDateRange(const std::optional< QDateTime > &from, const std::optional< QDateTime > &to)
Filter transactions between date range.
void setLimit(int limit)
Set maximum number of rows returned, -1 if unlimited.
std::optional< QDateTime > dateTo
void setWatchOnlyFilter(WatchOnlyFilter filter)
int rowCount(const QModelIndex &parent=QModelIndex()) const override
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override
static quint32 TYPE(int type)
void setShowInactive(bool showInactive)
Set whether to show conflicted transactions.
void setSearchString(const QString &)
void setTypeFilter(quint32 modes)
TransactionFilterProxy(QObject *parent=nullptr)
@ Conflicted
Conflicts with other transaction or mempool.
@ LabelRole
Label of address related to transaction.
@ TypeRole
Type of transaction.
@ StatusRole
Transaction status (TransactionRecord::Status)
@ DateRole
Date and time this transaction was created.
@ TxHashRole
Transaction hash.
@ AddressRole
Address of transaction.
@ WatchonlyRole
Watch-only boolean.
@ AmountRole
Net amount of transaction.