Bitcoin Core 29.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 m_search_string(),
17 typeFilter(ALL_TYPES)
18{
19}
20
21bool TransactionFilterProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
22{
23 QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
24
25 int status = index.data(TransactionTableModel::StatusRole).toInt();
27 return false;
28
29 int type = index.data(TransactionTableModel::TypeRole).toInt();
30 if (!(TYPE(type) & typeFilter))
31 return false;
32
33 QDateTime datetime = index.data(TransactionTableModel::DateRole).toDateTime();
34 if (dateFrom && datetime < *dateFrom) return false;
35 if (dateTo && datetime > *dateTo) return false;
36
37 QString address = index.data(TransactionTableModel::AddressRole).toString();
38 QString label = index.data(TransactionTableModel::LabelRole).toString();
39 QString txid = index.data(TransactionTableModel::TxHashRole).toString();
40 if (!address.contains(m_search_string, Qt::CaseInsensitive) &&
41 ! label.contains(m_search_string, Qt::CaseInsensitive) &&
42 ! txid.contains(m_search_string, Qt::CaseInsensitive)) {
43 return false;
44 }
45
46 qint64 amount = llabs(index.data(TransactionTableModel::AmountRole).toLongLong());
47 if (amount < minAmount)
48 return false;
49
50 return true;
51}
52
53void TransactionFilterProxy::setDateRange(const std::optional<QDateTime>& from, const std::optional<QDateTime>& to)
54{
55 dateFrom = from;
56 dateTo = to;
57 invalidateFilter();
58}
59
60void TransactionFilterProxy::setSearchString(const QString &search_string)
61{
62 if (m_search_string == search_string) return;
63 m_search_string = search_string;
64 invalidateFilter();
65}
66
68{
69 this->typeFilter = modes;
70 invalidateFilter();
71}
72
74{
75 this->minAmount = minimum;
76 invalidateFilter();
77}
78
80{
81 this->showInactive = _showInactive;
82 invalidateFilter();
83}
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.