qt: Refactor open date range to use std::optional

This commit is contained in:
João Barbosa
2021-06-03 09:54:25 +01:00
parent a9435e3445
commit 4830f4912a
3 changed files with 19 additions and 25 deletions

View File

@@ -9,15 +9,8 @@
#include <cstdlib>
// 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),
m_search_string(),
typeFilter(ALL_TYPES),
watchOnlyFilter(WatchOnlyFilter_All),
@@ -46,8 +39,8 @@ bool TransactionFilterProxy::filterAcceptsRow(int sourceRow, const QModelIndex &
return false;
QDateTime datetime = index.data(TransactionTableModel::DateRole).toDateTime();
if (datetime < dateFrom || datetime > dateTo)
return false;
if (dateFrom && datetime < *dateFrom) return false;
if (dateTo && datetime > *dateTo) return false;
QString address = index.data(TransactionTableModel::AddressRole).toString();
QString label = index.data(TransactionTableModel::LabelRole).toString();
@@ -65,10 +58,10 @@ bool TransactionFilterProxy::filterAcceptsRow(int sourceRow, const QModelIndex &
return true;
}
void TransactionFilterProxy::setDateRange(const QDateTime &from, const QDateTime &to)
void TransactionFilterProxy::setDateRange(const std::optional<QDateTime>& from, const std::optional<QDateTime>& to)
{
this->dateFrom = from;
this->dateTo = to;
dateFrom = from;
dateTo = to;
invalidateFilter();
}