BSHA3  0.17.99
P2P Blockchain, based on Bitcoin
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 
8 #include <qt/transactionrecord.h>
9 
10 #include <cstdlib>
11 
12 // Earliest date that can be represented (far in the past)
13 const QDateTime TransactionFilterProxy::MIN_DATE = QDateTime::fromTime_t(0);
14 // Last date that can be represented (far in the future)
15 const QDateTime TransactionFilterProxy::MAX_DATE = QDateTime::fromTime_t(0xFFFFFFFF);
16 
18  QSortFilterProxyModel(parent),
19  dateFrom(MIN_DATE),
20  dateTo(MAX_DATE),
21  m_search_string(),
22  typeFilter(ALL_TYPES),
23  watchOnlyFilter(WatchOnlyFilter_All),
24  minAmount(0),
25  limitRows(-1),
26  showInactive(true)
27 {
28 }
29 
30 bool TransactionFilterProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
31 {
32  QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
33 
34  int status = index.data(TransactionTableModel::StatusRole).toInt();
36  return false;
37 
38  int type = index.data(TransactionTableModel::TypeRole).toInt();
39  if (!(TYPE(type) & typeFilter))
40  return false;
41 
42  bool involvesWatchAddress = index.data(TransactionTableModel::WatchonlyRole).toBool();
43  if (involvesWatchAddress && watchOnlyFilter == WatchOnlyFilter_No)
44  return false;
45  if (!involvesWatchAddress && watchOnlyFilter == WatchOnlyFilter_Yes)
46  return false;
47 
48  QDateTime datetime = index.data(TransactionTableModel::DateRole).toDateTime();
49  if (datetime < dateFrom || datetime > dateTo)
50  return false;
51 
52  QString address = index.data(TransactionTableModel::AddressRole).toString();
53  QString label = index.data(TransactionTableModel::LabelRole).toString();
54  QString txid = index.data(TransactionTableModel::TxHashRole).toString();
55  if (!address.contains(m_search_string, Qt::CaseInsensitive) &&
56  ! label.contains(m_search_string, Qt::CaseInsensitive) &&
57  ! txid.contains(m_search_string, Qt::CaseInsensitive)) {
58  return false;
59  }
60 
61  qint64 amount = llabs(index.data(TransactionTableModel::AmountRole).toLongLong());
62  if (amount < minAmount)
63  return false;
64 
65  return true;
66 }
67 
68 void TransactionFilterProxy::setDateRange(const QDateTime &from, const QDateTime &to)
69 {
70  this->dateFrom = from;
71  this->dateTo = to;
72  invalidateFilter();
73 }
74 
75 void TransactionFilterProxy::setSearchString(const QString &search_string)
76 {
77  if (m_search_string == search_string) return;
78  m_search_string = search_string;
79  invalidateFilter();
80 }
81 
83 {
84  this->typeFilter = modes;
85  invalidateFilter();
86 }
87 
89 {
90  this->minAmount = minimum;
91  invalidateFilter();
92 }
93 
95 {
96  this->watchOnlyFilter = filter;
97  invalidateFilter();
98 }
99 
101 {
102  this->limitRows = limit;
103 }
104 
106 {
107  this->showInactive = _showInactive;
108  invalidateFilter();
109 }
110 
111 int TransactionFilterProxy::rowCount(const QModelIndex &parent) const
112 {
113  if(limitRows != -1)
114  {
115  return std::min(QSortFilterProxyModel::rowCount(parent), limitRows);
116  }
117  else
118  {
119  return QSortFilterProxyModel::rowCount(parent);
120  }
121 }
Transaction status (TransactionRecord::Status)
void setTypeFilter(quint32 modes)
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
int rowCount(const QModelIndex &parent=QModelIndex()) const
TransactionFilterProxy(QObject *parent=0)
static quint32 TYPE(int type)
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
isminefilter filter
Definition: rpcwallet.cpp:1011
static const QDateTime MIN_DATE
Earliest date that can be represented (far in the past)
static const QDateTime MAX_DATE
Last date that can be represented (far in the future)
void setDateRange(const QDateTime &from, const QDateTime &to)
Date and time this transaction was created.
void setWatchOnlyFilter(WatchOnlyFilter filter)
void setMinAmount(const CAmount &minimum)
void setLimit(int limit)
Set maximum number of rows returned, -1 if unlimited.
void setShowInactive(bool showInactive)
Set whether to show conflicted transactions.
Conflicts with other transaction or mempool.
Label of address related to transaction.
void setSearchString(const QString &)