diff options
-rw-r--r-- | planner.c | 2 | ||||
-rw-r--r-- | qt-ui/diveplanner.cpp | 38 | ||||
-rw-r--r-- | qt-ui/diveplanner.h | 4 | ||||
-rw-r--r-- | qt-ui/maintab.cpp | 4 |
4 files changed, 22 insertions, 26 deletions
@@ -57,6 +57,8 @@ void set_last_stop(bool last_stop_6m) void get_gas_from_events(struct divecomputer *dc, int time, int *o2, int *he) { + // we don't modify the values passed in if nothing is found + // so don't call with uninitialized o2/he ! struct event *event = dc->events; while (event && event->time.seconds <= time) { if (!strcmp(event->name, "gaschange")) { 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); diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index a310cf045..1d15fb766 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -61,7 +61,8 @@ public slots: void createTemporaryPlan(); void deleteTemporaryPlan(); void loadFromDive(dive* d); - void undoEdition(); + void restoreBackupDive(); + signals: void planCreated(); void planCanceled(); @@ -73,6 +74,7 @@ private: Mode mode; QVector<divedatapoint> divepoints; struct dive *tempDive; + struct dive backupDive; void deleteTemporaryPlan(struct divedatapoint *dp); QVector<sample> backupSamples; // For editing added dives. struct dive *stagingDive; diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 16350f709..7c94ab4c8 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -565,7 +565,9 @@ void MainTab::rejectChanges() // clean up DivePlannerPointsModel::instance()->cancelPlan(); } else if (lastMode == MANUALLY_ADDED_DIVE ) { - DivePlannerPointsModel::instance()->undoEdition(); // that's BOGUS... just copy the original dive back and be done with it... + // when we tried to edit a manually added dive, we destroyed + // the dive we edited, so let's just restore it from backup + DivePlannerPointsModel::instance()->restoreBackupDive(); } struct dive *curr = current_dive; ui.notes->setText(notesBackup[curr].notes ); |