-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActionsFilterModel.cpp
More file actions
53 lines (40 loc) · 1.24 KB
/
ActionsFilterModel.cpp
File metadata and controls
53 lines (40 loc) · 1.24 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "ActionsFilterModel.h"
ActionsFilterModel::ActionsFilterModel(QObject* parent) :
QSortFilterProxyModel(parent)
{
}
void ActionsFilterModel::setSearchRoles(QVector<int> roles)
{
searchRoles = std::move(roles);
}
bool ActionsFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const
{
const QModelIndex idx = sourceModel()->index(sourceRow, 0, sourceParent);
if (!idx.isValid())
return false;
if (rowMatches(idx))
return true;
const auto childCount = sourceModel()->rowCount(idx);
for (int i = 0; i < childCount; ++i)
{
if (filterAcceptsRow(i, idx))
return true;
}
return false;
}
bool ActionsFilterModel::rowMatches(const QModelIndex& idx) const
{
const auto re = filterRegularExpression();
if (!re.isValid() || re.pattern().isEmpty())
return true;
// Always include DisplayRole at minimum
const QString display = sourceModel()->data(idx, Qt::DisplayRole).toString();
if (display.contains(re))
return true;
for (int r : searchRoles) {
const auto string = sourceModel()->data(idx, r).toString();
if (!string.isEmpty() && string.contains(re))
return true;
}
return false;
}