#include "FluTableSortProxyModel.h" #include FluTableSortProxyModel::FluTableSortProxyModel(QSortFilterProxyModel *parent) : QSortFilterProxyModel {parent} { _model = nullptr; connect(this,&FluTableSortProxyModel::modelChanged,this,[=]{ setSourceModel(this->model()); }); } bool FluTableSortProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const{ QJSValue filter = _filter; if(filter.isUndefined()){ return true; } QJSValueList data; data<_comparator = comparator; if(sortOrder()==Qt::AscendingOrder){ sort(column,Qt::DescendingOrder); }else{ sort(column,Qt::AscendingOrder); } } void FluTableSortProxyModel::setFilter(QJSValue filter){ this->_filter = filter; invalidateFilter(); } QVariant FluTableSortProxyModel::getRow(int rowIndex){ QVariant result; QMetaObject::invokeMethod(_model, "getRow",Q_RETURN_ARG(QVariant, result),Q_ARG(int, mapToSource(index(rowIndex,0)).row())); return result; } void FluTableSortProxyModel::setRow(int rowIndex,QVariant val){ QMetaObject::invokeMethod(_model, "setRow",Q_ARG(int, mapToSource(index(rowIndex,0)).row()),Q_ARG(QVariant,val)); } void FluTableSortProxyModel::removeRow(int rowIndex,int rows){ QMetaObject::invokeMethod(_model, "removeRow",Q_ARG(int, mapToSource(index(rowIndex,0)).row()),Q_ARG(int,rows)); }