You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

transactionfilterproxy.cpp 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // Copyright (c) 2011-2016 The Starwels developers
  2. // Distributed under the MIT software license, see the accompanying
  3. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  4. #include "transactionfilterproxy.h"
  5. #include "transactiontablemodel.h"
  6. #include "transactionrecord.h"
  7. #include <cstdlib>
  8. #include <QDateTime>
  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. TransactionFilterProxy::TransactionFilterProxy(QObject *parent) :
  14. QSortFilterProxyModel(parent),
  15. dateFrom(MIN_DATE),
  16. dateTo(MAX_DATE),
  17. addrPrefix(),
  18. typeFilter(ALL_TYPES),
  19. watchOnlyFilter(WatchOnlyFilter_All),
  20. minAmount(0),
  21. limitRows(-1),
  22. showInactive(true)
  23. {
  24. }
  25. bool TransactionFilterProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
  26. {
  27. QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
  28. int type = index.data(TransactionTableModel::TypeRole).toInt();
  29. QDateTime datetime = index.data(TransactionTableModel::DateRole).toDateTime();
  30. bool involvesWatchAddress = index.data(TransactionTableModel::WatchonlyRole).toBool();
  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. int status = index.data(TransactionTableModel::StatusRole).toInt();
  35. if(!showInactive && status == TransactionStatus::Conflicted)
  36. return false;
  37. if(!(TYPE(type) & typeFilter))
  38. return false;
  39. if (involvesWatchAddress && watchOnlyFilter == WatchOnlyFilter_No)
  40. return false;
  41. if (!involvesWatchAddress && watchOnlyFilter == WatchOnlyFilter_Yes)
  42. return false;
  43. if(datetime < dateFrom || datetime > dateTo)
  44. return false;
  45. if (!address.contains(addrPrefix, Qt::CaseInsensitive) && !label.contains(addrPrefix, Qt::CaseInsensitive))
  46. return false;
  47. if(amount < minAmount)
  48. return false;
  49. return true;
  50. }
  51. void TransactionFilterProxy::setDateRange(const QDateTime &from, const QDateTime &to)
  52. {
  53. this->dateFrom = from;
  54. this->dateTo = to;
  55. invalidateFilter();
  56. }
  57. void TransactionFilterProxy::setAddressPrefix(const QString &_addrPrefix)
  58. {
  59. this->addrPrefix = _addrPrefix;
  60. invalidateFilter();
  61. }
  62. void TransactionFilterProxy::setTypeFilter(quint32 modes)
  63. {
  64. this->typeFilter = modes;
  65. invalidateFilter();
  66. }
  67. void TransactionFilterProxy::setMinAmount(const CAmount& minimum)
  68. {
  69. this->minAmount = minimum;
  70. invalidateFilter();
  71. }
  72. void TransactionFilterProxy::setWatchOnlyFilter(WatchOnlyFilter filter)
  73. {
  74. this->watchOnlyFilter = filter;
  75. invalidateFilter();
  76. }
  77. void TransactionFilterProxy::setLimit(int limit)
  78. {
  79. this->limitRows = limit;
  80. }
  81. void TransactionFilterProxy::setShowInactive(bool _showInactive)
  82. {
  83. this->showInactive = _showInactive;
  84. invalidateFilter();
  85. }
  86. int TransactionFilterProxy::rowCount(const QModelIndex &parent) const
  87. {
  88. if(limitRows != -1)
  89. {
  90. return std::min(QSortFilterProxyModel::rowCount(parent), limitRows);
  91. }
  92. else
  93. {
  94. return QSortFilterProxyModel::rowCount(parent);
  95. }
  96. }