diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2013-11-08 18:15:04 +0900 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-11-08 18:15:04 +0900 |
commit | 1578c1edb2dd7e74b111e6b6b5c7883c37554235 (patch) | |
tree | 58a8a63a7849525a38a7ac21f647c89fba311041 /qt-ui | |
parent | bf0bd88226508ca9c2dc8941cde82f72cbe1d371 (diff) | |
download | subsurface-1578c1edb2dd7e74b111e6b6b5c7883c37554235.tar.gz |
Be consistent when passing around gas data in the planner
We need to make sure that the correct segment has the correct gas assigned
to it - and that those gases are correctly tracked when editing a manually
added dive as well.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui')
-rw-r--r-- | qt-ui/diveplanner.cpp | 58 | ||||
-rw-r--r-- | qt-ui/diveplanner.h | 2 | ||||
-rw-r--r-- | qt-ui/maintab.cpp | 7 | ||||
-rw-r--r-- | qt-ui/maintab.h | 1 |
4 files changed, 38 insertions, 30 deletions
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 2b4b1d1d2..398d11fc3 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -412,17 +412,16 @@ void DivePlannerGraphics::mouseDoubleClickEvent(QMouseEvent* event) int minutes = rint(timeLine->valueAt(mappedPos)); int milimeters = rint(depthLine->valueAt(mappedPos) / M_OR_FT(1,1)) * M_OR_FT(1,1); - plannerModel->addStop(milimeters, minutes * 60, tr("Air"), 0); + plannerModel->addStop(milimeters, minutes * 60, O2_IN_AIR, 0, 0); } void DivePlannerPointsModel::createSimpleDive() { - plannerModel->addStop(M_OR_FT(15,45), 1 * 60, tr("Air"), 0); - plannerModel->addStop(M_OR_FT(15,45), 40 * 60, tr("Air"), 0); -// plannerModel->addStop(9000, 26 * 60, tr("Air"), 0); -// plannerModel->addStop(9000, 41 * 60, tr("Air"), 0); - plannerModel->addStop(M_OR_FT(5,15), 42 * 60, tr("Air"), 0); - plannerModel->addStop(M_OR_FT(5,15), 45 * 60, tr("Air"), 0); + plannerModel->addStop(0, 0, O2_IN_AIR, 0, 0); + plannerModel->addStop(M_OR_FT(15,45), 1 * 60, O2_IN_AIR, 0, 0); + plannerModel->addStop(M_OR_FT(15,45), 40 * 60, O2_IN_AIR, 0, 0); + plannerModel->addStop(M_OR_FT(5,15), 42 * 60, O2_IN_AIR, 0, 0); + plannerModel->addStop(M_OR_FT(5,15), 45 * 60, O2_IN_AIR, 0, 0); } void DivePlannerPointsModel::loadFromDive(dive* d) @@ -431,14 +430,23 @@ 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 = 1; i < d->dc.samples-1; i++){ + for(int i = 0; i < d->dc.samples-1; i++){ backupSamples.push_back( d->dc.sample[i]); } + save_dive(stdout, current_dive); + save_dive(stdout, backupDive); Q_FOREACH(const sample &s, backupSamples){ - // we need to use the correct gas - plannerModel->addStop(s.depth.mm, s.time.seconds, tr("Air"), 0); + int o2 = 0, he = 0; + get_gas_from_events(&backupDive->dc, s.time.seconds, &o2, &he); + qDebug() << "time / depth" << s.time.seconds << s.depth.mm << "o2/he" << o2 << he; + plannerModel->addStop(s.depth.mm, s.time.seconds, o2, he, 0); } } @@ -466,6 +474,10 @@ void DivePlannerGraphics::drawProfile() plannerModel->createTemporaryPlan(); struct diveplan diveplan = plannerModel->getDiveplan(); struct divedatapoint *dp = diveplan.dp; + if (!dp) { + plannerModel->deleteTemporaryPlan(); + return; + } while(dp->next) dp = dp->next; @@ -1076,9 +1088,10 @@ bool divePointsLessThan(const divedatapoint& p1, const divedatapoint& p2) return p1.time <= p2.time; } -int DivePlannerPointsModel::addStop(int milimeters, int minutes, const QString& gas, int ccpoint) +int DivePlannerPointsModel::addStop(int milimeters, int minutes, int o2, int he, int ccpoint) { int row = divepoints.count(); +#if 0 // this seems bogus if(milimeters == 0 && minutes == 0) { if(row == 0) { milimeters = M_OR_FT(10,30); @@ -1089,6 +1102,7 @@ int DivePlannerPointsModel::addStop(int milimeters, int minutes, const QString& minutes = p.time + 600; } } +#endif // check if there's already a new stop before this one: for (int i = 0; i < divepoints.count(); i++) { @@ -1104,16 +1118,9 @@ int DivePlannerPointsModel::addStop(int milimeters, int minutes, const QString& divedatapoint point; point.depth = milimeters; point.time = minutes; - if (row == 0) { - point.o2 = 209; - point.he = 0; - point.po2 = 0; - } else { - divedatapoint before = at(row-1); - point.o2 = before.o2; - point.he = before.he; - point.po2 = 0; - } + point.o2 = o2; + point.he = he; + point.po2 = ccpoint; divepoints.append( point ); std::sort(divepoints.begin(), divepoints.end(), divePointsLessThan); endInsertRows(); @@ -1174,8 +1181,8 @@ void DivePlannerPointsModel::createTemporaryPlan() // Get the user-input and calculate the dive info // Not sure if this is the place to create the diveplan... // We just start with a surface node at time = 0 - struct divedatapoint *dp = create_dp(0, 0, 209, 0, 0); - dp->entered = TRUE; + struct divedatapoint *dp = NULL; // create_dp(0, 0, 209, 0, 0); +// dp->entered = TRUE; diveplan.dp = dp; int lastIndex = -1; for (int i = 0; i < rowCount(); i++) { @@ -1194,6 +1201,7 @@ void DivePlannerPointsModel::createTemporaryPlan() if (mode == ADD) { copy_samples(tempDive, current_dive); copy_cylinders(tempDive, current_dive); + copy_events(tempDive, current_dive); } #if DEBUG_PLAN dump_plan(&diveplan); @@ -1206,7 +1214,9 @@ void DivePlannerPointsModel::undoEdition() divepoints.clear(); endRemoveRows(); Q_FOREACH(const sample &s, backupSamples){ - plannerModel->addStop(s.depth.mm, s.time.seconds, tr("Air"), 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); } } diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index 6883f62eb..83bfadc32 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -41,7 +41,7 @@ public: int size(); struct diveplan getDiveplan(); public slots: - int addStop(int meters = 0, int minutes = 0,const QString& gas = QString(), int ccpoint = 0 ); + int addStop(int meters = 0, int minutes = 0, int o2 = 0, int he = 0, int ccpoint = 0 ); void setGFHigh(short gfhigh); void setGFLow(short ghflow); void setSurfacePressure(int pressure); diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index dfcb48a0c..8230cf663 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -538,14 +538,13 @@ void MainTab::rejectChanges() if (mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1){ ui.notes->setText(notesBackup[NULL].notes ); ui.location->setText(notesBackup[NULL].location); - }else{ + } else { if (editMode == ADD) { // clean up delete_single_dive(selected_dive); DivePlannerPointsModel::instance()->cancelPlan(); - } - else if (editMode == MANUALLY_ADDED_DIVE ){ - DivePlannerPointsModel::instance()->undoEdition(); + } else if (editMode == MANUALLY_ADDED_DIVE ) { + DivePlannerPointsModel::instance()->undoEdition(); // that's BOGUS... just copy the original dive back and be done with it... } struct dive *curr = current_dive; ui.notes->setText(notesBackup[curr].notes ); diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h index 22a705530..68803c02d 100644 --- a/qt-ui/maintab.h +++ b/qt-ui/maintab.h @@ -94,7 +94,6 @@ private: * dive to this structure, making all editions there, * then applying the changes on the other dives.*/ struct dive multiEditEquipmentPlaceholder; - Completers completers; void resetPallete(); void saveTags(); |