From e99c4c90592c9dba17d5cbb9a99d0bf458fb53d2 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Tue, 12 Mar 2019 17:28:43 +0100 Subject: Dive site: introduce proxy model DiveSiteSortedModel The LocationInformationModel used to sort its entries and was completely rebuilt after every change. This makes it rather complex to support incremental changes. Instead, keep LocationInformationModel sorted by UUID so that indexes are consistent with indices in the core dive site table. Implement sorting by other columns than name and enable sorting in the dive site view. Finally, don't cache the list of dive site names for the mobile app, since that would also need some rather convoluted methods of keeping the list up to date. Calculate it on the fly. Signed-off-by: Berthold Stoeger --- qt-models/divelocationmodel.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'qt-models/divelocationmodel.h') diff --git a/qt-models/divelocationmodel.h b/qt-models/divelocationmodel.h index 65fabca96..f2bcc7cf7 100644 --- a/qt-models/divelocationmodel.h +++ b/qt-models/divelocationmodel.h @@ -32,12 +32,19 @@ public: public slots: void update(); - QStringList allSiteNames() const; void diveSiteDiveCountChanged(struct dive_site *ds); void diveSiteAdded(struct dive_site *ds, int idx); void diveSiteDeleted(struct dive_site *ds, int idx); +}; + +class DiveSiteSortedModel : public QSortFilterProxyModel { + Q_OBJECT private: - QStringList locationNames; + bool filterAcceptsRow(int sourceRow, const QModelIndex &source_parent) const override; + bool lessThan(const QModelIndex &i1, const QModelIndex &i2) const override; +public: + DiveSiteSortedModel(); + QStringList allSiteNames() const; }; // To access only divesites at the given GPS coordinates with the exception of a given dive site -- cgit v1.2.3-70-g09d2