Raven Core  3.0.0
P2P Digital Currency
transactionfilterproxy.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2016 The Bitcoin Core developers
2 // Copyright (c) 2017-2019 The Raven Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
7 
9 #include "transactionrecord.h"
10 
11 #include <cstdlib>
12 
13 #include <QDateTime>
14 
15 // Earliest date that can be represented (far in the past)
16 const QDateTime TransactionFilterProxy::MIN_DATE = QDateTime::fromTime_t(0);
17 // Last date that can be represented (far in the future)
18 const QDateTime TransactionFilterProxy::MAX_DATE = QDateTime::fromTime_t(0xFFFFFFFF);
19 
21  QSortFilterProxyModel(parent),
22  dateFrom(MIN_DATE),
23  dateTo(MAX_DATE),
24  addrPrefix(),
25  assetNamePrefix(),
26  typeFilter(ALL_TYPES),
27  watchOnlyFilter(WatchOnlyFilter_All),
28  minAmount(0),
29  limitRows(-1),
30  showInactive(true)
31 {
32 }
33 
34 bool TransactionFilterProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
35 {
36  QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
37 
38  int type = index.data(TransactionTableModel::TypeRole).toInt();
39  QDateTime datetime = index.data(TransactionTableModel::DateRole).toDateTime();
40  bool involvesWatchAddress = index.data(TransactionTableModel::WatchonlyRole).toBool();
41  QString address = index.data(TransactionTableModel::AddressRole).toString();
42  QString label = index.data(TransactionTableModel::LabelRole).toString();
43  qint64 amount = llabs(index.data(TransactionTableModel::AmountRole).toLongLong());
44  int status = index.data(TransactionTableModel::StatusRole).toInt();
45  QString assetName = index.data(TransactionTableModel::AssetNameRole).toString();
46 
48  return false;
49  if(!(TYPE(type) & typeFilter))
50  return false;
51  if (involvesWatchAddress && watchOnlyFilter == WatchOnlyFilter_No)
52  return false;
53  if (!involvesWatchAddress && watchOnlyFilter == WatchOnlyFilter_Yes)
54  return false;
55  if(datetime < dateFrom || datetime > dateTo)
56  return false;
57  if (!address.contains(addrPrefix, Qt::CaseInsensitive) && !label.contains(addrPrefix, Qt::CaseInsensitive))
58  return false;
59  if(amount < minAmount)
60  return false;
61  if(!assetName.contains(assetNamePrefix, Qt::CaseInsensitive))
62  return false;
63 
64  return true;
65 }
66 
67 void TransactionFilterProxy::setDateRange(const QDateTime &from, const QDateTime &to)
68 {
69  this->dateFrom = from;
70  this->dateTo = to;
71  invalidateFilter();
72 }
73 
74 void TransactionFilterProxy::setAddressPrefix(const QString &_addrPrefix)
75 {
76  this->addrPrefix = _addrPrefix;
77  invalidateFilter();
78 }
79 
81 {
82  this->typeFilter = modes;
83  invalidateFilter();
84 }
85 
87 {
88  this->minAmount = minimum;
89  invalidateFilter();
90 }
91 
92 void TransactionFilterProxy::setAssetNamePrefix(const QString &_assetNamePrefix)
93 {
94  this->assetNamePrefix = _assetNamePrefix;
95  invalidateFilter();
96 }
97 
99 {
100  this->watchOnlyFilter = filter;
101  invalidateFilter();
102 }
103 
105 {
106  this->limitRows = limit;
107 }
108 
110 {
111  this->showInactive = _showInactive;
112  invalidateFilter();
113 }
114 
115 int TransactionFilterProxy::rowCount(const QModelIndex &parent) const
116 {
117  if(limitRows != -1)
118  {
119  return std::min(QSortFilterProxyModel::rowCount(parent), limitRows);
120  }
121  else
122  {
123  return QSortFilterProxyModel::rowCount(parent);
124  }
125 }
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)
void setAddressPrefix(const QString &addrPrefix)
static quint32 TYPE(int type)
int64_t CAmount
Amount in corbies (Can be negative)
Definition: amount.h:13
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.
void setAssetNamePrefix(const QString &assetNamePrefix)
Conflicts with other transaction or mempool.
Label of address related to transaction.