summaryrefslogtreecommitdiffstats
path: root/qthelper.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-01-07 09:30:01 +0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-01-07 12:02:42 +0800
commit65e9fecd806810d9462e775ffeba3badf66bd948 (patch)
tree67b967685fb50027433aaaa517fb1ffbaa92685a /qthelper.cpp
parentca391035f303e7d4382eb8e50cca8619e354c20e (diff)
downloadsubsurface-65e9fecd806810d9462e775ffeba3badf66bd948.tar.gz
Add a unique id to every dive
This id is just held in memory. It's not supposed to be used for anything but having a unique handle that represents a dive. Whenever you need to remember a dive across an operation that might change the dive_table, this is what you should hold on to, not a dive number, a dive pointer, or anything like that. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qthelper.cpp')
-rw-r--r--qthelper.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/qthelper.cpp b/qthelper.cpp
index 7eb1e48f4..9d503cb6a 100644
--- a/qthelper.cpp
+++ b/qthelper.cpp
@@ -217,3 +217,27 @@ QList< int > getDivesInTrip ( dive_trip_t* trip )
}
return ret;
}
+
+// we need this to be uniq, but also make sure
+// it doesn't change during the life time of a Subsurface session
+// oh, and it has no meaning whatsoever - that's why we have the
+// silly initial number and increment by 3 :-)
+int getUniqID(struct dive *d)
+{
+ static QSet<int> ids;
+ static int maxId = 83529;
+
+ int id = d->id;
+ if (id) {
+ if (!ids.contains(id)) {
+ qDebug() << "WTF - only I am allowed to create IDs";
+ ids.insert(id);
+ }
+ return id;
+ }
+ maxId += 3;
+ id = maxId;
+ Q_ASSERT(!ids.contains(id));
+ ids.insert(id);
+ return id;
+}