LCOV - code coverage report
Current view: top level - src/qt - transactionfilterproxy.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 2 76 2.6 %
Date: 2020-09-26 01:30:44 Functions: 2 13 15.4 %

          Line data    Source code
       1             : // Copyright (c) 2011-2018 The Bitcoin Core developers
       2             : // Distributed under the MIT software license, see the accompanying
       3             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       4             : 
       5             : #include <qt/transactionfilterproxy.h>
       6             : 
       7             : #include <qt/transactiontablemodel.h>
       8             : #include <qt/transactionrecord.h>
       9             : 
      10             : #include <cstdlib>
      11             : 
      12             : // Earliest date that can be represented (far in the past)
      13           1 : const QDateTime TransactionFilterProxy::MIN_DATE = QDateTime::fromTime_t(0);
      14             : // Last date that can be represented (far in the future)
      15           1 : const QDateTime TransactionFilterProxy::MAX_DATE = QDateTime::fromTime_t(0xFFFFFFFF);
      16             : 
      17           0 : TransactionFilterProxy::TransactionFilterProxy(QObject *parent) :
      18           0 :     QSortFilterProxyModel(parent),
      19           0 :     dateFrom(MIN_DATE),
      20           0 :     dateTo(MAX_DATE),
      21           0 :     m_search_string(),
      22           0 :     typeFilter(ALL_TYPES),
      23           0 :     watchOnlyFilter(WatchOnlyFilter_All),
      24           0 :     minAmount(0),
      25           0 :     limitRows(-1),
      26           0 :     showInactive(true)
      27           0 : {
      28           0 : }
      29             : 
      30           0 : bool TransactionFilterProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
      31             : {
      32           0 :     QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
      33             : 
      34           0 :     int status = index.data(TransactionTableModel::StatusRole).toInt();
      35           0 :     if (!showInactive && status == TransactionStatus::Conflicted)
      36           0 :         return false;
      37             : 
      38           0 :     int type = index.data(TransactionTableModel::TypeRole).toInt();
      39           0 :     if (!(TYPE(type) & typeFilter))
      40           0 :         return false;
      41             : 
      42           0 :     bool involvesWatchAddress = index.data(TransactionTableModel::WatchonlyRole).toBool();
      43           0 :     if (involvesWatchAddress && watchOnlyFilter == WatchOnlyFilter_No)
      44           0 :         return false;
      45           0 :     if (!involvesWatchAddress && watchOnlyFilter == WatchOnlyFilter_Yes)
      46           0 :         return false;
      47             : 
      48           0 :     QDateTime datetime = index.data(TransactionTableModel::DateRole).toDateTime();
      49           0 :     if (datetime < dateFrom || datetime > dateTo)
      50           0 :         return false;
      51             : 
      52           0 :     QString address = index.data(TransactionTableModel::AddressRole).toString();
      53           0 :     QString label = index.data(TransactionTableModel::LabelRole).toString();
      54           0 :     QString txid = index.data(TransactionTableModel::TxHashRole).toString();
      55           0 :     if (!address.contains(m_search_string, Qt::CaseInsensitive) &&
      56           0 :         !  label.contains(m_search_string, Qt::CaseInsensitive) &&
      57           0 :         !   txid.contains(m_search_string, Qt::CaseInsensitive)) {
      58           0 :         return false;
      59             :     }
      60             : 
      61           0 :     qint64 amount = llabs(index.data(TransactionTableModel::AmountRole).toLongLong());
      62           0 :     if (amount < minAmount)
      63           0 :         return false;
      64             : 
      65           0 :     return true;
      66           0 : }
      67             : 
      68           0 : void TransactionFilterProxy::setDateRange(const QDateTime &from, const QDateTime &to)
      69             : {
      70           0 :     this->dateFrom = from;
      71           0 :     this->dateTo = to;
      72           0 :     invalidateFilter();
      73           0 : }
      74             : 
      75           0 : void TransactionFilterProxy::setSearchString(const QString &search_string)
      76             : {
      77           0 :     if (m_search_string == search_string) return;
      78           0 :     m_search_string = search_string;
      79           0 :     invalidateFilter();
      80           0 : }
      81             : 
      82           0 : void TransactionFilterProxy::setTypeFilter(quint32 modes)
      83             : {
      84           0 :     this->typeFilter = modes;
      85           0 :     invalidateFilter();
      86           0 : }
      87             : 
      88           0 : void TransactionFilterProxy::setMinAmount(const CAmount& minimum)
      89             : {
      90           0 :     this->minAmount = minimum;
      91           0 :     invalidateFilter();
      92           0 : }
      93             : 
      94           0 : void TransactionFilterProxy::setWatchOnlyFilter(WatchOnlyFilter filter)
      95             : {
      96           0 :     this->watchOnlyFilter = filter;
      97           0 :     invalidateFilter();
      98           0 : }
      99             : 
     100           0 : void TransactionFilterProxy::setLimit(int limit)
     101             : {
     102           0 :     this->limitRows = limit;
     103           0 : }
     104             : 
     105           0 : void TransactionFilterProxy::setShowInactive(bool _showInactive)
     106             : {
     107           0 :     this->showInactive = _showInactive;
     108           0 :     invalidateFilter();
     109           0 : }
     110             : 
     111           0 : int TransactionFilterProxy::rowCount(const QModelIndex &parent) const
     112             : {
     113           0 :     if(limitRows != -1)
     114             :     {
     115           0 :         return std::min(QSortFilterProxyModel::rowCount(parent), limitRows);
     116             :     }
     117             :     else
     118             :     {
     119           0 :         return QSortFilterProxyModel::rowCount(parent);
     120             :     }
     121           0 : }

Generated by: LCOV version 1.15