From b791b41db98ddec7b25448092fa30f24224af8c5 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Fri, 30 May 2014 15:17:15 -0700 Subject: Remove unused structure member Signed-off-by: Dirk Hohndel --- dive.h | 1 - 1 file changed, 1 deletion(-) diff --git a/dive.h b/dive.h index 277573f5b..f1570d31e 100644 --- a/dive.h +++ b/dive.h @@ -640,7 +640,6 @@ struct divedatapoint { struct diveplan { timestamp_t when; - int lastdive_nr; int surface_pressure; /* mbar */ int bottomsac; /* ml/min */ int decosac; /* ml/min */ -- cgit v1.2.3-70-g09d2 From 65f3135a92cb9bb33c9870105334ca458e1f151d Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Fri, 30 May 2014 15:40:13 -0700 Subject: Planner: don't do unnecessary work on empty dive plans Signed-off-by: Dirk Hohndel --- planner.c | 14 ++++++++++++++ planner.h | 1 + qt-ui/diveplanner.cpp | 4 +++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/planner.c b/planner.c index 2cc47258c..405b07e02 100644 --- a/planner.c +++ b/planner.c @@ -49,6 +49,20 @@ void dump_plan(struct diveplan *diveplan) } #endif +bool diveplan_empty(struct diveplan *diveplan) +{ + struct divedatapoint *dp; + if (!diveplan || !diveplan->dp) + return true; + dp = diveplan->dp; + while(dp) { + if (dp->time) + return false; + dp = dp->next; + } + return true; +} + void set_last_stop(bool last_stop_6m) { if (last_stop_6m == true) diff --git a/planner.h b/planner.h index 49f8be5ef..d5607a948 100644 --- a/planner.h +++ b/planner.h @@ -13,6 +13,7 @@ extern void show_planned_dive(char **error_string_p); extern void set_last_stop(bool last_stop_6m); extern void get_gas_from_events(struct divecomputer *dc, int time, int *o2, int *he); extern int get_gasidx(struct dive *dive, int o2, int he); +extern bool diveplan_empty(struct diveplan *diveplan); extern struct dive *planned_dive; extern char *cache_data; diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 2b1662f7d..0d5b79edd 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -777,6 +777,8 @@ void DivePlannerPointsModel::addDecoToModel() { struct divedatapoint *dp; + if (diveplan_empty(&diveplan)) + return; bool oldRecalc = plannerModel->setRecalc(false); plannerModel->removeDeco(); @@ -832,7 +834,7 @@ void DivePlannerPointsModel::createTemporaryPlan() #if DEBUG_PLAN dump_plan(&diveplan); #endif - if (plannerModel->recalcQ()) { + if (plannerModel->recalcQ() && !diveplan_empty(&diveplan)) { plan(&diveplan, &cache, &tempDive, stagingDive, isPlanner()); addDecoToModel(); if (mode == ADD || mode == PLAN) { -- cgit v1.2.3-70-g09d2 From a0136a3b8c7c20e2d28a6757d7356bbec6154a6c Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Fri, 30 May 2014 15:47:42 -0700 Subject: Planner: remove check for empty diveplan This was introduced in commit fc1336107930 ("Don't crash if we try to save a empty plan") - but it doesn't seem to make any sense. It is perfectly reasonable for the diveplan to have no datapoints at this spot - we are just about to call createTemporaryPlan() which will fill those datapoints from the mode. Signed-off-by: Dirk Hohndel --- qt-ui/diveplanner.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 0d5b79edd..76f81961f 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -876,9 +876,6 @@ void DivePlannerPointsModel::createPlan() char *cache = NULL; tempDive = NULL; - if (!diveplan.dp) - return cancelPlan(); - bool oldRecalc = plannerModel->setRecalc(false); removeDeco(); createTemporaryPlan(); -- cgit v1.2.3-70-g09d2 From 6f1e071a54224700de8f96d0eefa0ee807f886b0 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Fri, 30 May 2014 16:12:35 -0700 Subject: Planner: don't recreate the dive while cleaning up the widgets Otherwise the change to the Cylinder widget would trigger a recreation of the dive in an inconsistent state. Signed-off-by: Dirk Hohndel --- qt-ui/diveplanner.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 76f81961f..21559a65a 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -764,6 +764,7 @@ void DivePlannerPointsModel::clear() } else { stagingDive = alloc_dive(); } + bool oldRecalc = setRecalc(false); CylindersModel::instance()->setDive(stagingDive); if (rowCount() > 0) { beginRemoveRows(QModelIndex(), 0, rowCount() - 1); @@ -771,6 +772,7 @@ void DivePlannerPointsModel::clear() endRemoveRows(); } CylindersModel::instance()->clear(); + setRecalc(oldRecalc); } void DivePlannerPointsModel::addDecoToModel() -- cgit v1.2.3-70-g09d2 From eb26823b3476dca68200017948b73cb405ef803a Mon Sep 17 00:00:00 2001 From: "Robert C. Helling" Date: Sat, 31 May 2014 13:53:18 +0200 Subject: Allow editing segment duration. This shifts all following waypoints. Signed-off-by: Robert C. Helling Signed-off-by: Dirk Hohndel --- qt-ui/diveplanner.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 21559a65a..c73487048 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -388,6 +388,7 @@ bool DivePlannerPointsModel::setData(const QModelIndex &index, const QVariant &v { int o2 = 0; int he = 0; + int i, shift; if (role == Qt::EditRole) { divedatapoint &p = divepoints[index.row()]; switch (index.column()) { @@ -398,10 +399,13 @@ bool DivePlannerPointsModel::setData(const QModelIndex &index, const QVariant &v p.time = value.toInt() * 60; break; case DURATION: - if (index.row()) - p.time = value.toInt() * 60 + divepoints[index.row() - 1].time; + i = index.row(); + if (i) + shift = divepoints[i].time - divepoints[i - 1].time - value.toInt() * 60; else - p.time = value.toInt() * 60; + shift = divepoints[i].time - value.toInt() * 60; + while (i < divepoints.size()) + divepoints[i++].time -= shift; break; case CCSETPOINT: { int po2 = 0; @@ -445,7 +449,7 @@ QVariant DivePlannerPointsModel::headerData(int section, Qt::Orientation orienta Qt::ItemFlags DivePlannerPointsModel::flags(const QModelIndex &index) const { - if (index.column() != DURATION && index.column() != REMOVE) + if (index.column() != REMOVE) return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; else return QAbstractItemModel::flags(index); -- cgit v1.2.3-70-g09d2