From 37a3daf2dd51330a9dc0a26f1b923698546373ed Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Tue, 13 Aug 2019 20:23:54 +0200 Subject: Mobile: decouple full text search from DiveObjectHelper 1) The full text search was looping over the DiveListModel when it could simply loop over the core model. Do that instead. 2) Don't generate a DiveObjectHelper to do a full text search. Currently this is harmless as the DiveObjectHelper is only a disguised "dive *". But from a conceptual point of view, it represents the full representation of a dive and we don't want to generate that in a tight loop. This will help in 1) Making the DiveObjectHelper a non-reference object. 2) Moving fulltext search to the core and thus making it available to desktop and more performant. Signed-off-by: Berthold Stoeger --- qt-models/divelistmodel.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'qt-models') diff --git a/qt-models/divelistmodel.cpp b/qt-models/divelistmodel.cpp index 72ce90049..c1b8bea83 100644 --- a/qt-models/divelistmodel.cpp +++ b/qt-models/divelistmodel.cpp @@ -20,19 +20,17 @@ void DiveListSortModel::updateFilterState() bool includeNotes = qPrefGeneral::filterFullTextNotes(); Qt::CaseSensitivity cs = qPrefGeneral::filterCaseSensitive() ? Qt::CaseSensitive : Qt::CaseInsensitive; - // get the underlying model and re-calculate the filter value for each dive - DiveListModel *mySourceModel = qobject_cast(sourceModel()); - for (int i = 0; i < mySourceModel->rowCount(); i++) { - DiveObjectHelper *d = mySourceModel->at(i); - QString fullText = includeNotes? d->fullText() : d->fullTextNoNotes(); - d->getDive()->hidden_by_filter = !fullText.contains(filterString, cs); - } + int i; + struct dive *d; + for_each_dive(i, d) + d->hidden_by_filter = !diveContainsText(d, filterString, cs, includeNotes); } void DiveListSortModel::setSourceModel(QAbstractItemModel *sourceModel) { QSortFilterProxyModel::setSourceModel(sourceModel); } + void DiveListSortModel::setFilter(QString f) { filterString = f; -- cgit v1.2.3-70-g09d2