Mobile/filtering: first attempt to filter on dive site

[Dirk Hohndel: this is the starting point of my following commits, I decided to
	       leave it in place to give Jan credit for the work he did on
               figuring out some of the plumbing needed to get things to work]

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Jan Mulder 2018-02-04 16:46:03 +01:00 committed by Dirk Hohndel
parent f1bb2c8478
commit 0bc0b6bfe8
4 changed files with 52 additions and 1 deletions

View file

@ -8,6 +8,17 @@ DiveListSortModel::DiveListSortModel(QObject *parent) : QSortFilterProxyModel(pa
}
void DiveListSortModel::setFilter(QString f)
{
setFilterRole(DiveListModel::DiveSiteRole);
setFilterRegExp(f);
}
void DiveListSortModel::resetFilter()
{
setFilterRegExp("");
}
int DiveListSortModel::getDiveId(int idx)
{
DiveListModel *mySourceModel = qobject_cast<DiveListModel *>(sourceModel());
@ -151,6 +162,7 @@ QVariant DiveListModel::data(const QModelIndex &index, int role) const
switch(role) {
case DiveRole: return QVariant::fromValue<QObject*>(curr_dive);
case DiveDateRole: return (qlonglong)curr_dive->timestamp();
case DiveSiteRole: return curr_dive->location();
}
return QVariant();
@ -161,6 +173,7 @@ QHash<int, QByteArray> DiveListModel::roleNames() const
QHash<int, QByteArray> roles;
roles[DiveRole] = "dive";
roles[DiveDateRole] = "date";
roles[DiveSiteRole] = "site";
return roles;
}