summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@atdotde.de>2014-11-04 12:15:27 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-11-04 07:21:34 -0800
commit20a9db779d3a7ba1591e8d336c6b99b80aef71de (patch)
tree9fa678ed3da32dc3b0e6006c11c78eb4a272adcf
parent06ddfc01222879ee0463affe796dba05de33b368 (diff)
downloadsubsurface-20a9db779d3a7ba1591e8d336c6b99b80aef71de.tar.gz
Offer to save to a copy in replan mode
When replannig a dive, offer another button that creates a new dive rather than overwriting the old. This should help in creating several versions of a planned dive (longer/shorter, deeper/shallower etc). Note that this makes dives that start at the same time not influcence each other's deco. Also, only the first of a row of simultaneous dives contributes to the tissue loadings of later dives. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--divelist.c8
-rw-r--r--qt-ui/diveplanner.cpp30
-rw-r--r--qt-ui/diveplanner.h7
-rw-r--r--qt-ui/diveplanner.ui26
-rw-r--r--qt-ui/mainwindow.cpp2
5 files changed, 66 insertions, 7 deletions
diff --git a/divelist.c b/divelist.c
index 7efafa88c..9034007b7 100644
--- a/divelist.c
+++ b/divelist.c
@@ -347,7 +347,7 @@ double init_decompression(struct dive *dive)
{
int i, divenr = -1;
unsigned int surface_time;
- timestamp_t when, lasttime = 0;
+ timestamp_t when, lasttime = 0, laststart = 0;
bool deco_init = false;
double tissue_tolerance, surface_pressure;
@@ -370,8 +370,11 @@ double init_decompression(struct dive *dive)
* for how far back we need to go */
if (dive->divetrip && pdive->divetrip != dive->divetrip)
continue;
- if (!pdive || pdive->when > when || pdive->when + pdive->duration.seconds + 48 * 60 * 60 < when)
+ if (!pdive || pdive->when >= when || pdive->when + pdive->duration.seconds + 48 * 60 * 60 < when)
break;
+ /* For simultaneous dives, only consider the first */
+ if (pdive->when == laststart)
+ continue;
when = pdive->when;
lasttime = when + pdive->duration.seconds;
}
@@ -389,6 +392,7 @@ double init_decompression(struct dive *dive)
#endif
}
add_dive_to_deco(pdive);
+ laststart = pdive->when;
#if DECO_CALC_DEBUG & 2
printf("added dive #%d\n", pdive->number);
dump_tissues();
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index 4a299ca98..839c9d080 100644
--- a/qt-ui/diveplanner.cpp
+++ b/qt-ui/diveplanner.cpp
@@ -300,7 +300,9 @@ DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidg
connect(DivePlannerPointsModel::instance(), SIGNAL(startTimeChanged(QDateTime)), this, SLOT(setupStartTime(QDateTime)));
// Creating (and canceling) the plan
- connect(ui.buttonBox, SIGNAL(accepted()), plannerModel, SLOT(createPlan()));
+ replanButton = ui.buttonBox->addButton(tr("Save New"), QDialogButtonBox::ActionRole);
+ connect(replanButton, SIGNAL(clicked()), plannerModel, SLOT(saveDuplicatePlan()));
+ connect(ui.buttonBox, SIGNAL(accepted()), plannerModel, SLOT(savePlan()));
connect(ui.buttonBox, SIGNAL(rejected()), plannerModel, SLOT(cancelPlan()));
QShortcut *closeKey = new QShortcut(QKeySequence(Qt::Key_Escape), this);
connect(closeKey, SIGNAL(activated()), plannerModel, SLOT(cancelPlan()));
@@ -319,6 +321,11 @@ DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidg
setMinimumHeight(0);
}
+void DivePlannerWidget::setReplanButton(bool replan)
+{
+ replanButton->setVisible(replan);
+}
+
void DivePlannerWidget::setupStartTime(QDateTime startTime)
{
ui.startTime->setTime(startTime.time());
@@ -1168,7 +1175,17 @@ void DivePlannerPointsModel::deleteTemporaryPlan()
free_dps(&diveplan);
}
-void DivePlannerPointsModel::createPlan()
+void DivePlannerPointsModel::savePlan()
+{
+ createPlan(false);
+}
+
+void DivePlannerPointsModel::saveDuplicatePlan()
+{
+ createPlan(true);
+}
+
+void DivePlannerPointsModel::createPlan(bool replanCopy)
{
// Ok, so, here the diveplan creates a dive
char *cache = NULL;
@@ -1188,6 +1205,15 @@ void DivePlannerPointsModel::createPlan()
displayed_dive.maxdepth.mm = 0;
displayed_dive.dc.maxdepth.mm = 0;
fixup_dive(&displayed_dive);
+ if (replanCopy) {
+ struct dive *copy = alloc_dive();
+ copy_dive(current_dive, copy);
+ copy->id = 0;
+ copy->divetrip = NULL;
+ if (current_dive->divetrip)
+ add_dive_to_trip(copy, current_dive->divetrip);
+ record_dive(copy);
+ }
copy_dive(&displayed_dive, current_dive);
}
mark_divelist_changed(true);
diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h
index da2f6526b..c613ae210 100644
--- a/qt-ui/diveplanner.h
+++ b/qt-ui/diveplanner.h
@@ -3,6 +3,7 @@
#include <QGraphicsPathItem>
#include <QAbstractTableModel>
+#include <QAbstractButton>
#include <QDateTime>
#include "dive.h"
@@ -80,7 +81,8 @@ slots:
void setDisplayRuntime(bool value);
void setDisplayDuration(bool value);
void setDisplayTransitions(bool value);
- void createPlan();
+ void savePlan();
+ void saveDuplicatePlan();
void remove(const QModelIndex &index);
void cancelPlan();
void createTemporaryPlan();
@@ -97,6 +99,7 @@ signals:
private:
explicit DivePlannerPointsModel(QObject *parent = 0);
bool addGas(struct gasmix mix);
+ void createPlan(bool replanCopy);
struct diveplan diveplan;
Mode mode;
bool recalc;
@@ -136,6 +139,7 @@ class DivePlannerWidget : public QWidget {
Q_OBJECT
public:
explicit DivePlannerWidget(QWidget *parent = 0, Qt::WindowFlags f = 0);
+ void setReplanButton(bool replan);
public
slots:
void setupStartTime(QDateTime startTime);
@@ -146,6 +150,7 @@ slots:
private:
Ui::DivePlanner ui;
+ QAbstractButton *replanButton;
};
#include "ui_plannerSettings.h"
diff --git a/qt-ui/diveplanner.ui b/qt-ui/diveplanner.ui
index b640d88dc..54abcc35a 100644
--- a/qt-ui/diveplanner.ui
+++ b/qt-ui/diveplanner.ui
@@ -100,7 +100,10 @@
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="sizePolicy">
- <sizepolicy hsizetype="Expanding" vsizetype="Preferred"/>
+ <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
</property>
<property name="text">
<string>Planned dive time</string>
@@ -109,6 +112,12 @@
</item>
<item row="1" column="1">
<widget class="QDialogButtonBox" name="buttonBox">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Save</set>
</property>
@@ -118,13 +127,26 @@
<layout class="QHBoxLayout" name="dateAndTime">
<item>
<widget class="QDateEdit" name="dateEdit">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
<property name="calendarPopup">
<bool>true</bool>
</property>
</widget>
</item>
<item>
- <widget class="QTimeEdit" name="startTime"/>
+ <widget class="QTimeEdit" name="startTime">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
</item>
</layout>
</item>
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index cc2d9704e..8a72bc898 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -466,6 +466,7 @@ void MainWindow::on_actionReplanDive_triggered()
ui.newProfile->setPlanState();
ui.newProfile->clearHandlers();
ui.infoPane->setCurrentIndex(PLANNERWIDGET);
+ ui.divePlannerWidget->setReplanButton(true);
DivePlannerPointsModel::instance()->loadFromDive(current_dive);
reset_cylinders(&displayed_dive, true);
ui.diveListPane->setCurrentIndex(1); // switch to the plan output
@@ -491,6 +492,7 @@ void MainWindow::on_actionDivePlanner_triggered()
DivePlannerPointsModel::instance()->setupStartTime();
DivePlannerPointsModel::instance()->createSimpleDive();
DivePictureModel::instance()->updateDivePictures();
+ ui.divePlannerWidget->setReplanButton(false);
ui.diveListPane->setCurrentIndex(1); // switch to the plan output
ui.globePane->setCurrentIndex(1);