parent
e7e6c583b6
commit
612c497608
@ -1,6 +1,66 @@
|
||||
#include "TransactionHistorySortFiltrerModel.h"
|
||||
#include "TransactionHistorySortFilterModel.h"
|
||||
#include "TransactionHistoryModel.h"
|
||||
|
||||
TransactionHistorySortFiltrerModel::TransactionHistorySortFiltrerModel()
|
||||
#include <QDebug>
|
||||
|
||||
TransactionHistorySortFilterModel::TransactionHistorySortFilterModel(QObject *parent)
|
||||
: QSortFilterProxyModel(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QString TransactionHistorySortFilterModel::paymentIdFilter() const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TransactionHistorySortFilterModel::setPaymentIdFilter(const QString &arg)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TransactionHistorySortFilterModel::sort(int column, Qt::SortOrder order)
|
||||
{
|
||||
QSortFilterProxyModel::sort(column, order);
|
||||
}
|
||||
|
||||
bool TransactionHistorySortFilterModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
|
||||
{
|
||||
|
||||
if (source_row < 0 || source_row >= sourceModel()->rowCount()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
|
||||
if (!index.isValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result = true;
|
||||
|
||||
for (int role : m_filterValues.keys()) {
|
||||
if (m_filterValues.contains(role)) {
|
||||
QVariant data = sourceModel()->data(index, role);
|
||||
result = data.toString().contains(m_filterValues.value(role).toString());
|
||||
if (result)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool TransactionHistorySortFilterModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const
|
||||
{
|
||||
return QSortFilterProxyModel::lessThan(source_left, source_right);
|
||||
}
|
||||
|
||||
QVariant TransactionHistorySortFilterModel::filterValue(int role)
|
||||
{
|
||||
return m_filterValues.value(role);
|
||||
}
|
||||
|
||||
void TransactionHistorySortFilterModel::setFilterValue(int role, const QVariant &filterValue)
|
||||
{
|
||||
m_filterValues[role] = filterValue;
|
||||
}
|
||||
|
@ -1,12 +1,34 @@
|
||||
#ifndef TRANSACTIONHISTORYSORTFILTRERMODEL_H
|
||||
#define TRANSACTIONHISTORYSORTFILTRERMODEL_H
|
||||
#ifndef TRANSACTIONHISTORYSORTFILTERMODEL_H
|
||||
#define TRANSACTIONHISTORYSORTFILTERMODEL_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class TransactionHistorySortFiltrerModel : public QSortFilterProxyModel
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QMap>
|
||||
#include <QVariant>
|
||||
|
||||
|
||||
class TransactionHistorySortFilterModel: public QSortFilterProxyModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
TransactionHistorySortFiltrerModel();
|
||||
TransactionHistorySortFilterModel(QObject * parent = nullptr);
|
||||
QString paymentIdFilter() const;
|
||||
void setPaymentIdFilter(const QString &arg);
|
||||
|
||||
|
||||
Q_INVOKABLE void sort(int column, Qt::SortOrder order);
|
||||
protected:
|
||||
// QSortFilterProxyModel overrides
|
||||
virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
|
||||
virtual bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const;
|
||||
|
||||
|
||||
private:
|
||||
QVariant filterValue(int role);
|
||||
void setFilterValue(int role, const QVariant &filterValue);
|
||||
|
||||
private:
|
||||
QMap<int, QVariant> m_filterValues;
|
||||
};
|
||||
|
||||
#endif // TRANSACTIONHISTORYSORTFILTRERMODEL_H
|
||||
#endif // TRANSACTIONHISTORYSORTFILTERMODEL_H
|
||||
|
Reference in new issue