diff options
Diffstat (limited to 'qt-models')
-rw-r--r-- | qt-models/divelistmodel.cpp | 13 | ||||
-rw-r--r-- | qt-models/divelistmodel.h | 5 |
2 files changed, 17 insertions, 1 deletions
diff --git a/qt-models/divelistmodel.cpp b/qt-models/divelistmodel.cpp index 8dc119ad8..76c0db7e3 100644 --- a/qt-models/divelistmodel.cpp +++ b/qt-models/divelistmodel.cpp @@ -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; } diff --git a/qt-models/divelistmodel.h b/qt-models/divelistmodel.h index d7988f2d9..2773ce33d 100644 --- a/qt-models/divelistmodel.h +++ b/qt-models/divelistmodel.h @@ -17,6 +17,8 @@ public: public slots: int getDiveId(int idx); int getIdxForId(int id); + void setFilter(QString f); + void resetFilter(); }; class DiveListModel : public QAbstractListModel @@ -26,7 +28,8 @@ public: enum DiveListRoles { DiveRole = Qt::UserRole + 1, - DiveDateRole + DiveDateRole, + DiveSiteRole }; static DiveListModel *instance(); |