Dive list: filter dives at DiveTripModel level

We use a QFilterProxyModel to filter out dives that are hidden
according to the current filter-criterion. Instead, filter the
dives already at the DiveTripModel level. Filter out hidden
dives immediately when receiving them. The only difficult case
is when dives are changed, because then visibility can change.
This means that we have three cases to consider:
  1) Visibility unchanged -> send change signal
  2) Change from hidden to unhidden -> add dives to model
  3) Change from unhidden to hidden -> remove dives from model
Things get complicated by the fact that the tree-version of
the model might have to add/remove full trips!

Suggested-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2020-02-09 22:47:47 +01:00 committed by Dirk Hohndel
parent e761d00ddd
commit 7633d5feec
2 changed files with 278 additions and 179 deletions

View file

@ -124,6 +124,8 @@ private:
void divesSelectedTrip(dive_trip *trip, const QVector<dive *> &dives, QVector<QModelIndex> &);
dive *diveOrNull(const QModelIndex &index) const override;
void divesChangedTrip(dive_trip *trip, const QVector<dive *> &dives);
void divesShown(dive_trip *trip, const QVector<dive *> &dives);
void divesHidden(dive_trip *trip, const QVector<dive *> &dives);
void divesTimeChangedTrip(dive_trip *trip, timestamp_t delta, const QVector<dive *> &dives);
bool calculateFilterForTrip(const std::vector<dive *> &dives, const DiveFilter *filter, quintptr parentIndex);
@ -151,8 +153,13 @@ private:
dive_or_trip tripOrDive(const QModelIndex &index) const;
// Returns either a pointer to a trip or a dive, or twice null of index is invalid
// null, something is really wrong
// Addition and deletion of dives
// Addition and deletion of dives and trips
void addTrip(dive_trip *trip, const QVector<dive *> &dives);
void addDivesToTrip(int idx, const QVector<dive *> &dives);
void addDivesTopLevel(const QVector<dive *> &dives);
void removeDivesFromTrip(int idx, const QVector<dive *> &dives);
void removeDivesTopLevel(const QVector<dive *> &dives);
void removeTrip(int idx);
void topLevelChanged(int idx);
// Access trips and dives
@ -190,6 +197,8 @@ private:
QVariant data(const QModelIndex &index, int role) const override;
bool lessThan(const QModelIndex &i1, const QModelIndex &i2) const override;
dive *diveOrNull(const QModelIndex &index) const override;
void addDives(QVector<dive *> &dives);
void removeDives(QVector<dive *> &dives);
std::vector<dive *> items; // TODO: access core data directly
};