-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathticketfiltermodel.cpp
More file actions
27 lines (24 loc) · 1.17 KB
/
ticketfiltermodel.cpp
File metadata and controls
27 lines (24 loc) · 1.17 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
#include "ticketfiltermodel.h"
#include "ticketmodel.h"
#include <array>
#include <algorithm>
TicketFilterModel::TicketFilterModel(QObject *parent): QSortFilterProxyModel(parent) {
connect(this, &TicketFilterModel::queryChanged, this, &TicketFilterModel::invalidateFilter);
}
bool TicketFilterModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const {
Q_UNUSED(source_parent)
if (!sourceModel()) {
return false;
}
QStringList queries = m_query.split(" ", Qt::SkipEmptyParts, Qt::CaseInsensitive);
QModelIndex index = sourceModel()->index(source_row, 0);
QString firstName = index.data(TicketModel::FirstNameRole).toString();
QString lastName = index.data(TicketModel::LastNameRole).toString();
QString email = index.data(TicketModel::EmailRole).toString();
QString time = index.data(TicketModel::TimeRole).toString();
QStringList strings = {firstName, lastName, email, time};
return std::all_of(queries.cbegin(), queries.cend(), [strings](const QString &q) {
return std::any_of(strings.cbegin(), strings.cend(), [q](const QString &str) {
return str.contains(q, Qt::CaseInsensitive);
});});
}