MySortFilterProxyModel *myProxyModel;
MySortFilterProxyModel
::MySortFilterProxyModel(QObject *parent
){
}
bool MySortFilterProxyModel::filterAcceptsRow(int sourceRow,
{
QModelIndex index1
= sourceModel
()->index
(sourceRow,
1, sourceParent
);
QModelIndex index2
= sourceModel
()->index
(sourceRow,
2, sourceParent
);
QModelIndex index3
= sourceModel
()->index
(sourceRow,
3, sourceParent
);
QModelIndex index4
= sourceModel
()->index
(sourceRow,
4, sourceParent
);
QModelIndex index5
= sourceModel
()->index
(sourceRow,
5, sourceParent
);
return (sourceModel()->data(index1).toString().contains(filterPlayerWhite)
&& sourceModel()->data(index2).toString().contains(filterRankWhite)
&& sourceModel()->data(index3).toString().contains(filterPlayerBlack)
&& sourceModel()->data(index4).toString().contains(filterRankBlack)
&& sourceModel()->data(index5).toString().contains(filterResult));
}
connect(filters
->lineEditPlayerWhite,
SIGNAL(textChanged
(const QString &)),
this, SLOT(doFilter()));
void MainWindow::doFilter()
{
myProxyModel->filterPlayerWhite = lineEditPlayerWhite->text();
// NEED TO UPDATE VIEW NOW
// THESE two lines work, but is it really necessary to setup these connections again. Just to display these filters right now?
myProxyModel->setSourceModel(model);
treeView->setModel(myProxyModel);
}
MySortFilterProxyModel *myProxyModel;
MySortFilterProxyModel::MySortFilterProxyModel(QObject *parent)
: QSortFilterProxyModel(parent)
{
}
bool MySortFilterProxyModel::filterAcceptsRow(int sourceRow,
const QModelIndex &sourceParent) const
{
QModelIndex index1 = sourceModel()->index(sourceRow, 1, sourceParent);
QModelIndex index2 = sourceModel()->index(sourceRow, 2, sourceParent);
QModelIndex index3 = sourceModel()->index(sourceRow, 3, sourceParent);
QModelIndex index4 = sourceModel()->index(sourceRow, 4, sourceParent);
QModelIndex index5 = sourceModel()->index(sourceRow, 5, sourceParent);
return (sourceModel()->data(index1).toString().contains(filterPlayerWhite)
&& sourceModel()->data(index2).toString().contains(filterRankWhite)
&& sourceModel()->data(index3).toString().contains(filterPlayerBlack)
&& sourceModel()->data(index4).toString().contains(filterRankBlack)
&& sourceModel()->data(index5).toString().contains(filterResult));
}
connect(filters->lineEditPlayerWhite, SIGNAL(textChanged(const QString &)),
this, SLOT(doFilter()));
void MainWindow::doFilter()
{
myProxyModel->filterPlayerWhite = lineEditPlayerWhite->text();
// NEED TO UPDATE VIEW NOW
// THESE two lines work, but is it really necessary to setup these connections again. Just to display these filters right now?
myProxyModel->setSourceModel(model);
treeView->setModel(myProxyModel);
}
To copy to clipboard, switch view to plain text mode
Bookmarks