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