mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Mobile/filtering: update nr of dives shown in a trip when filtering
Whenever the filter changes, simply walk the filtered dive list and ensure that we have the correct count for dives that match this filter. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
89a242976f
commit
c5fb66e775
2 changed files with 22 additions and 0 deletions
|
@ -27,6 +27,7 @@ void DiveListSortModel::updateFilterState()
|
|||
QString fullText = includeNotes? mySourceModel->at(i)->fullText() : mySourceModel->at(i)->fullTextNoNotes();
|
||||
filteredRows.at(i) = fullText.contains(filterString, cs);
|
||||
}
|
||||
updateDivesShownInTrips();
|
||||
}
|
||||
|
||||
void DiveListSortModel::setSourceModel(QAbstractItemModel *sourceModel)
|
||||
|
@ -38,6 +39,7 @@ void DiveListSortModel::setFilter(QString f)
|
|||
filterString = f;
|
||||
updateFilterState();
|
||||
invalidateFilter();
|
||||
updateDivesShownInTrips();
|
||||
}
|
||||
|
||||
void DiveListSortModel::resetFilter()
|
||||
|
@ -45,6 +47,7 @@ void DiveListSortModel::resetFilter()
|
|||
filterString = "";
|
||||
filteredRows.clear();
|
||||
invalidateFilter();
|
||||
updateDivesShownInTrips();
|
||||
}
|
||||
|
||||
// filtering is way too slow on mobile. Maybe we should roll our own?
|
||||
|
@ -91,6 +94,24 @@ 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->nrdives;
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
||||
DiveListModel *DiveListModel::m_instance = NULL;
|
||||
|
||||
DiveListModel::DiveListModel(QObject *parent) : QAbstractListModel(parent)
|
||||
|
|
|
@ -21,6 +21,7 @@ public slots:
|
|||
void setFilter(QString f);
|
||||
void resetFilter();
|
||||
int shown();
|
||||
void updateDivesShownInTrips();
|
||||
protected:
|
||||
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
|
||||
private:
|
||||
|
|
Loading…
Add table
Reference in a new issue