diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-08-13 21:11:08 +0200 |
---|---|---|
committer | bstoeger <32835590+bstoeger@users.noreply.github.com> | 2019-09-14 13:20:59 +0200 |
commit | 62f1a92068a3322c306f88344bd02836abbade9a (patch) | |
tree | bd98f3c36416fe14252dec6a1734755971d06cda | |
parent | ca939300e203c7cad5763e5d58de40e9afde063a (diff) | |
download | subsurface-62f1a92068a3322c306f88344bd02836abbade9a.tar.gz |
Mobile: provide direct access to dives in DiveListModel
Accesses were via DiveObjectHelpers. Provide a direct access to
struct dive *. Use this for the filter - there is no point in
mass generating DiveHelperObjects in the filter code.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r-- | qt-models/divelistmodel.cpp | 19 | ||||
-rw-r--r-- | qt-models/divelistmodel.h | 1 |
2 files changed, 14 insertions, 6 deletions
diff --git a/qt-models/divelistmodel.cpp b/qt-models/divelistmodel.cpp index e24ba08e8..8143dd550 100644 --- a/qt-models/divelistmodel.cpp +++ b/qt-models/divelistmodel.cpp @@ -51,8 +51,8 @@ void DiveListSortModel::resetFilter() bool DiveListSortModel::filterAcceptsRow(int source_row, const QModelIndex &) const { DiveListModel *mySourceModel = qobject_cast<DiveListModel *>(sourceModel()); - DiveObjectHelper d = mySourceModel->at(source_row); - return d && !d.getDive()->hidden_by_filter; + const dive *d = mySourceModel->getDive(source_row); + return d && !d->hidden_by_filter; } int DiveListSortModel::shown() @@ -262,11 +262,18 @@ DiveListModel *DiveListModel::instance() return m_instance; } -DiveObjectHelper DiveListModel::at(int i) +struct dive *DiveListModel::getDive(int i) { if (i < 0 || i >= dive_table.nr) { - qWarning("DiveListModel::at(): accessing invalid dive with id %d", i); - return DiveObjectHelper(); // Returns an invalid DiveObjectHelper that will crash on access. + qWarning("DiveListModel::getDive(): accessing invalid dive with id %d", i); + return nullptr; } - return DiveObjectHelper(dive_table.dives[i]); + return dive_table.dives[i]; +} + +DiveObjectHelper DiveListModel::at(int i) +{ + // For an invalid id, returns an invalid DiveObjectHelper that will crash on access. + dive *d = getDive(i); + return d ? DiveObjectHelper(d) : DiveObjectHelper(); } diff --git a/qt-models/divelistmodel.h b/qt-models/divelistmodel.h index cb7c902b3..193d728ea 100644 --- a/qt-models/divelistmodel.h +++ b/qt-models/divelistmodel.h @@ -55,6 +55,7 @@ public: void removeDiveById(int id); void updateDive(int i, dive *d); void reload(); + struct dive *getDive(int i); int rowCount(const QModelIndex &parent = QModelIndex()) const; int getDiveIdx(int id) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; |