mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 15:19:07 +01:00
e15e8cbadaqt: Modernize custom filtering (Hennadii Stepanov) Pull request description: In [`QSortFilterProxyModel::invalidateFilter()`](https://doc.qt.io/qt-6/qsortfilterproxymodel.html#invalidateFilter) is scheduled for deprecation in Qt 6.13. and emits warnings in Qt 6.10 [`QSortFilterProxyModel::beginFilterChange()`](https://doc.qt.io/qt-6/qsortfilterproxymodel.html#beginFilterChange) was introduced in Qt 6.9. [`QSortFilterProxyModel::endFilterChange()`](https://doc.qt.io/qt-6/qsortfilterproxymodel.html#endFilterChange) was introduced in Qt 6.10. Fixes https://github.com/bitcoin/bitcoin/issues/33571. <img width="724" height="509" alt="image" src="https://github.com/user-attachments/assets/877740c4-7fdf-4478-963c-c639f0b80ad9" /> ACKs for top commit: maflcko: re-review ACKe15e8cbada🌿 pablomartin4btc: re-ACKe15e8cbadaTree-SHA512: d31829f33292b3f9cdfb025d7b0db5fe50033752f58dbb634384ddaea0cac6f304dba7f2c8e706d1bc8bef15a4cb9162defdb7e7fee3433cd832ccc4ada737bb
128 lines
3.4 KiB
C++
128 lines
3.4 KiB
C++
// Copyright (c) 2011-2021 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#include <qt/transactionfilterproxy.h>
|
|
|
|
#include <qt/transactiontablemodel.h>
|
|
#include <qt/transactionrecord.h>
|
|
|
|
#include <algorithm>
|
|
#include <cstdlib>
|
|
#include <optional>
|
|
|
|
TransactionFilterProxy::TransactionFilterProxy(QObject* parent)
|
|
: QSortFilterProxyModel(parent)
|
|
{
|
|
}
|
|
|
|
bool TransactionFilterProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
|
{
|
|
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
|
|
|
|
int status = index.data(TransactionTableModel::StatusRole).toInt();
|
|
if (!showInactive && status == TransactionStatus::Conflicted)
|
|
return false;
|
|
|
|
int type = index.data(TransactionTableModel::TypeRole).toInt();
|
|
if (!(TYPE(type) & typeFilter))
|
|
return false;
|
|
|
|
QDateTime datetime = index.data(TransactionTableModel::DateRole).toDateTime();
|
|
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();
|
|
QString txid = index.data(TransactionTableModel::TxHashRole).toString();
|
|
if (!address.contains(m_search_string, Qt::CaseInsensitive) &&
|
|
! label.contains(m_search_string, Qt::CaseInsensitive) &&
|
|
! txid.contains(m_search_string, Qt::CaseInsensitive)) {
|
|
return false;
|
|
}
|
|
|
|
qint64 amount = llabs(index.data(TransactionTableModel::AmountRole).toLongLong());
|
|
if (amount < minAmount)
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
void TransactionFilterProxy::setDateRange(const std::optional<QDateTime>& from, const std::optional<QDateTime>& to)
|
|
{
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0)
|
|
beginFilterChange();
|
|
#endif
|
|
|
|
dateFrom = from;
|
|
dateTo = to;
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0)
|
|
endFilterChange(QSortFilterProxyModel::Direction::Rows);
|
|
#else
|
|
invalidateFilter();
|
|
#endif
|
|
}
|
|
|
|
void TransactionFilterProxy::setSearchString(const QString &search_string)
|
|
{
|
|
if (m_search_string == search_string) return;
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0)
|
|
beginFilterChange();
|
|
#endif
|
|
|
|
m_search_string = search_string;
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0)
|
|
endFilterChange(QSortFilterProxyModel::Direction::Rows);
|
|
#else
|
|
invalidateFilter();
|
|
#endif
|
|
}
|
|
|
|
void TransactionFilterProxy::setTypeFilter(quint32 modes)
|
|
{
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0)
|
|
beginFilterChange();
|
|
#endif
|
|
|
|
this->typeFilter = modes;
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0)
|
|
endFilterChange(QSortFilterProxyModel::Direction::Rows);
|
|
#else
|
|
invalidateFilter();
|
|
#endif
|
|
}
|
|
|
|
void TransactionFilterProxy::setMinAmount(const CAmount& minimum)
|
|
{
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0)
|
|
beginFilterChange();
|
|
#endif
|
|
|
|
this->minAmount = minimum;
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0)
|
|
endFilterChange(QSortFilterProxyModel::Direction::Rows);
|
|
#else
|
|
invalidateFilter();
|
|
#endif
|
|
}
|
|
|
|
void TransactionFilterProxy::setShowInactive(bool _showInactive)
|
|
{
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0)
|
|
beginFilterChange();
|
|
#endif
|
|
|
|
this->showInactive = _showInactive;
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0)
|
|
endFilterChange(QSortFilterProxyModel::Direction::Rows);
|
|
#else
|
|
invalidateFilter();
|
|
#endif
|
|
}
|