Changeset View
Changeset View
Standalone View
Standalone View
src/qt/transactionfilterproxy.cpp
Show All 13 Lines | |||||
// Earliest date that can be represented (far in the past) | // Earliest date that can be represented (far in the past) | ||||
const QDateTime TransactionFilterProxy::MIN_DATE = QDateTime::fromTime_t(0); | const QDateTime TransactionFilterProxy::MIN_DATE = QDateTime::fromTime_t(0); | ||||
// Last date that can be represented (far in the future) | // Last date that can be represented (far in the future) | ||||
const QDateTime TransactionFilterProxy::MAX_DATE = | const QDateTime TransactionFilterProxy::MAX_DATE = | ||||
QDateTime::fromTime_t(0xFFFFFFFF); | QDateTime::fromTime_t(0xFFFFFFFF); | ||||
TransactionFilterProxy::TransactionFilterProxy(QObject *parent) | TransactionFilterProxy::TransactionFilterProxy(QObject *parent) | ||||
: QSortFilterProxyModel(parent), dateFrom(MIN_DATE), dateTo(MAX_DATE), | : QSortFilterProxyModel(parent), dateFrom(MIN_DATE), dateTo(MAX_DATE), | ||||
addrPrefix(), typeFilter(ALL_TYPES), watchOnlyFilter(WatchOnlyFilter_All), | m_search_string(), typeFilter(ALL_TYPES), | ||||
minAmount(), limitRows(-1), showInactive(true) {} | watchOnlyFilter(WatchOnlyFilter_All), minAmount(), limitRows(-1), | ||||
showInactive(true) {} | |||||
bool TransactionFilterProxy::filterAcceptsRow( | bool TransactionFilterProxy::filterAcceptsRow( | ||||
int sourceRow, const QModelIndex &sourceParent) const { | int sourceRow, const QModelIndex &sourceParent) const { | ||||
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); | QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); | ||||
int type = index.data(TransactionTableModel::TypeRole).toInt(); | int type = index.data(TransactionTableModel::TypeRole).toInt(); | ||||
QDateTime datetime = | QDateTime datetime = | ||||
index.data(TransactionTableModel::DateRole).toDateTime(); | index.data(TransactionTableModel::DateRole).toDateTime(); | ||||
bool involvesWatchAddress = | bool involvesWatchAddress = | ||||
index.data(TransactionTableModel::WatchonlyRole).toBool(); | index.data(TransactionTableModel::WatchonlyRole).toBool(); | ||||
QString address = index.data(TransactionTableModel::AddressRole).toString(); | QString address = index.data(TransactionTableModel::AddressRole).toString(); | ||||
QString label = index.data(TransactionTableModel::LabelRole).toString(); | QString label = index.data(TransactionTableModel::LabelRole).toString(); | ||||
QString txid = index.data(TransactionTableModel::TxIDRole).toString(); | |||||
Amount amount( | Amount amount( | ||||
int64_t( | int64_t( | ||||
llabs(index.data(TransactionTableModel::AmountRole).toLongLong())) * | llabs(index.data(TransactionTableModel::AmountRole).toLongLong())) * | ||||
SATOSHI); | SATOSHI); | ||||
int status = index.data(TransactionTableModel::StatusRole).toInt(); | int status = index.data(TransactionTableModel::StatusRole).toInt(); | ||||
if (!showInactive && status == TransactionStatus::Conflicted) { | if (!showInactive && status == TransactionStatus::Conflicted) { | ||||
return false; | return false; | ||||
} | } | ||||
if (!(TYPE(type) & typeFilter)) { | if (!(TYPE(type) & typeFilter)) { | ||||
return false; | return false; | ||||
} | } | ||||
if (involvesWatchAddress && watchOnlyFilter == WatchOnlyFilter_No) { | if (involvesWatchAddress && watchOnlyFilter == WatchOnlyFilter_No) { | ||||
return false; | return false; | ||||
} | } | ||||
if (!involvesWatchAddress && watchOnlyFilter == WatchOnlyFilter_Yes) { | if (!involvesWatchAddress && watchOnlyFilter == WatchOnlyFilter_Yes) { | ||||
return false; | return false; | ||||
} | } | ||||
if (datetime < dateFrom || datetime > dateTo) { | if (datetime < dateFrom || datetime > dateTo) { | ||||
return false; | return false; | ||||
} | } | ||||
if (!address.contains(addrPrefix, Qt::CaseInsensitive) && | if (!address.contains(m_search_string, Qt::CaseInsensitive) && | ||||
!label.contains(addrPrefix, Qt::CaseInsensitive)) { | !label.contains(m_search_string, Qt::CaseInsensitive) && | ||||
!txid.contains(m_search_string, Qt::CaseInsensitive)) { | |||||
return false; | return false; | ||||
} | } | ||||
if (amount < minAmount) { | if (amount < minAmount) { | ||||
return false; | return false; | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
void TransactionFilterProxy::setDateRange(const QDateTime &from, | void TransactionFilterProxy::setDateRange(const QDateTime &from, | ||||
const QDateTime &to) { | const QDateTime &to) { | ||||
this->dateFrom = from; | this->dateFrom = from; | ||||
this->dateTo = to; | this->dateTo = to; | ||||
invalidateFilter(); | invalidateFilter(); | ||||
} | } | ||||
void TransactionFilterProxy::setAddressPrefix(const QString &_addrPrefix) { | void TransactionFilterProxy::setSearchString(const QString &search_string) { | ||||
this->addrPrefix = _addrPrefix; | if (m_search_string == search_string) { | ||||
return; | |||||
} | |||||
m_search_string = search_string; | |||||
invalidateFilter(); | invalidateFilter(); | ||||
} | } | ||||
void TransactionFilterProxy::setTypeFilter(quint32 modes) { | void TransactionFilterProxy::setTypeFilter(quint32 modes) { | ||||
this->typeFilter = modes; | this->typeFilter = modes; | ||||
invalidateFilter(); | invalidateFilter(); | ||||
} | } | ||||
Show All 26 Lines |