Fabcoin Core  0.16.2
P2P Digital Currency
tokenfilterproxy.cpp
Go to the documentation of this file.
1 #include <tokenfilterproxy.h>
2 
3 #include <cstdlib>
4 
5 #include <QDateTime>
6 
7 // Earliest date that can be represented (far in the past)
8 const QDateTime TokenFilterProxy::MIN_DATE = QDateTime::fromTime_t(0);
9 // Last date that can be represented (far in the future)
10 const QDateTime TokenFilterProxy::MAX_DATE = QDateTime::fromTime_t(0xFFFFFFFF);
11 
12 int256_t abs_int256(const int256_t& value)
13 {
14  return value > 0 ? value : -value;
15 }
16 
18  QSortFilterProxyModel(parent),
19  dateFrom(MIN_DATE),
20  dateTo(MAX_DATE),
21  addrPrefix(),
22  name(),
23  typeFilter(ALL_TYPES),
24  minAmount(0),
25  limitRows(-1)
26 {
27 
28 }
29 
30 void TokenFilterProxy::setDateRange(const QDateTime &from, const QDateTime &to)
31 {
32  this->dateFrom = from;
33  this->dateTo = to;
34  invalidateFilter();
35 }
36 
37 void TokenFilterProxy::setAddressPrefix(const QString &_addrPrefix)
38 {
39  this->addrPrefix = _addrPrefix;
40  invalidateFilter();
41 }
42 
44 {
45  this->typeFilter = modes;
46  invalidateFilter();
47 }
48 
49 void TokenFilterProxy::setMinAmount(const int256_t &minimum)
50 {
51  this->minAmount = minimum;
52  invalidateFilter();
53 }
54 
55 void TokenFilterProxy::setName(const QString _name)
56 {
57  this->name = _name;
58  invalidateFilter();
59 }
60 
62 {
63  this->limitRows = limit;
64 }
65 
66 int TokenFilterProxy::rowCount(const QModelIndex &parent) const
67 {
68  if(limitRows != -1)
69  {
70  return std::min(QSortFilterProxyModel::rowCount(parent), limitRows);
71  }
72  else
73  {
74  return QSortFilterProxyModel::rowCount(parent);
75  }
76 }
77 
78 bool TokenFilterProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
79 {
80  QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
81 
82  int type = index.data(TokenTransactionTableModel::TypeRole).toInt();
83  QDateTime datetime = index.data(TokenTransactionTableModel::DateRole).toDateTime();
84  QString address = index.data(TokenTransactionTableModel::AddressRole).toString();
85  int256_t amount(index.data(TokenTransactionTableModel::AmountRole).toString().toStdString());
86  amount = abs_int256(amount);
87  QString tokenName = index.data(TokenTransactionTableModel::NameRole).toString();
88 
89  if(!(TYPE(type) & typeFilter))
90  return false;
91  if(datetime < dateFrom || datetime > dateTo)
92  return false;
93  if (!address.contains(addrPrefix, Qt::CaseInsensitive))
94  return false;
95  if(amount < minAmount)
96  return false;
97  if(!name.isEmpty() && name != tokenName)
98  return false;
99 
100  return true;
101 }
102 
103 bool TokenFilterProxy::lessThan(const QModelIndex &left, const QModelIndex &right) const
104 {
105  if(left.column() == TokenTransactionTableModel::Amount &&
106  right.column() == TokenTransactionTableModel::Amount)
107  {
108  int256_t amountLeft(left.data(TokenTransactionTableModel::AmountRole).toString().toStdString());
109  amountLeft = abs_int256(amountLeft);
110 
111  int256_t amountRight(right.data(TokenTransactionTableModel::AmountRole).toString().toStdString());
112  amountRight = abs_int256(amountRight);
113 
114  return amountLeft < amountRight;
115  }
116  return QSortFilterProxyModel::lessThan(left, right);
117 }
Date and time this transaction was created.
static quint32 TYPE(int type)
bool lessThan(const QModelIndex &left, const QModelIndex &right) const
void setTypeFilter(quint32 modes)
TokenFilterProxy(QObject *parent=0)
void setName(const QString _name)
void setDateRange(const QDateTime &from, const QDateTime &to)
int rowCount(const QModelIndex &parent=QModelIndex()) const
void setAddressPrefix(const QString &addrPrefix)
ExecStats::duration min
Definition: ExecStats.cpp:35
static const QDateTime MIN_DATE
Earliest date that can be represented (far in the past)
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)
const char * name
Definition: rest.cpp:36
void setMinAmount(const int256_t &minimum)
int256_t abs_int256(const int256_t &value)
PlatformStyle::TableColorType type
Definition: rpcconsole.cpp:61
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
struct evm_uint160be address(struct evm_env *env)
Definition: capi.c:13