Feathercoin  0.5.0
P2P Digital Currency
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
transactionfilterproxy.cpp
Go to the documentation of this file.
2 
4 
5 #include <QDateTime>
6 
7 #include <cstdlib>
8 
9 // Earliest date that can be represented (far in the past)
10 const QDateTime TransactionFilterProxy::MIN_DATE = QDateTime::fromTime_t(0);
11 // Last date that can be represented (far in the future)
12 const QDateTime TransactionFilterProxy::MAX_DATE = QDateTime::fromTime_t(0xFFFFFFFF);
13 
15  QSortFilterProxyModel(parent),
16  dateFrom(MIN_DATE),
17  dateTo(MAX_DATE),
18  addrPrefix(),
19  typeFilter(ALL_TYPES),
20  minAmount(0),
21  limitRows(-1)
22 {
23 }
24 
25 bool TransactionFilterProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
26 {
27  QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
28 
29  int type = index.data(TransactionTableModel::TypeRole).toInt();
30  QDateTime datetime = index.data(TransactionTableModel::DateRole).toDateTime();
31  QString address = index.data(TransactionTableModel::AddressRole).toString();
32  QString label = index.data(TransactionTableModel::LabelRole).toString();
33  qint64 amount = llabs(index.data(TransactionTableModel::AmountRole).toLongLong());
34 
35  if(!(TYPE(type) & typeFilter))
36  return false;
37  if(datetime < dateFrom || datetime > dateTo)
38  return false;
39  if (!address.contains(addrPrefix, Qt::CaseInsensitive) && !label.contains(addrPrefix, Qt::CaseInsensitive))
40  return false;
41  if(amount < minAmount)
42  return false;
43 
44  return true;
45 }
46 
47 void TransactionFilterProxy::setDateRange(const QDateTime &from, const QDateTime &to)
48 {
49  this->dateFrom = from;
50  this->dateTo = to;
51  invalidateFilter();
52 }
53 
54 void TransactionFilterProxy::setAddressPrefix(const QString &addrPrefix)
55 {
56  this->addrPrefix = addrPrefix;
57  invalidateFilter();
58 }
59 
61 {
62  this->typeFilter = modes;
63  invalidateFilter();
64 }
65 
67 {
68  this->minAmount = minimum;
69  invalidateFilter();
70 }
71 
73 {
74  this->limitRows = limit;
75 }
76 
77 int TransactionFilterProxy::rowCount(const QModelIndex &parent) const
78 {
79  if(limitRows != -1)
80  {
81  return std::min(QSortFilterProxyModel::rowCount(parent), limitRows);
82  }
83  else
84  {
85  return QSortFilterProxyModel::rowCount(parent);
86  }
87 }
void setTypeFilter(quint32 modes)
TransactionFilterProxy(QObject *parent=0)
void setAddressPrefix(const QString &addrPrefix)
static quint32 TYPE(int type)
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)
void setMinAmount(qint64 minimum)
Date and time this transaction was created.
void setLimit(int limit)
Set maximum number of rows returned, -1 if unlimited.
int rowCount(const QModelIndex &parent=QModelIndex()) const
Label of address related to transaction.
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const