2018-01-02 18:12:05 +01:00
|
|
|
// Copyright (c) 2011-2017 The Bitcoin Core developers
|
2014-12-13 05:09:33 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2013-11-04 16:20:43 +01:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2017-11-10 01:57:53 +01:00
|
|
|
#include <qt/transactionfilterproxy.h>
|
2013-01-23 21:51:02 +01:00
|
|
|
|
2017-11-10 01:57:53 +01:00
|
|
|
#include <qt/transactiontablemodel.h>
|
|
|
|
#include <qt/transactionrecord.h>
|
2011-06-28 21:41:56 +02:00
|
|
|
|
2011-08-07 16:09:49 +02:00
|
|
|
#include <cstdlib>
|
2011-06-28 21:41:56 +02:00
|
|
|
|
|
|
|
// Earliest date that can be represented (far in the past)
|
|
|
|
const QDateTime TransactionFilterProxy::MIN_DATE = QDateTime::fromTime_t(0);
|
|
|
|
// Last date that can be represented (far in the future)
|
|
|
|
const QDateTime TransactionFilterProxy::MAX_DATE = QDateTime::fromTime_t(0xFFFFFFFF);
|
|
|
|
|
|
|
|
TransactionFilterProxy::TransactionFilterProxy(QObject *parent) :
|
|
|
|
QSortFilterProxyModel(parent),
|
|
|
|
dateFrom(MIN_DATE),
|
|
|
|
dateTo(MAX_DATE),
|
2017-09-25 06:13:27 +02:00
|
|
|
m_search_string(),
|
2011-06-28 21:41:56 +02:00
|
|
|
typeFilter(ALL_TYPES),
|
2014-08-10 02:26:04 +02:00
|
|
|
watchOnlyFilter(WatchOnlyFilter_All),
|
2011-08-03 20:52:18 +02:00
|
|
|
minAmount(0),
|
2014-02-14 07:59:07 +01:00
|
|
|
limitRows(-1),
|
2014-07-17 14:09:46 +02:00
|
|
|
showInactive(true)
|
2011-06-28 21:41:56 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TransactionFilterProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
|
|
|
{
|
|
|
|
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
|
|
|
|
|
|
|
|
int type = index.data(TransactionTableModel::TypeRole).toInt();
|
|
|
|
QDateTime datetime = index.data(TransactionTableModel::DateRole).toDateTime();
|
2014-08-10 02:26:04 +02:00
|
|
|
bool involvesWatchAddress = index.data(TransactionTableModel::WatchonlyRole).toBool();
|
2011-06-28 21:41:56 +02:00
|
|
|
QString address = index.data(TransactionTableModel::AddressRole).toString();
|
|
|
|
QString label = index.data(TransactionTableModel::LabelRole).toString();
|
2017-09-25 06:18:35 +02:00
|
|
|
QString txid = index.data(TransactionTableModel::TxIDRole).toString();
|
2011-08-05 15:35:52 +02:00
|
|
|
qint64 amount = llabs(index.data(TransactionTableModel::AmountRole).toLongLong());
|
2014-02-14 07:59:07 +01:00
|
|
|
int status = index.data(TransactionTableModel::StatusRole).toInt();
|
2011-06-28 21:41:56 +02:00
|
|
|
|
2014-07-17 14:09:46 +02:00
|
|
|
if(!showInactive && status == TransactionStatus::Conflicted)
|
2014-02-14 07:59:07 +01:00
|
|
|
return false;
|
2011-06-28 21:41:56 +02:00
|
|
|
if(!(TYPE(type) & typeFilter))
|
|
|
|
return false;
|
2014-08-10 02:26:04 +02:00
|
|
|
if (involvesWatchAddress && watchOnlyFilter == WatchOnlyFilter_No)
|
|
|
|
return false;
|
|
|
|
if (!involvesWatchAddress && watchOnlyFilter == WatchOnlyFilter_Yes)
|
|
|
|
return false;
|
2011-06-28 21:41:56 +02:00
|
|
|
if(datetime < dateFrom || datetime > dateTo)
|
|
|
|
return false;
|
2017-09-25 06:18:35 +02:00
|
|
|
if (!address.contains(m_search_string, Qt::CaseInsensitive) &&
|
|
|
|
! label.contains(m_search_string, Qt::CaseInsensitive) &&
|
|
|
|
! txid.contains(m_search_string, Qt::CaseInsensitive)) {
|
2011-06-28 21:41:56 +02:00
|
|
|
return false;
|
2017-09-25 06:18:35 +02:00
|
|
|
}
|
2011-06-28 21:41:56 +02:00
|
|
|
if(amount < minAmount)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransactionFilterProxy::setDateRange(const QDateTime &from, const QDateTime &to)
|
|
|
|
{
|
|
|
|
this->dateFrom = from;
|
|
|
|
this->dateTo = to;
|
|
|
|
invalidateFilter();
|
|
|
|
}
|
|
|
|
|
2017-09-25 06:13:27 +02:00
|
|
|
void TransactionFilterProxy::setSearchString(const QString &search_string)
|
2011-06-28 21:41:56 +02:00
|
|
|
{
|
2017-09-26 01:23:46 +02:00
|
|
|
if (m_search_string == search_string) return;
|
2017-09-25 06:13:27 +02:00
|
|
|
m_search_string = search_string;
|
2011-06-28 21:41:56 +02:00
|
|
|
invalidateFilter();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransactionFilterProxy::setTypeFilter(quint32 modes)
|
|
|
|
{
|
|
|
|
this->typeFilter = modes;
|
|
|
|
invalidateFilter();
|
|
|
|
}
|
|
|
|
|
2014-04-23 00:46:19 +02:00
|
|
|
void TransactionFilterProxy::setMinAmount(const CAmount& minimum)
|
2011-06-28 21:41:56 +02:00
|
|
|
{
|
|
|
|
this->minAmount = minimum;
|
|
|
|
invalidateFilter();
|
|
|
|
}
|
2011-08-03 20:52:18 +02:00
|
|
|
|
2014-08-10 02:26:04 +02:00
|
|
|
void TransactionFilterProxy::setWatchOnlyFilter(WatchOnlyFilter filter)
|
|
|
|
{
|
|
|
|
this->watchOnlyFilter = filter;
|
|
|
|
invalidateFilter();
|
|
|
|
}
|
|
|
|
|
2011-08-03 20:52:18 +02:00
|
|
|
void TransactionFilterProxy::setLimit(int limit)
|
|
|
|
{
|
|
|
|
this->limitRows = limit;
|
|
|
|
}
|
|
|
|
|
2016-09-09 13:43:29 +02:00
|
|
|
void TransactionFilterProxy::setShowInactive(bool _showInactive)
|
2014-02-14 07:59:07 +01:00
|
|
|
{
|
2016-09-09 13:43:29 +02:00
|
|
|
this->showInactive = _showInactive;
|
2014-02-14 07:59:07 +01:00
|
|
|
invalidateFilter();
|
|
|
|
}
|
|
|
|
|
2011-08-03 20:52:18 +02:00
|
|
|
int TransactionFilterProxy::rowCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
if(limitRows != -1)
|
|
|
|
{
|
|
|
|
return std::min(QSortFilterProxyModel::rowCount(parent), limitRows);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return QSortFilterProxyModel::rowCount(parent);
|
|
|
|
}
|
|
|
|
}
|