summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-05-31 06:46:30 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-05-31 06:46:30 -0700
commit738c472daf76cde95f61c4b9a615af82b01e60d3 (patch)
tree8ee51c37c7a887b574cd00c3d183fd4275486cff
parent8cbf2071693f06a2fe25c6ae322c3131302dd2bf (diff)
parenteb26823b3476dca68200017948b73cb405ef803a (diff)
downloadsubsurface-738c472daf76cde95f61c4b9a615af82b01e60d3.tar.gz
Merge branch 'latest'
-rw-r--r--dive.h1
-rw-r--r--planner.c14
-rw-r--r--planner.h1
-rw-r--r--qt-ui/diveplanner.cpp18
4 files changed, 28 insertions, 6 deletions
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 */
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 d11b89617..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);
@@ -764,6 +768,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,12 +776,15 @@ void DivePlannerPointsModel::clear()
endRemoveRows();
}
CylindersModel::instance()->clear();
+ setRecalc(oldRecalc);
}
void DivePlannerPointsModel::addDecoToModel()
{
struct divedatapoint *dp;
+ if (diveplan_empty(&diveplan))
+ return;
bool oldRecalc = plannerModel->setRecalc(false);
plannerModel->removeDeco();
@@ -832,7 +840,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) {