PIVX Core  5.6.99
P2P Digital Currency
transactionfilterproxy.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2013 The Bitcoin developers
2 // Copyright (c) 2017-2021 The PIVX Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or https://www.opensource.org/licenses/mit-license.php.
5 
7 
8 #include "transactionrecord.h"
10 
11 #include <cstdlib>
12 
13 // Earliest date that can be represented (far in the past)
14 const QDateTime TransactionFilterProxy::MIN_DATE = QDateTime::fromTime_t(0);
15 // Last date that can be represented (far in the future)
16 const QDateTime TransactionFilterProxy::MAX_DATE = QDateTime::fromTime_t(0xFFFFFFFF);
17 
18 TransactionFilterProxy::TransactionFilterProxy(QObject* parent) : QSortFilterProxyModel(parent),
19  dateFrom(MIN_DATE),
20  dateTo(MAX_DATE),
21  typeFilter(ALL_TYPES),
22  watchOnlyFilter(WatchOnlyFilter_All),
23  minAmount(0),
24  limitRows(-1),
25  showInactive(true),
26  fHideOrphans(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 (fHideOrphans && isOrphan(status, type)) return false;
40  if (!(bool)(TYPE(type) & typeFilter)) 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  qint64 amount = llabs(index.data(TransactionTableModel::AmountRole).toLongLong());
53  if (amount < minAmount)
54  return false;
55 
56  return true;
57 }
58 
59 void TransactionFilterProxy::setDateRange(const QDateTime& from, const QDateTime& to)
60 {
61  if (from == this->dateFrom && to == this->dateTo)
62  return; // No need to set the range.
63  this->dateFrom = from;
64  this->dateTo = to;
65  invalidateFilter();
66 }
67 
69 {
70  if (typeFilter == modes) return;
71  this->typeFilter = modes;
72  invalidateFilter();
73 }
74 
76 {
77  this->minAmount = minimum;
78  invalidateFilter();
79 }
80 
82 {
83  this->watchOnlyFilter = filter;
84  invalidateFilter();
85 }
86 
88 {
89  this->limitRows = limit;
90 }
91 
93 {
94  this->showInactive = showInactive;
95  invalidateFilter();
96 }
97 
99 {
100  this->fHideOrphans = fHide;
101  invalidateFilter();
102 }
103 
104 int TransactionFilterProxy::rowCount(const QModelIndex& parent) const
105 {
106  if (limitRows != -1) {
107  return std::min(QSortFilterProxyModel::rowCount(parent), limitRows);
108  } else {
109  return QSortFilterProxyModel::rowCount(parent);
110  }
111 }
112 
113 bool TransactionFilterProxy::isOrphan(const int status, const int type)
114 {
115  return ( (type == TransactionRecord::Generated || type == TransactionRecord::StakeMint ||
118 }
int64_t CAmount
Amount in PIV (Can be negative)
Definition: amount.h:13
true
Definition: bls_dkg.cpp:153
void setMinAmount(const CAmount &minimum)
void setHideOrphans(bool fHide)
Set whether to hide orphan stakes.
void setLimit(int limit)
Set maximum number of rows returned, -1 if unlimited.
static const QDateTime MAX_DATE
Last date that can be represented (far in the future)
void setWatchOnlyFilter(WatchOnlyFilter filter)
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)
static const QDateTime MIN_DATE
Earliest date that can be represented (far in the past)
void setShowInactive(bool showInactive)
Set whether to show conflicted transactions.
static bool isOrphan(const int status, const int type)
void setDateRange(const QDateTime &from, const QDateTime &to)
void setTypeFilter(quint32 modes)
@ NotAccepted
Mined but not accepted.
@ Conflicted
Conflicts with other transaction or mempool.
@ TypeRole
Type of transaction.
@ StatusRole
Transaction status (TransactionRecord::Status)
@ DateRole
Date and time this transaction was created.
@ WatchonlyRole
Watch-only boolean.
@ AmountRole
Net amount of transaction.