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.
68 lines
2.0 KiB
68 lines
2.0 KiB
14 years ago
|
#include "transactionfilterproxy.h"
|
||
|
#include "transactiontablemodel.h"
|
||
|
|
||
|
#include <QDateTime>
|
||
|
#include <QDebug>
|
||
|
|
||
|
// 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),
|
||
|
addrPrefix(),
|
||
|
typeFilter(ALL_TYPES),
|
||
|
minAmount(0)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
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();
|
||
|
QString address = index.data(TransactionTableModel::AddressRole).toString();
|
||
|
QString label = index.data(TransactionTableModel::LabelRole).toString();
|
||
|
qint64 amount = index.data(TransactionTableModel::AbsoluteAmountRole).toLongLong();
|
||
|
|
||
|
if(!(TYPE(type) & typeFilter))
|
||
|
return false;
|
||
|
if(datetime < dateFrom || datetime > dateTo)
|
||
|
return false;
|
||
|
if(!address.startsWith(addrPrefix) && !label.startsWith(addrPrefix))
|
||
|
return false;
|
||
|
if(amount < minAmount)
|
||
|
return false;
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
void TransactionFilterProxy::setDateRange(const QDateTime &from, const QDateTime &to)
|
||
|
{
|
||
|
this->dateFrom = from;
|
||
|
this->dateTo = to;
|
||
|
invalidateFilter();
|
||
|
}
|
||
|
|
||
|
void TransactionFilterProxy::setAddressPrefix(const QString &addrPrefix)
|
||
|
{
|
||
|
this->addrPrefix = addrPrefix;
|
||
|
invalidateFilter();
|
||
|
}
|
||
|
|
||
|
void TransactionFilterProxy::setTypeFilter(quint32 modes)
|
||
|
{
|
||
|
this->typeFilter = modes;
|
||
|
invalidateFilter();
|
||
|
}
|
||
|
|
||
|
void TransactionFilterProxy::setMinAmount(qint64 minimum)
|
||
|
{
|
||
|
this->minAmount = minimum;
|
||
|
invalidateFilter();
|
||
|
}
|