diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2013-11-09 20:35:09 +0900 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-11-09 20:35:09 +0900 |
commit | 487efb1ee91c5b7e648f31ef3700fae2c45753d4 (patch) | |
tree | ee9226b8abb20f09473dd42ef0dca4578433911d /qt-ui/diveplanner.cpp | |
parent | 5dce73f62b21b9d70cf4d7f51c8d6ec9cf8bb9f1 (diff) | |
parent | 6d5b2d75927b23183f8864bebf894b7bf4828311 (diff) | |
download | subsurface-487efb1ee91c5b7e648f31ef3700fae2c45753d4.tar.gz |
Merge branch 'addDiveGasFix'
Diffstat (limited to 'qt-ui/diveplanner.cpp')
-rw-r--r-- | qt-ui/diveplanner.cpp | 146 |
1 files changed, 87 insertions, 59 deletions
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 376887b43..ec7a8a21f 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -41,7 +41,7 @@ QStringListModel *airTypes() { } QString strForAir(const divedatapoint& p) { - return p.o2 == 209 ? QObject::tr("AIR") + return is_air(p.o2, p.he) ? QObject::tr("AIR") : p.o2 == 320 ? QObject::tr("EAN32") : p.o2 == 360 ? QObject::tr("EAN36") : QObject::tr("Choose Gas"); @@ -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,22 @@ 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 +473,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; @@ -476,16 +487,16 @@ void DivePlannerGraphics::drawProfile() } // Re-position the user generated dive handlers - for (int i = 0; i < plannerModel->rowCount(); i++) { + for (int i = 1; i < plannerModel->rowCount(); i++) { divedatapoint dp = plannerModel->at(i); DiveHandler *h = handles.at(i); h->setPos(timeLine->posAtValue(dp.time / 60), depthLine->posAtValue(dp.depth)); - QPointF p1 = (i == 0) ? QPointF(timeLine->posAtValue(0), depthLine->posAtValue(0)) : handles[i-1]->pos(); + QPointF p1 = handles[i-1]->pos(); QPointF p2 = handles[i]->pos(); QLineF line(p1, p2); QPointF pos = line.pointAt(0.5); gases[i]->setPos(pos); - gases[i]->setText( strForAir(dp)); + gases[i]->setText(strForAir(plannerModel->at(i-1))); } // (re-) create the profile with different colors for segments that were @@ -953,10 +964,15 @@ QVariant DivePlannerPointsModel::data(const QModelIndex& index, int role) const if(role == Qt::DisplayRole) { divedatapoint p = divepoints.at(index.row()); switch(index.column()) { - case CCSETPOINT: return p.po2; - case DEPTH: return rint(get_depth_units(p.depth, NULL, NULL)); - case DURATION: return p.time / 60; - case GAS: return strForAir(p); + case CCSETPOINT: return p.po2; + case DEPTH: return rint(get_depth_units(p.depth, NULL, NULL)); + case DURATION: return p.time / 60; + case GAS: + if (index.row() > 0) { + p = divepoints.at(index.row() - 1); + return strForAir(p); + } + return ""; } } else if (role == Qt::DecorationRole) { switch(index.column()) { @@ -973,23 +989,30 @@ bool DivePlannerPointsModel::setData(const QModelIndex& index, const QVariant& v if(role == Qt::EditRole) { divedatapoint& p = divepoints[index.row()]; switch(index.column()) { - case DEPTH: p.depth = units_to_depth(value.toInt()); break; - case DURATION: p.time = value.toInt() * 60; break; - case CCSETPOINT:{ - int po2 = 0; - QByteArray gasv = value.toByteArray(); - if (validate_po2(gasv.data(), &po2)) - p.po2 = po2; - } break; - case GAS: { - int o2 = 0; - int he = 0; - QByteArray gasv = value.toByteArray(); - if (validate_gas(gasv.data(), &o2, &he)) { - p.o2 = o2; - p.he = he; - }break; + case DEPTH: p.depth = units_to_depth(value.toInt()); break; + case DURATION: p.time = value.toInt() * 60; break; + case CCSETPOINT: { + int po2 = 0; + QByteArray gasv = value.toByteArray(); + if (validate_po2(gasv.data(), &po2)) + p.po2 = po2; + } + break; + case GAS: { + if (index.row() == 0) { + qDebug() << "how can index.row be 0???"; + return false; + } + divedatapoint& pp = divepoints[index.row() - 1]; + int o2 = 0; + int he = 0; + QByteArray gasv = value.toByteArray(); + if (validate_gas(gasv.data(), &o2, &he)) { + pp.o2 = o2; + pp.he = he; + } } + break; } editStop(index.row(), p); } @@ -1076,23 +1099,32 @@ 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(milimeters == 0 && minutes == 0) { - if(row == 0) { - milimeters = M_OR_FT(10,30); - minutes = 600; - } else { - divedatapoint p = at(row-1); - milimeters = p.depth; - minutes = p.time + 600; - } + if(row == 0) { + beginInsertRows(QModelIndex(), row, row); + divedatapoint point; + point.depth = 0; + point.time = 0; + point.o2 = o2; + point.he = he; + point.po2 = ccpoint; + divepoints.append( point ); + endInsertRows(); + row++; } // check if there's already a new stop before this one: - for (int i = 0; i < divepoints.count(); i++) { + for (int i = 0; i < row; i++) { const divedatapoint& dp = divepoints.at(i); + if (dp.time == minutes) { + row = i; + beginRemoveRows(QModelIndex(), row, row); + divepoints.remove(row); + endRemoveRows(); + break; + } if (dp.time > minutes ) { row = i; break; @@ -1104,16 +1136,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(); @@ -1185,8 +1210,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++) { @@ -1205,6 +1230,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); @@ -1215,7 +1241,9 @@ void DivePlannerPointsModel::undoEdition() { clear(); 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); } } |