summaryrefslogtreecommitdiffstats
path: root/qt-ui/diveplanner.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-11-13 21:45:54 +0900
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-11-13 21:56:22 +0900
commitd7fb6853a30d430d73df9d1b076ea194ddeacac2 (patch)
treea2f33260f6d8bff8c30a8c5cdc7944682aa1fdce /qt-ui/diveplanner.cpp
parentaa76d3592361ec7b07a8fc15fd466bcd392629ec (diff)
downloadsubsurface-d7fb6853a30d430d73df9d1b076ea194ddeacac2.tar.gz
Connect changes in the tanks with the dive that is being added
- you can no longer delete a tank when its gas is in use - therefore you can no longer delete the last tank - when you change the gas mix of a tank, the corresponding segments in the dive change as well - when changing gas for a segment the correct available gases are offered Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/diveplanner.cpp')
-rw-r--r--qt-ui/diveplanner.cpp60
1 files changed, 59 insertions, 1 deletions
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index 45360c85c..65a358489 100644
--- a/qt-ui/diveplanner.cpp
+++ b/qt-ui/diveplanner.cpp
@@ -1263,6 +1263,64 @@ DivePlannerPointsModel::Mode DivePlannerPointsModel::currentMode() const
return mode;
}
+QList<QPair<int, int> > DivePlannerPointsModel::collectGases(struct dive *d)
+{
+ QList<QPair<int, int> > l;
+ for (int i = 0; i < MAX_CYLINDERS; i++) {
+ cylinder_t *cyl = &d->cylinder[i];
+ if (!cylinder_nodata(cyl))
+ l.push_back(QPair<int, int>(cyl->gasmix.o2.permille, cyl->gasmix.he.permille));
+ }
+ return l;
+}
+void DivePlannerPointsModel::rememberTanks()
+{
+ oldGases = collectGases(stagingDive);
+}
+
+bool DivePlannerPointsModel::tankInUse(int o2, int he)
+{
+ for (int j = 0; j < rowCount(); j++) {
+ divedatapoint& p = divepoints[j];
+ if (p.time == 0) // special entries that hold the available gases
+ continue;
+ if ((p.o2 == o2 && p.he == he) ||
+ (is_air(p.o2, p.he) && is_air(o2, he)))
+ return true;
+ }
+ return false;
+}
+
+void DivePlannerPointsModel::tanksUpdated()
+{
+ if (mode == ADD) {
+ // we don't know exactly what changed - what we care about is
+ // "did a gas change on us". So we look through the diveplan to
+ // see if there is a gas that is now missing and if there is, we
+ // replace it with the matching new gas.
+ QList<QPair<int,int> > gases = collectGases(stagingDive);
+ if (gases.length() == oldGases.length()) {
+ // either nothing relevant changed, or exactly ONE gasmix changed
+ for (int i = 0; i < gases.length(); i++) {
+ if (gases.at(i) != oldGases.at(i)) {
+ for (int j = 0; j < rowCount(); j++) {
+ divedatapoint& p = divepoints[j];
+ int o2 = oldGases.at(i).first;
+ int he = oldGases.at(i).second;
+ if (p.o2 == o2 && p.he == he ||
+ (is_air(p.o2, p.he) && (is_air(o2, he) || (o2 == 0 && he == 0)))) {
+ p.o2 = gases.at(i).first;
+ p.he = gases.at(i).second;
+ }
+ }
+ break;
+ }
+ }
+ }
+ emit dataChanged(createIndex(0, 0), createIndex(rowCount()-1, COLUMNS-1));
+ }
+}
+
void DivePlannerPointsModel::clear()
{
if (mode == ADD) {
@@ -1312,8 +1370,8 @@ void DivePlannerPointsModel::createTemporaryPlan()
#endif
plan(&diveplan, &cache, &tempDive, isPlanner(), &errorString);
if (mode == ADD) {
+ // copy the samples and events, but don't overwrite the cylinders
copy_samples(tempDive, current_dive);
- copy_cylinders(tempDive, current_dive);
copy_events(tempDive, current_dive);
}
#if DEBUG_PLAN