diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2013-11-18 11:55:56 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-11-18 11:55:56 -0800 |
commit | 8ae8c81d3d47e5ba6b7ea292c92a9527fc85994f (patch) | |
tree | 52a3b5676d1d01a6d0b823346022d6fcd77f855f /qt-ui/diveplanner.cpp | |
parent | 3801b765fff847adff1899c7d54484b0bb100c87 (diff) | |
download | subsurface-8ae8c81d3d47e5ba6b7ea292c92a9527fc85994f.tar.gz |
Fix various issues with the dive add / edit manual dive code
- get_gas_from_events does NOT always set o2/he. It only updates them IFF
a matching event is found; so we need to make sure we start out with a
valid gas mix
- the way we tried to restore the edited dive in case of an edit to a
manually added that is cancelled was completely bogus. Way too complex
when we can simply and reliably simply store the dive and then copy it
back
Fixes #270
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/diveplanner.cpp')
-rw-r--r-- | qt-ui/diveplanner.cpp | 38 |
1 files changed, 14 insertions, 24 deletions
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 39fe0548f..aefb4ef65 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -442,28 +442,30 @@ void DivePlannerPointsModel::loadFromDive(dive* d) * as soon as the model is modified, it will * remove all samples from the current dive. * */ - struct dive *backupDive = alloc_dive(); - backupDive->when = current_dive->when; // do we need anything else? - copy_samples(current_dive, backupDive); - copy_cylinders(current_dive, backupDive); - copy_events(current_dive, backupDive); - backupSamples.clear(); - for(int i = 0; i < d->dc.samples-1; i++){ - backupSamples.push_back( d->dc.sample[i]); - } + memcpy(&backupDive, current_dive, sizeof(struct dive)); + copy_samples(current_dive, &backupDive); + copy_events(current_dive, &backupDive); copy_cylinders(current_dive, stagingDive); // this way the correct cylinder data is shown CylindersModel::instance()->setDive(stagingDive); int lasttime = 0; - Q_FOREACH(const sample &s, backupSamples){ - int o2 = 0, he = 0; + // we start with the first gas and see if it was changed + int o2 = backupDive.cylinder[0].gasmix.o2.permille; + int he = backupDive.cylinder[0].gasmix.he.permille; + for (int i = 0; i < backupDive.dc.samples; i++) { + const sample &s = backupDive.dc.sample[i]; if (s.time.seconds == 0) continue; - get_gas_from_events(&backupDive->dc, lasttime, &o2, &he); + get_gas_from_events(&backupDive.dc, lasttime, &o2, &he); plannerModel->addStop(s.depth.mm, s.time.seconds, o2, he, 0); lasttime = s.time.seconds; } } +void DivePlannerPointsModel::restoreBackupDive() +{ + memcpy(current_dive, &backupDive, sizeof(struct dive)); +} + void DivePlannerPointsModel::copyCylinders(dive *d) { copy_cylinders(stagingDive, d); @@ -1412,18 +1414,6 @@ void DivePlannerPointsModel::createTemporaryPlan() #endif } -void DivePlannerPointsModel::undoEdition() -{ - clear(); - Q_FOREACH(const sample &s, backupSamples){ - if (s.time.seconds > 0) { - int o2, he; - get_gas_from_events(¤t_dive->dc, s.time.seconds, &o2, &he); - plannerModel->addStop(s.depth.mm, s.time.seconds, o2, he, 0); - } - } -} - void DivePlannerPointsModel::deleteTemporaryPlan() { deleteTemporaryPlan(diveplan.dp); |