From f8c5c8bedf9c0af8f031da7fc74c516a40e9e1c6 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Tue, 13 Aug 2019 08:19:04 +0200 Subject: Mobile: Generate DiveObjectHelpers on the fly Instead of keeping track of a list of DiveObjectHelpers, generate them on-the-fly in DiveListModel. Thus, there is less danger of model and core getting out of sync. On the flip-side, now the DiveListModel and the DiveListSortModel might get out of sync. Signed-off-by: Berthold Stoeger --- core/subsurface-qt/DiveObjectHelper.cpp | 10 ++++++++++ core/subsurface-qt/DiveObjectHelper.h | 2 ++ 2 files changed, 12 insertions(+) (limited to 'core') diff --git a/core/subsurface-qt/DiveObjectHelper.cpp b/core/subsurface-qt/DiveObjectHelper.cpp index c19c03eb4..cb6cf6dd1 100644 --- a/core/subsurface-qt/DiveObjectHelper.cpp +++ b/core/subsurface-qt/DiveObjectHelper.cpp @@ -67,6 +67,16 @@ DiveObjectHelper::DiveObjectHelper(struct dive *d) : { } +DiveObjectHelper::operator bool() const +{ + return !!m_dive; +} + +bool DiveObjectHelper::operator!() const +{ + return !m_dive; +} + int DiveObjectHelper::number() const { return m_dive->number; diff --git a/core/subsurface-qt/DiveObjectHelper.h b/core/subsurface-qt/DiveObjectHelper.h index 7071c1580..674386e56 100644 --- a/core/subsurface-qt/DiveObjectHelper.h +++ b/core/subsurface-qt/DiveObjectHelper.h @@ -50,6 +50,8 @@ class DiveObjectHelper { public: DiveObjectHelper(); // This is only to be used by Qt's metatype system! DiveObjectHelper(struct dive *dive); + operator bool() const; // Returns false if this is an invalid default-generated object + bool operator!() const; // Returns true if this is an invalid default-generated object int number() const; int id() const; struct dive *getDive() const; -- cgit v1.2.3-70-g09d2