-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilterproxymodel.cpp
More file actions
37 lines (30 loc) · 989 Bytes
/
filterproxymodel.cpp
File metadata and controls
37 lines (30 loc) · 989 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "filterproxymodel.h"
#include <algorithm>
#include <QDebug>
FilterProxyModel::FilterProxyModel(QObject *parent)
: QSortFilterProxyModel(parent)
{
m_filter = "";
}
void FilterProxyModel::setFilter(QString filter)
{
m_filter = filter;
invalidateFilter();
}
bool FilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex&) const
{
if(m_filter.isEmpty()) return true;
QModelIndex firstColumn = sourceModel()->index(sourceRow, 0);
QModelIndex secondColumn = sourceModel()->index(sourceRow, 1);
QString software = firstColumn.data().toString();
QString selected = secondColumn.data().toString();
QStringList options = secondColumn.data(Qt::UserRole).toStringList();
if(software.contains(m_filter)) return true;
if(selected.contains(m_filter)) return true;
if(std::any_of(options.begin(), options.end(), [this](QString a) {
return a.contains(m_filter);
})) {
return true;
}
return false;
}