aboutsummaryrefslogtreecommitdiffstats
path: root/qt-models
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-11-22 23:28:06 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-11-23 13:22:24 -0800
commit1ebf5a99ed934d4cf5af937b638647d5c5c83e6d (patch)
treef8b6bc3098089b1ee8d41905b683565c84772457 /qt-models
parent70897dd1b7d33f3d1f6b47acc587a7f33a176a04 (diff)
downloadsubsurface-1ebf5a99ed934d4cf5af937b638647d5c5c83e6d.tar.gz
Filter: use hidden_by_filter also on mobile
Desktop used the hidden_in_filter flag in struct dive, mobile used its own vector plus a new showndives member in struct dive_trip. Unifiy these to use the same core-facility, viz. hidden_by_filter. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models')
-rw-r--r--qt-models/divelistmodel.cpp51
-rw-r--r--qt-models/divelistmodel.h2
2 files changed, 16 insertions, 37 deletions
diff --git a/qt-models/divelistmodel.cpp b/qt-models/divelistmodel.cpp
index bfed1d0cb..953229c45 100644
--- a/qt-models/divelistmodel.cpp
+++ b/qt-models/divelistmodel.cpp
@@ -12,7 +12,7 @@ DiveListSortModel::DiveListSortModel(QObject *parent) : QSortFilterProxyModel(pa
void DiveListSortModel::updateFilterState()
{
if (filterString.isEmpty()) {
- filteredRows.clear();
+ resetFilter();
return;
}
// store this in local variables to avoid having to call these methods over and over
@@ -21,13 +21,11 @@ void DiveListSortModel::updateFilterState()
// get the underlying model and re-calculate the filter value for each dive
DiveListModel *mySourceModel = qobject_cast<DiveListModel *>(sourceModel());
- filteredRows.clear();
- filteredRows.resize(mySourceModel->rowCount());
for (int i = 0; i < mySourceModel->rowCount(); i++) {
- QString fullText = includeNotes? mySourceModel->at(i)->fullText() : mySourceModel->at(i)->fullTextNoNotes();
- filteredRows.at(i) = fullText.contains(filterString, cs);
+ DiveObjectHelper *d = mySourceModel->at(i);
+ QString fullText = includeNotes? d->fullText() : d->fullTextNoNotes();
+ d->getDive()->hidden_by_filter = !fullText.contains(filterString, cs);
}
- updateDivesShownInTrips();
}
void DiveListSortModel::setSourceModel(QAbstractItemModel *sourceModel)
@@ -39,23 +37,23 @@ void DiveListSortModel::setFilter(QString f)
filterString = f;
updateFilterState();
invalidateFilter();
- updateDivesShownInTrips();
}
void DiveListSortModel::resetFilter()
{
- filterString = "";
- filteredRows.clear();
+ int i;
+ struct dive *d;
+ for_each_dive(i, d)
+ d->hidden_by_filter = false;
invalidateFilter();
- updateDivesShownInTrips();
}
// filtering is way too slow on mobile. Maybe we should roll our own?
-bool DiveListSortModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
+bool DiveListSortModel::filterAcceptsRow(int source_row, const QModelIndex &) const
{
- Q_UNUSED(source_parent)
-
- return filteredRows.size() > source_row ? filteredRows[source_row] : true;
+ DiveListModel *mySourceModel = qobject_cast<DiveListModel *>(sourceModel());
+ DiveObjectHelper *d = mySourceModel->at(source_row);
+ return d && !d->getDive()->hidden_by_filter;
}
int DiveListSortModel::shown()
@@ -84,7 +82,6 @@ void DiveListSortModel::clear()
{
DiveListModel *mySourceModel = qobject_cast<DiveListModel *>(sourceModel());
mySourceModel->clear();
- filteredRows.clear();
}
void DiveListSortModel::addAllDives()
@@ -94,24 +91,6 @@ void DiveListSortModel::addAllDives()
updateFilterState();
}
-void DiveListSortModel::updateDivesShownInTrips()
-{
- // if filtering is active, reset all the counts to zero, otherwise set them to the full count
- struct dive_trip *dt = dive_trip_list;
- int rc = rowCount();
- while (dt) {
- dt->showndives = rc ? 0 : dt->dives.nr;
- dt = dt->next;
- }
- for (int i = 0; i < rowCount(); i++) {
- QVariant v = data(index(i, 0), DiveListModel::DiveRole);
- DiveObjectHelper *d = v.value<DiveObjectHelper *>();
- dt = d->getDive()->divetrip;
- if (dt)
- dt->showndives++;
- }
-}
-
// In QML, section headings can only be strings. To identify dives that
// belong to the same trip, a string containing the trip-pointer in hexadecimal
// encoding is passed in. To format the trip heading, the string is then
@@ -131,7 +110,9 @@ QString DiveListSortModel::tripTitle(const QVariant &tripIn)
dive_trip *dt = tripIn.value<dive_trip *>();
if (!dt)
return QString();
- QString numDives = tr("(%n dive(s))", "", dt->showndives);
+ QString numDives = tr("(%n dive(s))", "", dt->dives.nr);
+ int shown = trip_shown_dives(dt);
+ QString shownDives = shown != dt->dives.nr ? QStringLiteral(" ") + tr("(%L1 shown)").arg(shown) : QString();
QString title(dt->location);
if (title.isEmpty()) {
@@ -149,7 +130,7 @@ QString DiveListSortModel::tripTitle(const QVariant &tripIn)
else
title = firstMonth + " " + firstYear + " - " + lastMonth + " " + lastYear;
}
- return QStringLiteral("%1 %2").arg(title, numDives);
+ return QStringLiteral("%1 %2%3").arg(title, numDives, shownDives);
}
QString DiveListSortModel::tripShortDate(const QVariant &tripIn)
diff --git a/qt-models/divelistmodel.h b/qt-models/divelistmodel.h
index 0c393bc2d..64d1e7ddc 100644
--- a/qt-models/divelistmodel.h
+++ b/qt-models/divelistmodel.h
@@ -24,11 +24,9 @@ public slots:
void setFilter(QString f);
void resetFilter();
int shown();
- void updateDivesShownInTrips();
protected:
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
private:
- std::vector<unsigned char> filteredRows; // using unsigned char because using 'bool' turns this into a bitfield
QString filterString;
void updateFilterState();
};