Anoncoin  0.9.4
P2P Digital Currency
transactionfilterproxy.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2013 The Bitcoin developers
2 // Copyright (c) 2013-2014 The Anoncoin Core developers
3 // Distributed under the MIT/X11 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  typeFilter(ALL_TYPES),
26  watchOnlyFilter(WatchOnlyFilter_All),
27  minAmount(0),
28  limitRows(-1),
29  showInactive(true)
30 {
31 }
32 
33 bool TransactionFilterProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
34 {
35  QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
36 
37  int type = index.data(TransactionTableModel::TypeRole).toInt();
38  QDateTime datetime = index.data(TransactionTableModel::DateRole).toDateTime();
39  bool involvesWatchAddress = index.data(TransactionTableModel::WatchonlyRole).toBool();
40  QString address = index.data(TransactionTableModel::AddressRole).toString();
41  QString label = index.data(TransactionTableModel::LabelRole).toString();
42  qint64 amount = llabs(index.data(TransactionTableModel::AmountRole).toLongLong());
43  int status = index.data(TransactionTableModel::StatusRole).toInt();
44 
46  return false;
47  if(!(TYPE(type) & typeFilter))
48  return false;
49  if (involvesWatchAddress && watchOnlyFilter == WatchOnlyFilter_No)
50  return false;
51  if (!involvesWatchAddress && watchOnlyFilter == WatchOnlyFilter_Yes)
52  return false;
53  if(datetime < dateFrom || datetime > dateTo)
54  return false;
55  if (!address.contains(addrPrefix, Qt::CaseInsensitive) && !label.contains(addrPrefix, Qt::CaseInsensitive))
56  return false;
57  if(amount < minAmount)
58  return false;
59 
60  return true;
61 }
62 
63 void TransactionFilterProxy::setDateRange(const QDateTime &from, const QDateTime &to)
64 {
65  this->dateFrom = from;
66  this->dateTo = to;
67  invalidateFilter();
68 }
69 
70 void TransactionFilterProxy::setAddressPrefix(const QString &addrPrefix)
71 {
72  this->addrPrefix = addrPrefix;
73  invalidateFilter();
74 }
75 
77 {
78  this->typeFilter = modes;
79  invalidateFilter();
80 }
81 
83 {
84  this->minAmount = minimum;
85  invalidateFilter();
86 }
87 
89 {
90  this->watchOnlyFilter = filter;
91  invalidateFilter();
92 }
93 
95 {
96  this->limitRows = limit;
97 }
98 
100 {
101  this->showInactive = showInactive;
102  invalidateFilter();
103 }
104 
105 int TransactionFilterProxy::rowCount(const QModelIndex &parent) const
106 {
107  if(limitRows != -1)
108  {
109  return std::min(QSortFilterProxyModel::rowCount(parent), limitRows);
110  }
111  else
112  {
113  return QSortFilterProxyModel::rowCount(parent);
114  }
115 }
Transaction status (TransactionRecord::Status)
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 setWatchOnlyFilter(WatchOnlyFilter filter)
void setLimit(int limit)
Set maximum number of rows returned, -1 if unlimited.
void setShowInactive(bool showInactive)
Set whether to show conflicted transactions.
int rowCount(const QModelIndex &parent=QModelIndex()) const
Conflicts with other transaction or mempool.
Label of address related to transaction.
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const