Bitcoin Core 30.99.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
9
10#include <algorithm>
11#include <cstdlib>
12#include <optional>
13
15 : QSortFilterProxyModel(parent)
16{
17}
18
19bool TransactionFilterProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
20{
21 QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
22
23 int status = index.data(TransactionTableModel::StatusRole).toInt();
25 return false;
26
27 int type = index.data(TransactionTableModel::TypeRole).toInt();
28 if (!(TYPE(type) & typeFilter))
29 return false;
30
31 QDateTime datetime = index.data(TransactionTableModel::DateRole).toDateTime();
32 if (dateFrom && datetime < *dateFrom) return false;
33 if (dateTo && datetime > *dateTo) return false;
34
35 QString address = index.data(TransactionTableModel::AddressRole).toString();
36 QString label = index.data(TransactionTableModel::LabelRole).toString();
37 QString txid = index.data(TransactionTableModel::TxHashRole).toString();
38 if (!address.contains(m_search_string, Qt::CaseInsensitive) &&
39 ! label.contains(m_search_string, Qt::CaseInsensitive) &&
40 ! txid.contains(m_search_string, Qt::CaseInsensitive)) {
41 return false;
42 }
43
44 qint64 amount = llabs(index.data(TransactionTableModel::AmountRole).toLongLong());
45 if (amount < minAmount)
46 return false;
47
48 return true;
49}
50
51void TransactionFilterProxy::setDateRange(const std::optional<QDateTime>& from, const std::optional<QDateTime>& to)
52{
53#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0)
54 beginFilterChange();
55#endif
56
57 dateFrom = from;
58 dateTo = to;
59
60#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0)
61 endFilterChange(QSortFilterProxyModel::Direction::Rows);
62#else
63 invalidateFilter();
64#endif
65}
66
67void TransactionFilterProxy::setSearchString(const QString &search_string)
68{
69 if (m_search_string == search_string) return;
70
71#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0)
72 beginFilterChange();
73#endif
74
75 m_search_string = search_string;
76
77#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0)
78 endFilterChange(QSortFilterProxyModel::Direction::Rows);
79#else
80 invalidateFilter();
81#endif
82}
83
85{
86#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0)
87 beginFilterChange();
88#endif
89
90 this->typeFilter = modes;
91
92#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0)
93 endFilterChange(QSortFilterProxyModel::Direction::Rows);
94#else
95 invalidateFilter();
96#endif
97}
98
100{
101#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0)
102 beginFilterChange();
103#endif
104
105 this->minAmount = minimum;
106
107#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0)
108 endFilterChange(QSortFilterProxyModel::Direction::Rows);
109#else
110 invalidateFilter();
111#endif
112}
113
115{
116#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0)
117 beginFilterChange();
118#endif
119
120 this->showInactive = _showInactive;
121
122#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0)
123 endFilterChange(QSortFilterProxyModel::Direction::Rows);
124#else
125 invalidateFilter();
126#endif
127}
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.
std::optional< QDateTime > dateTo
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)
@ 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.
@ AmountRole
Net amount of transaction.
@ Conflicted
Conflicts with other transaction or mempool.