Bitcoin ABC 0.32.6
P2P Digital Currency
transactionfilterproxy.cpp
Go to the documentation of this file.
1// Copyright (c) 2011-2016 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
18 int sourceRow, const QModelIndex &sourceParent) const {
19 QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
20
21 int status = index.data(TransactionTableModel::StatusRole).toInt();
23 return false;
24 }
25
26 int type = index.data(TransactionTableModel::TypeRole).toInt();
27 if (!(TYPE(type) & typeFilter)) {
28 return false;
29 }
30
31 bool involvesWatchAddress =
32 index.data(TransactionTableModel::WatchonlyRole).toBool();
33 if (involvesWatchAddress && watchOnlyFilter == WatchOnlyFilter_No) {
34 return false;
35 }
36 if (!involvesWatchAddress && watchOnlyFilter == WatchOnlyFilter_Yes) {
37 return false;
38 }
39
40 QDateTime datetime =
41 index.data(TransactionTableModel::DateRole).toDateTime();
42 if (dateFrom && datetime < *dateFrom) {
43 return false;
44 }
45 if (dateTo && datetime > *dateTo) {
46 return false;
47 }
48
49 QString address = index.data(TransactionTableModel::AddressRole).toString();
50 QString label = index.data(TransactionTableModel::LabelRole).toString();
51 QString txid = index.data(TransactionTableModel::TxHashRole).toString();
52 if (!address.contains(m_search_string, Qt::CaseInsensitive) &&
53 !label.contains(m_search_string, Qt::CaseInsensitive) &&
54 !txid.contains(m_search_string, Qt::CaseInsensitive)) {
55 return false;
56 }
57
58 Amount amount(
59 int64_t(
60 llabs(index.data(TransactionTableModel::AmountRole).toLongLong())) *
61 SATOSHI);
62 if (amount < minAmount) {
63 return false;
64 }
65
66 return true;
67}
68
69void TransactionFilterProxy::setDateRange(const std::optional<QDateTime> &from,
70 const std::optional<QDateTime> &to) {
71 dateFrom = from;
72 dateTo = to;
73 invalidateFilter();
74}
75
76void TransactionFilterProxy::setSearchString(const QString &search_string) {
77 if (m_search_string == search_string) {
78 return;
79 }
80 m_search_string = search_string;
81 invalidateFilter();
82}
83
85 this->typeFilter = modes;
86 invalidateFilter();
87}
88
90 this->minAmount = minimum;
91 invalidateFilter();
92}
93
95 this->watchOnlyFilter = filter;
96 invalidateFilter();
97}
98
100 this->limitRows = limit;
101}
102
104 this->showInactive = _showInactive;
105 invalidateFilter();
106}
107
108int TransactionFilterProxy::rowCount(const QModelIndex &parent) const {
109 if (limitRows != -1) {
110 return std::min(QSortFilterProxyModel::rowCount(parent), limitRows);
111 } else {
112 return QSortFilterProxyModel::rowCount(parent);
113 }
114}
static constexpr Amount SATOSHI
Definition: amount.h:148
std::optional< QDateTime > dateFrom
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 setMinAmount(const Amount minimum)
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.
Definition: amount.h:21