-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtraktpeoplefiltermodel.cpp
40 lines (32 loc) · 1 KB
/
traktpeoplefiltermodel.cpp
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
#include "traktpeoplefiltermodel.h"
#include "traktpeoplemodel.h"
TraktPeopleFilterModel::TraktPeopleFilterModel(QObject *parent) :
QSortFilterProxyModel(parent)
{
}
void TraktPeopleFilterModel::setTypeFilter(const QString &type)
{
m_typeFilter = type;
}
bool TraktPeopleFilterModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
Q_UNUSED(source_parent)
TraktPeopleModel *model = qobject_cast<TraktPeopleModel*>(sourceModel());
if (!model) {
return true;
}
TraktPerson *person = model->at(source_row);
if (!person) {
return true;
}
return m_typeFilter.isEmpty() || person->type() == m_typeFilter || (m_typeFilter == "crew" && person->type() != "cast");
}
TraktPerson *TraktPeopleFilterModel::at(int i) const
{
TraktPeopleModel *model = qobject_cast<TraktPeopleModel*>(sourceModel());
if (!model) {
return 0;
}
int sourceIndex = mapToSource(index(i, 0, QModelIndex())).row();
return model->at(sourceIndex);
}