logos-execution-zone-wallet-ui/src/LEZAccountFilterModel.cpp
2026-02-23 10:36:09 +01:00

39 lines
1.3 KiB
C++

#include "LEZAccountFilterModel.h"
LEZAccountFilterModel::LEZAccountFilterModel(QObject* parent)
: QSortFilterProxyModel(parent)
{
connect(this, &QAbstractItemModel::rowsInserted, this, &LEZAccountFilterModel::countChanged);
connect(this, &QAbstractItemModel::rowsRemoved, this, &LEZAccountFilterModel::countChanged);
connect(this, &QAbstractItemModel::modelReset, this, &LEZAccountFilterModel::countChanged);
connect(this, &QAbstractItemModel::layoutChanged, this, &LEZAccountFilterModel::countChanged);
}
void LEZAccountFilterModel::setFilterByPublic(bool value)
{
if (m_filterByPublic == value)
return;
m_filterByPublic = value;
invalidateFilter();
emit filterByPublicChanged();
emit countChanged();
}
bool LEZAccountFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const
{
if (!sourceModel())
return false;
const QModelIndex idx = sourceModel()->index(sourceRow, 0, sourceParent);
const bool isPublic = sourceModel()->data(idx, LEZWalletAccountModel::IsPublicRole).toBool();
return isPublic == m_filterByPublic;
}
int LEZAccountFilterModel::rowForAddress(const QString& address) const
{
for (int i = 0; i < rowCount(); ++i) {
if (data(index(i, 0), LEZWalletAccountModel::AddressRole).toString() == address)
return i;
}
return -1;
}