2013-06-20 15:33:26 +00:00
|
|
|
|
#include "diveplanner.h"
|
2013-08-30 10:14:30 +00:00
|
|
|
|
#include "modeldelegates.h"
|
2013-08-30 19:43:10 +00:00
|
|
|
|
#include "mainwindow.h"
|
2014-05-29 00:01:18 +00:00
|
|
|
|
#include "planner.h"
|
2013-09-20 23:41:42 +00:00
|
|
|
|
#include "helpers.h"
|
2015-02-09 20:27:59 +00:00
|
|
|
|
#include "models.h"
|
2015-02-09 21:51:31 +00:00
|
|
|
|
#include "profile/profilewidget2.h"
|
2013-08-30 10:14:30 +00:00
|
|
|
|
|
2013-07-02 17:36:52 +00:00
|
|
|
|
#include <QGraphicsSceneMouseEvent>
|
2013-07-04 15:58:11 +00:00
|
|
|
|
#include <QMessageBox>
|
2013-08-28 10:48:46 +00:00
|
|
|
|
#include <QSettings>
|
2014-06-03 22:26:06 +00:00
|
|
|
|
#include <QShortcut>
|
2013-06-20 15:33:26 +00:00
|
|
|
|
|
2013-06-27 14:10:03 +00:00
|
|
|
|
#define TIME_INITIAL_MAX 30
|
|
|
|
|
|
2013-09-22 19:37:49 +00:00
|
|
|
|
#define MAX_DEPTH M_OR_FT(150, 450)
|
|
|
|
|
#define MIN_DEPTH M_OR_FT(20, 60)
|
2013-07-02 17:14:09 +00:00
|
|
|
|
|
2014-06-24 22:08:36 +00:00
|
|
|
|
#define UNIT_FACTOR ((prefs.units.length == units::METERS) ? 1000.0 / 60.0 : feet_to_mm(1.0) / 60.0)
|
|
|
|
|
|
2014-06-01 22:25:19 +00:00
|
|
|
|
QString gasToStr(struct gasmix gas)
|
2014-02-28 04:09:57 +00:00
|
|
|
|
{
|
2014-07-10 20:57:32 +00:00
|
|
|
|
uint o2 = (get_o2(&gas) + 5) / 10, he = (get_he(&gas) + 5) / 10;
|
2014-11-17 16:39:40 +00:00
|
|
|
|
QString result = gasmix_is_air(&gas) ? QObject::tr("AIR") : he == 0 ? (o2 == 100 ? QObject::tr("OXYGEN") : QString("EAN%1").arg(o2, 2, 10, QChar('0'))) : QString("%1/%2").arg(o2).arg(he);
|
2013-11-11 08:09:19 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
QString dpGasToStr(const divedatapoint &p)
|
2013-11-11 08:09:19 +00:00
|
|
|
|
{
|
2014-06-01 22:25:19 +00:00
|
|
|
|
return gasToStr(p.gasmix);
|
2013-08-30 18:06:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-26 19:34:06 +00:00
|
|
|
|
static DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
|
2013-07-04 13:06:52 +00:00
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
bool intLessThan(int a, int b)
|
|
|
|
|
{
|
2013-08-30 18:53:10 +00:00
|
|
|
|
return a <= b;
|
|
|
|
|
}
|
2014-02-28 04:09:57 +00:00
|
|
|
|
void DivePlannerPointsModel::removeSelectedPoints(const QVector<int> &rows)
|
2013-08-30 18:53:10 +00:00
|
|
|
|
{
|
2014-07-20 13:18:00 +00:00
|
|
|
|
if (!rows.count())
|
|
|
|
|
return;
|
2013-08-30 18:53:10 +00:00
|
|
|
|
int firstRow = rowCount() - rows.count();
|
|
|
|
|
QVector<int> v2 = rows;
|
|
|
|
|
std::sort(v2.begin(), v2.end(), intLessThan);
|
2015-02-03 18:44:37 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* If we end up having divepoints that are not within the dive
|
|
|
|
|
* profile, we need to just skip the removal to prevent
|
|
|
|
|
* crashing due to index out of range.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (rowCount() >= divepoints.count())
|
|
|
|
|
return;
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
beginRemoveRows(QModelIndex(), firstRow, rowCount() - 1);
|
|
|
|
|
for (int i = v2.count() - 1; i >= 0; i--) {
|
2013-08-30 18:53:10 +00:00
|
|
|
|
divepoints.remove(v2[i]);
|
|
|
|
|
}
|
|
|
|
|
endRemoveRows();
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-27 18:28:42 +00:00
|
|
|
|
void DivePlannerPointsModel::createSimpleDive()
|
2013-09-20 12:36:14 +00:00
|
|
|
|
{
|
2014-06-02 01:18:29 +00:00
|
|
|
|
struct gasmix gas = { 0 };
|
2014-07-03 21:45:01 +00:00
|
|
|
|
|
2014-07-26 14:29:40 +00:00
|
|
|
|
// initialize the start time in the plan
|
|
|
|
|
diveplan.when = displayed_dive.when;
|
|
|
|
|
|
2014-06-02 01:18:29 +00:00
|
|
|
|
if (isPlanner())
|
2014-05-27 18:28:42 +00:00
|
|
|
|
// let's use the gas from the first cylinder
|
2014-07-03 21:45:01 +00:00
|
|
|
|
gas = displayed_dive.cylinder[0].gasmix;
|
2014-06-02 01:18:29 +00:00
|
|
|
|
|
2014-06-27 06:04:47 +00:00
|
|
|
|
// If we're in drop_stone_mode, don't add a first point.
|
|
|
|
|
// It will be added implicit.
|
2014-07-09 21:37:30 +00:00
|
|
|
|
if (!prefs.drop_stone_mode)
|
2014-06-27 06:04:47 +00:00
|
|
|
|
plannerModel->addStop(M_OR_FT(15, 45), 1 * 60, &gas, 0, true);
|
|
|
|
|
|
2014-06-02 19:36:05 +00:00
|
|
|
|
plannerModel->addStop(M_OR_FT(15, 45), 40 * 60, &gas, 0, true);
|
2014-05-27 18:28:42 +00:00
|
|
|
|
if (!isPlanner()) {
|
2014-06-02 19:36:05 +00:00
|
|
|
|
plannerModel->addStop(M_OR_FT(5, 15), 42 * 60, &gas, 0, true);
|
|
|
|
|
plannerModel->addStop(M_OR_FT(5, 15), 45 * 60, &gas, 0, true);
|
2014-05-25 22:28:55 +00:00
|
|
|
|
}
|
2013-09-20 12:36:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-28 15:07:28 +00:00
|
|
|
|
void DivePlannerPointsModel::setupStartTime()
|
|
|
|
|
{
|
|
|
|
|
// if the latest dive is in the future, then start an hour after it ends
|
|
|
|
|
// otherwise start an hour from now
|
|
|
|
|
startTime = QDateTime::currentDateTimeUtc().addSecs(3600 + gettimezoneoffset());
|
|
|
|
|
if (dive_table.nr) {
|
|
|
|
|
struct dive *d = get_dive(dive_table.nr - 1);
|
|
|
|
|
time_t ends = d->when + d->duration.seconds;
|
|
|
|
|
time_t diff = ends - startTime.toTime_t();
|
|
|
|
|
if (diff > 0) {
|
|
|
|
|
startTime = startTime.addSecs(diff + 3600);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
emit startTimeChanged(startTime);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
void DivePlannerPointsModel::loadFromDive(dive *d)
|
2013-11-01 15:48:34 +00:00
|
|
|
|
{
|
2014-08-19 19:59:15 +00:00
|
|
|
|
bool oldRec = recalc;
|
|
|
|
|
recalc = false;
|
2014-07-03 05:38:08 +00:00
|
|
|
|
CylindersModel::instance()->updateDive();
|
2014-07-17 19:16:49 +00:00
|
|
|
|
duration_t lasttime = {};
|
2014-07-19 01:37:28 +00:00
|
|
|
|
struct gasmix gas;
|
2014-08-20 02:07:43 +00:00
|
|
|
|
free_dps(&diveplan);
|
2014-07-29 19:50:50 +00:00
|
|
|
|
diveplan.when = d->when;
|
2014-08-20 02:07:43 +00:00
|
|
|
|
// is this a "new" dive where we marked manually entered samples?
|
|
|
|
|
// if yes then the first sample should be marked
|
|
|
|
|
// if it is we only add the manually entered samples as waypoints to the diveplan
|
|
|
|
|
// otherwise we have to add all of them
|
|
|
|
|
bool hasMarkedSamples = d->dc.sample[0].manually_entered;
|
2014-07-06 19:56:37 +00:00
|
|
|
|
for (int i = 0; i < d->dc.samples - 1; i++) {
|
|
|
|
|
const sample &s = d->dc.sample[i];
|
2014-08-20 02:07:43 +00:00
|
|
|
|
if (s.time.seconds == 0 || (hasMarkedSamples && !s.manually_entered))
|
2013-11-15 20:41:00 +00:00
|
|
|
|
continue;
|
2014-07-17 19:16:50 +00:00
|
|
|
|
get_gas_at_time(d, &d->dc, lasttime, &gas);
|
2014-06-02 19:36:05 +00:00
|
|
|
|
plannerModel->addStop(s.depth.mm, s.time.seconds, &gas, 0, true);
|
2014-07-17 19:16:49 +00:00
|
|
|
|
lasttime = s.time;
|
2013-11-01 15:48:34 +00:00
|
|
|
|
}
|
2014-08-19 19:59:15 +00:00
|
|
|
|
recalc = oldRec;
|
|
|
|
|
emitDataChanged();
|
2013-11-01 15:48:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-29 00:01:18 +00:00
|
|
|
|
// copy the tanks from the current dive, or the default cylinder
|
|
|
|
|
// or an unknown cylinder
|
|
|
|
|
// setup the cylinder widget accordingly
|
|
|
|
|
void DivePlannerPointsModel::setupCylinders()
|
2014-05-08 21:36:45 +00:00
|
|
|
|
{
|
2014-07-03 21:45:01 +00:00
|
|
|
|
if (mode == PLAN && current_dive) {
|
2015-02-15 11:28:46 +00:00
|
|
|
|
// take the displayed cylinders from the selected dive as starting point
|
2014-07-03 21:45:01 +00:00
|
|
|
|
CylindersModel::instance()->copyFromDive(current_dive);
|
2015-02-15 11:28:46 +00:00
|
|
|
|
copy_cylinders(current_dive, &displayed_dive, !prefs.display_unused_tanks);
|
2014-07-04 18:40:02 +00:00
|
|
|
|
reset_cylinders(&displayed_dive, true);
|
2014-05-29 00:01:18 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2014-07-03 21:45:01 +00:00
|
|
|
|
if (!same_string(prefs.default_cylinder, "")) {
|
|
|
|
|
fill_default_cylinder(&displayed_dive.cylinder[0]);
|
|
|
|
|
} else {
|
|
|
|
|
// roughly an AL80
|
|
|
|
|
displayed_dive.cylinder[0].type.description = strdup(tr("unknown").toUtf8().constData());
|
|
|
|
|
displayed_dive.cylinder[0].type.size.mliter = 11100;
|
|
|
|
|
displayed_dive.cylinder[0].type.workingpressure.mbar = 207000;
|
|
|
|
|
}
|
2014-07-04 18:40:02 +00:00
|
|
|
|
reset_cylinders(&displayed_dive, false);
|
2014-07-03 21:45:01 +00:00
|
|
|
|
CylindersModel::instance()->copyFromDive(&displayed_dive);
|
2014-05-08 21:36:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
QStringList &DivePlannerPointsModel::getGasList()
|
2013-11-11 08:09:19 +00:00
|
|
|
|
{
|
|
|
|
|
static QStringList list;
|
|
|
|
|
list.clear();
|
2014-07-03 21:45:01 +00:00
|
|
|
|
for (int i = 0; i < MAX_CYLINDERS; i++) {
|
|
|
|
|
cylinder_t *cyl = &displayed_dive.cylinder[i];
|
|
|
|
|
if (cylinder_nodata(cyl))
|
|
|
|
|
break;
|
|
|
|
|
list.push_back(gasToStr(cyl->gasmix));
|
2013-11-11 08:09:19 +00:00
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-24 14:42:10 +00:00
|
|
|
|
void DivePlannerPointsModel::removeDeco()
|
|
|
|
|
{
|
2014-05-06 13:28:32 +00:00
|
|
|
|
bool oldrec = setRecalc(false);
|
2014-04-24 14:42:10 +00:00
|
|
|
|
QVector<int> computedPoints;
|
|
|
|
|
for (int i = 0; i < plannerModel->rowCount(); i++)
|
|
|
|
|
if (!plannerModel->at(i).entered)
|
|
|
|
|
computedPoints.push_back(i);
|
|
|
|
|
removeSelectedPoints(computedPoints);
|
2014-05-06 13:28:32 +00:00
|
|
|
|
setRecalc(oldrec);
|
2014-04-24 14:42:10 +00:00
|
|
|
|
}
|
2014-05-25 03:51:05 +00:00
|
|
|
|
|
2014-05-24 01:39:51 +00:00
|
|
|
|
#if 0
|
2013-09-19 03:19:49 +00:00
|
|
|
|
void DivePlannerGraphics::drawProfile()
|
2013-06-20 16:20:41 +00:00
|
|
|
|
{
|
2014-05-22 02:49:17 +00:00
|
|
|
|
// Code ported to the new profile is deleted. This part that I left here
|
|
|
|
|
// is because I didn't fully understood the reason of the magic with
|
|
|
|
|
// the plannerModel.
|
2014-04-17 08:54:55 +00:00
|
|
|
|
bool oldRecalc = plannerModel->setRecalc(false);
|
2014-04-24 14:42:10 +00:00
|
|
|
|
plannerModel->removeDeco();
|
2014-05-22 02:49:17 +00:00
|
|
|
|
// Here we plotted the old planner profile. why there's the magic with the plannerModel here?
|
2014-04-17 08:54:55 +00:00
|
|
|
|
plannerModel->setRecalc(oldRecalc);
|
2013-09-16 15:11:06 +00:00
|
|
|
|
plannerModel->deleteTemporaryPlan();
|
2013-06-20 15:37:41 +00:00
|
|
|
|
}
|
2014-05-24 01:39:51 +00:00
|
|
|
|
#endif
|
2013-06-20 15:37:41 +00:00
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
DiveHandler::DiveHandler() : QGraphicsEllipseItem()
|
2013-06-20 17:29:32 +00:00
|
|
|
|
{
|
2014-02-28 04:09:57 +00:00
|
|
|
|
setRect(-5, -5, 10, 10);
|
2014-05-23 22:50:09 +00:00
|
|
|
|
setFlags(ItemIgnoresTransformations | ItemIsSelectable | ItemIsMovable | ItemSendsGeometryChanges);
|
2013-06-27 22:52:58 +00:00
|
|
|
|
setBrush(Qt::white);
|
|
|
|
|
setZValue(2);
|
2015-01-18 16:34:00 +00:00
|
|
|
|
t.start();
|
2013-06-20 17:29:32 +00:00
|
|
|
|
}
|
2013-07-04 14:01:59 +00:00
|
|
|
|
|
2013-11-19 22:42:05 +00:00
|
|
|
|
int DiveHandler::parentIndex()
|
|
|
|
|
{
|
2014-05-24 01:39:51 +00:00
|
|
|
|
ProfileWidget2 *view = qobject_cast<ProfileWidget2 *>(scene()->views().first());
|
2013-11-19 22:42:05 +00:00
|
|
|
|
return view->handles.indexOf(this);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
void DiveHandler::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
|
2013-11-15 01:29:36 +00:00
|
|
|
|
{
|
|
|
|
|
QMenu m;
|
2013-11-19 22:42:05 +00:00
|
|
|
|
GasSelectionModel *model = GasSelectionModel::instance();
|
|
|
|
|
model->repopulate();
|
|
|
|
|
int rowCount = model->rowCount();
|
2014-02-28 04:09:57 +00:00
|
|
|
|
for (int i = 0; i < rowCount; i++) {
|
2013-11-19 22:42:05 +00:00
|
|
|
|
QAction *action = new QAction(&m);
|
2014-02-28 04:09:57 +00:00
|
|
|
|
action->setText(model->data(model->index(i, 0), Qt::DisplayRole).toString());
|
2013-11-19 22:42:05 +00:00
|
|
|
|
connect(action, SIGNAL(triggered(bool)), this, SLOT(changeGas()));
|
|
|
|
|
m.addAction(action);
|
|
|
|
|
}
|
2014-07-15 10:29:43 +00:00
|
|
|
|
// don't allow removing the last point
|
|
|
|
|
if (DivePlannerPointsModel::instance()->rowCount() > 1) {
|
|
|
|
|
m.addSeparator();
|
|
|
|
|
m.addAction(QObject::tr("Remove this point"), this, SLOT(selfRemove()));
|
|
|
|
|
m.exec(event->screenPos());
|
|
|
|
|
}
|
2013-11-15 01:29:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DiveHandler::selfRemove()
|
|
|
|
|
{
|
|
|
|
|
setSelected(true);
|
2014-05-24 01:39:51 +00:00
|
|
|
|
ProfileWidget2 *view = qobject_cast<ProfileWidget2 *>(scene()->views().first());
|
2013-11-15 01:29:36 +00:00
|
|
|
|
view->keyDeleteAction();
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-19 22:42:05 +00:00
|
|
|
|
void DiveHandler::changeGas()
|
|
|
|
|
{
|
2014-02-28 04:09:57 +00:00
|
|
|
|
QAction *action = qobject_cast<QAction *>(sender());
|
2013-11-19 22:42:05 +00:00
|
|
|
|
QModelIndex index = plannerModel->index(parentIndex(), DivePlannerPointsModel::GAS);
|
|
|
|
|
plannerModel->setData(index, action->text());
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-23 23:51:30 +00:00
|
|
|
|
void DiveHandler::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
2013-07-04 14:01:59 +00:00
|
|
|
|
{
|
2015-01-18 16:34:00 +00:00
|
|
|
|
if (t.elapsed() < 40)
|
|
|
|
|
return;
|
|
|
|
|
t.start();
|
|
|
|
|
|
2014-05-23 23:51:30 +00:00
|
|
|
|
ProfileWidget2 *view = qobject_cast<ProfileWidget2*>(scene()->views().first());
|
|
|
|
|
if(view->isPointOutOfBoundaries(event->scenePos()))
|
|
|
|
|
return;
|
2015-01-18 16:34:00 +00:00
|
|
|
|
|
2014-05-23 23:51:30 +00:00
|
|
|
|
QGraphicsEllipseItem::mouseMoveEvent(event);
|
|
|
|
|
emit moved();
|
2013-07-04 14:01:59 +00:00
|
|
|
|
}
|
2013-06-20 18:52:27 +00:00
|
|
|
|
|
2014-06-30 22:08:16 +00:00
|
|
|
|
void DiveHandler::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
|
{
|
|
|
|
|
QGraphicsItem::mousePressEvent(event);
|
|
|
|
|
emit clicked();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DiveHandler::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
|
{
|
|
|
|
|
QGraphicsItem::mouseReleaseEvent(event);
|
|
|
|
|
emit released();
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f)
|
2013-10-03 18:54:25 +00:00
|
|
|
|
{
|
|
|
|
|
ui.setupUi(this);
|
2014-07-16 16:35:22 +00:00
|
|
|
|
ui.dateEdit->setDisplayFormat(getDateFormat());
|
2014-07-10 23:06:46 +00:00
|
|
|
|
ui.tableWidget->setTitle(tr("Dive planner points"));
|
2013-10-03 18:54:25 +00:00
|
|
|
|
ui.tableWidget->setModel(DivePlannerPointsModel::instance());
|
2014-04-17 08:54:55 +00:00
|
|
|
|
DivePlannerPointsModel::instance()->setRecalc(true);
|
2013-10-03 18:54:25 +00:00
|
|
|
|
ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::GAS, new AirTypesDelegate(this));
|
2014-07-10 23:06:46 +00:00
|
|
|
|
ui.cylinderTableWidget->setTitle(tr("Available gases"));
|
2013-11-09 22:06:26 +00:00
|
|
|
|
ui.cylinderTableWidget->setModel(CylindersModel::instance());
|
2013-11-12 19:57:33 +00:00
|
|
|
|
QTableView *view = ui.cylinderTableWidget->view();
|
|
|
|
|
view->setColumnHidden(CylindersModel::START, true);
|
|
|
|
|
view->setColumnHidden(CylindersModel::END, true);
|
2014-03-22 14:13:58 +00:00
|
|
|
|
view->setColumnHidden(CylindersModel::DEPTH, false);
|
2014-01-15 17:52:42 +00:00
|
|
|
|
view->setItemDelegateForColumn(CylindersModel::TYPE, new TankInfoDelegate(this));
|
2013-11-10 12:02:53 +00:00
|
|
|
|
connect(ui.cylinderTableWidget, SIGNAL(addButtonClicked()), DivePlannerPointsModel::instance(), SLOT(addCylinder_clicked()));
|
2013-10-03 18:54:25 +00:00
|
|
|
|
connect(ui.tableWidget, SIGNAL(addButtonClicked()), DivePlannerPointsModel::instance(), SLOT(addStop()));
|
2013-11-14 19:39:35 +00:00
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
connect(CylindersModel::instance(), SIGNAL(dataChanged(QModelIndex, QModelIndex)),
|
2013-11-14 19:39:35 +00:00
|
|
|
|
GasSelectionModel::instance(), SLOT(repopulate()));
|
2014-02-28 04:09:57 +00:00
|
|
|
|
connect(CylindersModel::instance(), SIGNAL(rowsInserted(QModelIndex, int, int)),
|
2013-11-14 19:39:35 +00:00
|
|
|
|
GasSelectionModel::instance(), SLOT(repopulate()));
|
2014-02-28 04:09:57 +00:00
|
|
|
|
connect(CylindersModel::instance(), SIGNAL(rowsRemoved(QModelIndex, int, int)),
|
2013-11-14 19:39:35 +00:00
|
|
|
|
GasSelectionModel::instance(), SLOT(repopulate()));
|
2014-04-18 02:48:00 +00:00
|
|
|
|
connect(CylindersModel::instance(), SIGNAL(dataChanged(QModelIndex, QModelIndex)),
|
2014-05-22 00:38:26 +00:00
|
|
|
|
plannerModel, SIGNAL(cylinderModelEdited()));
|
2014-04-17 08:54:55 +00:00
|
|
|
|
connect(CylindersModel::instance(), SIGNAL(rowsInserted(QModelIndex, int, int)),
|
2014-05-22 00:38:26 +00:00
|
|
|
|
plannerModel, SIGNAL(cylinderModelEdited()));
|
2014-04-17 08:54:55 +00:00
|
|
|
|
connect(CylindersModel::instance(), SIGNAL(rowsRemoved(QModelIndex, int, int)),
|
2014-05-22 00:38:26 +00:00
|
|
|
|
plannerModel, SIGNAL(cylinderModelEdited()));
|
2013-11-14 19:39:35 +00:00
|
|
|
|
|
2014-07-10 23:06:46 +00:00
|
|
|
|
ui.tableWidget->setBtnToolTip(tr("Add dive data point"));
|
2013-11-14 18:55:35 +00:00
|
|
|
|
connect(ui.startTime, SIGNAL(timeChanged(QTime)), plannerModel, SLOT(setStartTime(QTime)));
|
2014-06-28 15:07:28 +00:00
|
|
|
|
connect(ui.dateEdit, SIGNAL(dateChanged(QDate)), plannerModel, SLOT(setStartDate(QDate)));
|
2014-06-26 15:04:39 +00:00
|
|
|
|
connect(ui.ATMPressure, SIGNAL(valueChanged(int)), this, SLOT(atmPressureChanged(int)));
|
|
|
|
|
connect(ui.atmHeight, SIGNAL(valueChanged(int)), this, SLOT(heightChanged(int)));
|
2014-11-12 22:33:40 +00:00
|
|
|
|
connect(ui.salinity, SIGNAL(valueChanged(double)), this, SLOT(salinityChanged(double)));
|
2014-06-28 15:07:28 +00:00
|
|
|
|
connect(DivePlannerPointsModel::instance(), SIGNAL(startTimeChanged(QDateTime)), this, SLOT(setupStartTime(QDateTime)));
|
2013-09-09 10:18:22 +00:00
|
|
|
|
|
2014-05-27 22:27:53 +00:00
|
|
|
|
// Creating (and canceling) the plan
|
2014-11-10 22:41:18 +00:00
|
|
|
|
replanButton = ui.buttonBox->addButton(tr("Save new"), QDialogButtonBox::ActionRole);
|
2014-11-04 11:15:27 +00:00
|
|
|
|
connect(replanButton, SIGNAL(clicked()), plannerModel, SLOT(saveDuplicatePlan()));
|
|
|
|
|
connect(ui.buttonBox, SIGNAL(accepted()), plannerModel, SLOT(savePlan()));
|
2013-10-03 18:54:25 +00:00
|
|
|
|
connect(ui.buttonBox, SIGNAL(rejected()), plannerModel, SLOT(cancelPlan()));
|
2014-06-03 22:26:06 +00:00
|
|
|
|
QShortcut *closeKey = new QShortcut(QKeySequence(Qt::Key_Escape), this);
|
|
|
|
|
connect(closeKey, SIGNAL(activated()), plannerModel, SLOT(cancelPlan()));
|
2013-09-16 14:38:41 +00:00
|
|
|
|
|
2014-07-11 20:42:43 +00:00
|
|
|
|
// This makes shure the spinbox gets a setMinimum(0) on it so we can't have negative time or depth.
|
2014-07-12 12:24:25 +00:00
|
|
|
|
ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::DEPTH, new SpinBoxDelegate(0, INT_MAX, 1, this));
|
|
|
|
|
ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::RUNTIME, new SpinBoxDelegate(0, INT_MAX, 1, this));
|
|
|
|
|
ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::DURATION, new SpinBoxDelegate(0, INT_MAX, 1, this));
|
2014-07-12 12:24:26 +00:00
|
|
|
|
ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::CCSETPOINT, new DoubleSpinBoxDelegate(0, 2, 0.1, this));
|
2014-07-11 20:42:43 +00:00
|
|
|
|
|
2013-09-09 10:18:22 +00:00
|
|
|
|
/* set defaults. */
|
2014-06-26 15:04:39 +00:00
|
|
|
|
ui.ATMPressure->setValue(1013);
|
|
|
|
|
ui.atmHeight->setValue(0);
|
2013-09-26 21:14:09 +00:00
|
|
|
|
|
|
|
|
|
setMinimumWidth(0);
|
|
|
|
|
setMinimumHeight(0);
|
2013-08-28 10:48:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-04 11:15:27 +00:00
|
|
|
|
void DivePlannerWidget::setReplanButton(bool replan)
|
|
|
|
|
{
|
|
|
|
|
replanButton->setVisible(replan);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-28 15:07:28 +00:00
|
|
|
|
void DivePlannerWidget::setupStartTime(QDateTime startTime)
|
|
|
|
|
{
|
|
|
|
|
ui.startTime->setTime(startTime.time());
|
|
|
|
|
ui.dateEdit->setDate(startTime.date());
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-09 06:43:00 +00:00
|
|
|
|
void DivePlannerWidget::settingsChanged()
|
|
|
|
|
{
|
2014-06-27 09:43:11 +00:00
|
|
|
|
// Adopt units
|
|
|
|
|
if (get_units()->length == units::FEET) {
|
|
|
|
|
ui.atmHeight->setSuffix("ft");
|
|
|
|
|
} else {
|
|
|
|
|
ui.atmHeight->setSuffix(("m"));
|
|
|
|
|
}
|
2014-08-03 20:24:56 +00:00
|
|
|
|
ui.atmHeight->blockSignals(true);
|
|
|
|
|
ui.atmHeight->setValue((int) get_depth_units((int) (log(1013.0 / plannerModel->getSurfacePressure()) * 7800000), NULL,NULL));
|
|
|
|
|
ui.atmHeight->blockSignals(false);
|
2013-12-09 06:43:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-10 12:02:53 +00:00
|
|
|
|
void DivePlannerPointsModel::addCylinder_clicked()
|
|
|
|
|
{
|
|
|
|
|
CylindersModel::instance()->add();
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-26 15:04:39 +00:00
|
|
|
|
void DivePlannerWidget::atmPressureChanged(const int pressure)
|
2013-08-26 16:18:21 +00:00
|
|
|
|
{
|
2014-06-26 15:04:39 +00:00
|
|
|
|
plannerModel->setSurfacePressure(pressure);
|
|
|
|
|
ui.atmHeight->blockSignals(true);
|
2014-08-03 20:24:56 +00:00
|
|
|
|
ui.atmHeight->setValue((int) get_depth_units((int) (log(1013.0 / pressure) * 7800000), NULL,NULL));
|
2014-06-26 15:04:39 +00:00
|
|
|
|
ui.atmHeight->blockSignals(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DivePlannerWidget::heightChanged(const int height)
|
|
|
|
|
{
|
|
|
|
|
int pressure = (int) (1013.0 * exp(- (double) units_to_depth((double) height) / 7800000.0));
|
|
|
|
|
ui.ATMPressure->blockSignals(true);
|
|
|
|
|
ui.ATMPressure->setValue(pressure);
|
|
|
|
|
ui.ATMPressure->blockSignals(false);
|
|
|
|
|
plannerModel->setSurfacePressure(pressure);
|
2013-08-26 16:18:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-12 22:33:40 +00:00
|
|
|
|
void DivePlannerWidget::salinityChanged(const double salinity)
|
|
|
|
|
{
|
|
|
|
|
/* Salinity is expressed in weight in grams per 10l */
|
|
|
|
|
plannerModel->setSalinity(10000 * salinity);
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-19 16:13:55 +00:00
|
|
|
|
void PlannerSettingsWidget::bottomSacChanged(const double bottomSac)
|
2013-08-26 16:18:21 +00:00
|
|
|
|
{
|
2014-06-20 11:43:09 +00:00
|
|
|
|
plannerModel->setBottomSac(bottomSac);
|
2013-08-26 16:18:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-19 16:13:55 +00:00
|
|
|
|
void PlannerSettingsWidget::decoSacChanged(const double decosac)
|
2013-08-26 16:18:21 +00:00
|
|
|
|
{
|
2014-06-20 11:43:09 +00:00
|
|
|
|
plannerModel->setDecoSac(decosac);
|
2013-08-26 16:18:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-03 08:06:18 +00:00
|
|
|
|
void DivePlannerWidget::printDecoPlan()
|
|
|
|
|
{
|
|
|
|
|
MainWindow::instance()->printPlan();
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-10 15:40:02 +00:00
|
|
|
|
PlannerSettingsWidget::PlannerSettingsWidget(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f)
|
|
|
|
|
{
|
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
|
2014-07-15 18:39:13 +00:00
|
|
|
|
QSettings s;
|
2014-12-26 14:09:18 +00:00
|
|
|
|
QStringList rebreater_modes;
|
2014-07-15 18:39:13 +00:00
|
|
|
|
s.beginGroup("Planner");
|
2014-07-19 11:36:57 +00:00
|
|
|
|
prefs.ascrate75 = s.value("ascrate75", prefs.ascrate75).toInt();
|
|
|
|
|
prefs.ascrate50 = s.value("ascrate50", prefs.ascrate50).toInt();
|
|
|
|
|
prefs.ascratestops = s.value("ascratestops", prefs.ascratestops).toInt();
|
|
|
|
|
prefs.ascratelast6m = s.value("ascratelast6m", prefs.ascratelast6m).toInt();
|
|
|
|
|
prefs.descrate = s.value("descrate", prefs.descrate).toInt();
|
|
|
|
|
prefs.bottompo2 = s.value("bottompo2", prefs.bottompo2).toInt();
|
|
|
|
|
prefs.decopo2 = s.value("decopo2", prefs.decopo2).toInt();
|
|
|
|
|
prefs.doo2breaks = s.value("doo2breaks", prefs.doo2breaks).toBool();
|
|
|
|
|
prefs.drop_stone_mode = s.value("drop_stone_mode", prefs.drop_stone_mode).toBool();
|
|
|
|
|
prefs.bottomsac = s.value("bottomsac", prefs.bottomsac).toInt();
|
|
|
|
|
prefs.decosac = s.value("decosac", prefs.decosac).toInt();
|
2014-08-26 18:23:50 +00:00
|
|
|
|
plannerModel->getDiveplan().bottomsac = prefs.bottomsac;
|
|
|
|
|
plannerModel->getDiveplan().decosac = prefs.decosac;
|
2014-07-15 18:39:13 +00:00
|
|
|
|
s.endGroup();
|
|
|
|
|
|
2014-07-17 15:03:52 +00:00
|
|
|
|
updateUnitsUI();
|
2014-06-25 12:00:03 +00:00
|
|
|
|
ui.bottompo2->setValue(prefs.bottompo2 / 1000.0);
|
|
|
|
|
ui.decopo2->setValue(prefs.decopo2 / 1000.0);
|
2014-07-02 20:07:38 +00:00
|
|
|
|
ui.backgasBreaks->setChecked(prefs.doo2breaks);
|
2014-07-17 03:32:06 +00:00
|
|
|
|
ui.drop_stone_mode->setChecked(prefs.drop_stone_mode);
|
2015-01-16 14:05:00 +00:00
|
|
|
|
// should be the same order as in dive_comp_type!
|
|
|
|
|
rebreater_modes << tr("Open circuit") << tr("CCR") << tr("pSCR");
|
2014-12-26 14:09:18 +00:00
|
|
|
|
ui.rebreathermode->insertItems(0, rebreater_modes);
|
2014-06-24 22:08:36 +00:00
|
|
|
|
|
2014-06-10 15:40:02 +00:00
|
|
|
|
connect(ui.lastStop, SIGNAL(toggled(bool)), plannerModel, SLOT(setLastStop6m(bool)));
|
|
|
|
|
connect(ui.verbatim_plan, SIGNAL(toggled(bool)), plannerModel, SLOT(setVerbatim(bool)));
|
|
|
|
|
connect(ui.display_duration, SIGNAL(toggled(bool)), plannerModel, SLOT(setDisplayDuration(bool)));
|
|
|
|
|
connect(ui.display_runtime, SIGNAL(toggled(bool)), plannerModel, SLOT(setDisplayRuntime(bool)));
|
|
|
|
|
connect(ui.display_transitions, SIGNAL(toggled(bool)), plannerModel, SLOT(setDisplayTransitions(bool)));
|
2014-06-24 22:08:36 +00:00
|
|
|
|
connect(ui.ascRate75, SIGNAL(valueChanged(int)), this, SLOT(setAscRate75(int)));
|
|
|
|
|
connect(ui.ascRate75, SIGNAL(valueChanged(int)), plannerModel, SLOT(emitDataChanged()));
|
|
|
|
|
connect(ui.ascRate50, SIGNAL(valueChanged(int)), this, SLOT(setAscRate50(int)));
|
|
|
|
|
connect(ui.ascRate50, SIGNAL(valueChanged(int)), plannerModel, SLOT(emitDataChanged()));
|
|
|
|
|
connect(ui.ascRateStops, SIGNAL(valueChanged(int)), this, SLOT(setAscRateStops(int)));
|
|
|
|
|
connect(ui.ascRateStops, SIGNAL(valueChanged(int)), plannerModel, SLOT(emitDataChanged()));
|
|
|
|
|
connect(ui.ascRateLast6m, SIGNAL(valueChanged(int)), this, SLOT(setAscRateLast6m(int)));
|
|
|
|
|
connect(ui.ascRateLast6m, SIGNAL(valueChanged(int)), plannerModel, SLOT(emitDataChanged()));
|
2014-06-25 12:33:03 +00:00
|
|
|
|
connect(ui.descRate, SIGNAL(valueChanged(int)), this, SLOT(setDescRate(int)));
|
2014-06-24 22:08:36 +00:00
|
|
|
|
connect(ui.descRate, SIGNAL(valueChanged(int)), plannerModel, SLOT(emitDataChanged()));
|
2014-06-25 12:00:03 +00:00
|
|
|
|
connect(ui.bottompo2, SIGNAL(valueChanged(double)), this, SLOT(setBottomPo2(double)));
|
|
|
|
|
connect(ui.decopo2, SIGNAL(valueChanged(double)), this, SLOT(setDecoPo2(double)));
|
2014-06-26 15:04:39 +00:00
|
|
|
|
connect(ui.drop_stone_mode, SIGNAL(toggled(bool)), plannerModel, SLOT(setDropStoneMode(bool)));
|
2014-08-19 16:13:55 +00:00
|
|
|
|
connect(ui.bottomSAC, SIGNAL(valueChanged(double)), this, SLOT(bottomSacChanged(double)));
|
|
|
|
|
connect(ui.decoStopSAC, SIGNAL(valueChanged(double)), this, SLOT(decoSacChanged(double)));
|
2014-06-26 15:04:39 +00:00
|
|
|
|
connect(ui.gfhigh, SIGNAL(valueChanged(int)), plannerModel, SLOT(setGFHigh(int)));
|
|
|
|
|
connect(ui.gflow, SIGNAL(valueChanged(int)), plannerModel, SLOT(setGFLow(int)));
|
2014-08-05 15:06:17 +00:00
|
|
|
|
connect(ui.gfhigh, SIGNAL(editingFinished()), plannerModel, SLOT(triggerGFHigh()));
|
|
|
|
|
connect(ui.gflow, SIGNAL(editingFinished()), plannerModel, SLOT(triggerGFLow()));
|
2014-07-02 20:07:38 +00:00
|
|
|
|
connect(ui.backgasBreaks, SIGNAL(toggled(bool)), this, SLOT(setBackgasBreaks(bool)));
|
2015-01-16 14:05:00 +00:00
|
|
|
|
connect(ui.rebreathermode, SIGNAL(currentIndexChanged(int)), plannerModel, SLOT(setRebreatherMode(int)));
|
2014-08-19 16:13:55 +00:00
|
|
|
|
settingsChanged();
|
2014-06-26 15:04:39 +00:00
|
|
|
|
ui.gflow->setValue(prefs.gflow);
|
|
|
|
|
ui.gfhigh->setValue(prefs.gfhigh);
|
2014-06-10 15:40:02 +00:00
|
|
|
|
|
|
|
|
|
setMinimumWidth(0);
|
|
|
|
|
setMinimumHeight(0);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-17 15:03:52 +00:00
|
|
|
|
void PlannerSettingsWidget::updateUnitsUI()
|
|
|
|
|
{
|
|
|
|
|
ui.ascRate75->setValue(rint(prefs.ascrate75 / UNIT_FACTOR));
|
|
|
|
|
ui.ascRate50->setValue(rint(prefs.ascrate50 / UNIT_FACTOR));
|
|
|
|
|
ui.ascRateStops->setValue(rint(prefs.ascratestops / UNIT_FACTOR));
|
|
|
|
|
ui.ascRateLast6m->setValue(rint(prefs.ascratelast6m / UNIT_FACTOR));
|
|
|
|
|
ui.descRate->setValue(rint(prefs.descrate / UNIT_FACTOR));
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-15 18:39:13 +00:00
|
|
|
|
PlannerSettingsWidget::~PlannerSettingsWidget()
|
|
|
|
|
{
|
|
|
|
|
QSettings s;
|
|
|
|
|
s.beginGroup("Planner");
|
|
|
|
|
s.setValue("ascrate75", prefs.ascrate75);
|
|
|
|
|
s.setValue("ascrate50", prefs.ascrate50);
|
|
|
|
|
s.setValue("ascratestops", prefs.ascratestops);
|
|
|
|
|
s.setValue("ascratelast6m", prefs.ascratelast6m);
|
|
|
|
|
s.setValue("descrate", prefs.descrate);
|
|
|
|
|
s.setValue("bottompo2", prefs.bottompo2);
|
|
|
|
|
s.setValue("decopo2", prefs.decopo2);
|
|
|
|
|
s.setValue("doo2breaks", prefs.doo2breaks);
|
2014-07-17 03:32:06 +00:00
|
|
|
|
s.setValue("drop_stone_mode", prefs.drop_stone_mode);
|
|
|
|
|
s.setValue("bottomsac", prefs.bottomsac);
|
|
|
|
|
s.setValue("decosac", prefs.decosac);
|
2014-07-15 18:39:13 +00:00
|
|
|
|
s.endGroup();
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-10 15:40:02 +00:00
|
|
|
|
void PlannerSettingsWidget::settingsChanged()
|
|
|
|
|
{
|
2014-07-17 05:43:58 +00:00
|
|
|
|
QString vs;
|
2014-08-19 16:13:55 +00:00
|
|
|
|
// don't recurse into setting the value from the ui when setting the ui from the value
|
|
|
|
|
ui.bottomSAC->blockSignals(true);
|
|
|
|
|
ui.decoStopSAC->blockSignals(true);
|
2014-06-27 09:43:11 +00:00
|
|
|
|
if (get_units()->length == units::FEET) {
|
2014-07-17 05:43:58 +00:00
|
|
|
|
vs.append(tr("ft/min"));
|
2014-06-27 09:43:11 +00:00
|
|
|
|
ui.lastStop->setText(tr("Last stop at 20ft"));
|
2014-07-17 17:45:55 +00:00
|
|
|
|
ui.asc50to6->setText(tr("50% avg. depth to 20ft"));
|
|
|
|
|
ui.asc6toSurf->setText(tr("20ft to surface"));
|
2014-06-27 09:43:11 +00:00
|
|
|
|
} else {
|
2014-07-17 05:43:58 +00:00
|
|
|
|
vs.append(tr("m/min"));
|
2014-06-27 09:43:11 +00:00
|
|
|
|
ui.lastStop->setText(tr("Last stop at 6m"));
|
2014-07-17 17:45:55 +00:00
|
|
|
|
ui.asc50to6->setText(tr("50% avg. depth to 6m"));
|
|
|
|
|
ui.asc6toSurf->setText(tr("6m to surface"));
|
2014-06-27 09:43:11 +00:00
|
|
|
|
}
|
2014-08-06 08:16:12 +00:00
|
|
|
|
if(get_units()->volume == units::CUFT) {
|
|
|
|
|
ui.bottomSAC->setSuffix(tr("cuft/min"));
|
|
|
|
|
ui.decoStopSAC->setSuffix(tr("cuft/min"));
|
2014-08-19 16:13:55 +00:00
|
|
|
|
ui.bottomSAC->setDecimals(2);
|
|
|
|
|
ui.bottomSAC->setSingleStep(0.1);
|
|
|
|
|
ui.decoStopSAC->setDecimals(2);
|
|
|
|
|
ui.decoStopSAC->setSingleStep(0.1);
|
|
|
|
|
ui.bottomSAC->setValue(ml_to_cuft(prefs.bottomsac));
|
|
|
|
|
ui.decoStopSAC->setValue(ml_to_cuft(prefs.decosac));
|
2014-08-06 08:16:12 +00:00
|
|
|
|
} else {
|
|
|
|
|
ui.bottomSAC->setSuffix(tr("ℓ/min"));
|
|
|
|
|
ui.decoStopSAC->setSuffix(tr("ℓ/min"));
|
2014-08-19 16:13:55 +00:00
|
|
|
|
ui.bottomSAC->setDecimals(0);
|
|
|
|
|
ui.bottomSAC->setSingleStep(1);
|
|
|
|
|
ui.decoStopSAC->setDecimals(0);
|
|
|
|
|
ui.decoStopSAC->setSingleStep(1);
|
|
|
|
|
ui.bottomSAC->setValue((double) prefs.bottomsac / 1000.0);
|
|
|
|
|
ui.decoStopSAC->setValue((double) prefs.decosac / 1000.0);
|
2014-08-06 08:16:12 +00:00
|
|
|
|
}
|
2014-08-19 16:13:55 +00:00
|
|
|
|
ui.bottomSAC->blockSignals(false);
|
|
|
|
|
ui.decoStopSAC->blockSignals(false);
|
2014-07-17 15:03:52 +00:00
|
|
|
|
updateUnitsUI();
|
2014-07-17 05:43:58 +00:00
|
|
|
|
ui.ascRate75->setSuffix(vs);
|
|
|
|
|
ui.ascRate50->setSuffix(vs);
|
|
|
|
|
ui.ascRateStops->setSuffix(vs);
|
|
|
|
|
ui.ascRateLast6m->setSuffix(vs);
|
|
|
|
|
ui.descRate->setSuffix(vs);
|
2014-06-10 15:40:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PlannerSettingsWidget::atmPressureChanged(const QString &pressure)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PlannerSettingsWidget::printDecoPlan()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-24 22:08:36 +00:00
|
|
|
|
void PlannerSettingsWidget::setAscRate75(int rate)
|
|
|
|
|
{
|
|
|
|
|
prefs.ascrate75 = rate * UNIT_FACTOR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PlannerSettingsWidget::setAscRate50(int rate)
|
|
|
|
|
{
|
|
|
|
|
prefs.ascrate50 = rate * UNIT_FACTOR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PlannerSettingsWidget::setAscRateStops(int rate)
|
|
|
|
|
{
|
|
|
|
|
prefs.ascratestops = rate * UNIT_FACTOR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PlannerSettingsWidget::setAscRateLast6m(int rate)
|
|
|
|
|
{
|
|
|
|
|
prefs.ascratelast6m = rate * UNIT_FACTOR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PlannerSettingsWidget::setDescRate(int rate)
|
|
|
|
|
{
|
|
|
|
|
prefs.descrate = rate * UNIT_FACTOR;
|
|
|
|
|
}
|
2014-06-10 15:40:02 +00:00
|
|
|
|
|
2014-06-25 12:00:03 +00:00
|
|
|
|
void PlannerSettingsWidget::setBottomPo2(double po2)
|
|
|
|
|
{
|
|
|
|
|
prefs.bottompo2 = (int) (po2 * 1000.0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PlannerSettingsWidget::setDecoPo2(double po2)
|
|
|
|
|
{
|
|
|
|
|
prefs.decopo2 = (int) (po2 * 1000.0);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-02 20:07:38 +00:00
|
|
|
|
void PlannerSettingsWidget::setBackgasBreaks(bool dobreaks)
|
|
|
|
|
{
|
|
|
|
|
prefs.doo2breaks = dobreaks;
|
2014-07-09 13:02:15 +00:00
|
|
|
|
plannerModel->emitDataChanged();
|
2014-07-02 20:07:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-25 12:00:03 +00:00
|
|
|
|
|
2013-11-09 00:09:46 +00:00
|
|
|
|
void DivePlannerPointsModel::setPlanMode(Mode m)
|
2013-09-19 02:33:53 +00:00
|
|
|
|
{
|
2013-11-09 00:09:46 +00:00
|
|
|
|
mode = m;
|
2014-06-10 16:11:34 +00:00
|
|
|
|
// the planner may reset our GF settings that are used to show deco
|
|
|
|
|
// reset them to what's in the preferences
|
|
|
|
|
if (m != PLAN)
|
|
|
|
|
set_gf(prefs.gflow, prefs.gfhigh, prefs.gf_low_at_maxdepth);
|
2013-09-19 02:33:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DivePlannerPointsModel::isPlanner()
|
|
|
|
|
{
|
|
|
|
|
return mode == PLAN;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-18 14:08:33 +00:00
|
|
|
|
/* When the planner adds deco stops to the model, adding those should not trigger a new deco calculation.
|
|
|
|
|
* We thus start the planner only when recalc is true. */
|
|
|
|
|
|
2014-04-17 08:54:55 +00:00
|
|
|
|
bool DivePlannerPointsModel::setRecalc(bool rec)
|
|
|
|
|
{
|
|
|
|
|
bool old = recalc;
|
|
|
|
|
recalc = rec;
|
|
|
|
|
return old;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DivePlannerPointsModel::recalcQ()
|
|
|
|
|
{
|
|
|
|
|
return recalc;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
int DivePlannerPointsModel::columnCount(const QModelIndex &parent) const
|
2013-08-26 12:14:19 +00:00
|
|
|
|
{
|
2014-10-19 14:07:07 +00:00
|
|
|
|
return COLUMNS; // to disable CCSETPOINT subtract one
|
2013-08-26 12:14:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
QVariant DivePlannerPointsModel::data(const QModelIndex &index, int role) const
|
2013-08-26 12:14:19 +00:00
|
|
|
|
{
|
2014-05-30 02:51:25 +00:00
|
|
|
|
divedatapoint p = divepoints.at(index.row());
|
2014-06-03 18:44:05 +00:00
|
|
|
|
if (role == Qt::DisplayRole || role == Qt::EditRole) {
|
2014-01-16 04:50:56 +00:00
|
|
|
|
switch (index.column()) {
|
2014-02-28 04:09:57 +00:00
|
|
|
|
case CCSETPOINT:
|
2014-10-19 14:07:07 +00:00
|
|
|
|
return (double)p.setpoint / 1000;
|
2014-02-28 04:09:57 +00:00
|
|
|
|
case DEPTH:
|
2014-07-11 20:42:43 +00:00
|
|
|
|
return (int) rint(get_depth_units(p.depth, NULL, NULL));
|
2014-04-17 08:54:55 +00:00
|
|
|
|
case RUNTIME:
|
2014-02-28 04:09:57 +00:00
|
|
|
|
return p.time / 60;
|
2014-04-17 08:54:55 +00:00
|
|
|
|
case DURATION:
|
|
|
|
|
if (index.row())
|
2014-04-17 15:06:11 +00:00
|
|
|
|
return (p.time - divepoints.at(index.row() - 1).time) / 60;
|
2014-04-17 08:54:55 +00:00
|
|
|
|
else
|
|
|
|
|
return p.time / 60;
|
2014-02-28 04:09:57 +00:00
|
|
|
|
case GAS:
|
|
|
|
|
return dpGasToStr(p);
|
2013-08-26 16:18:21 +00:00
|
|
|
|
}
|
2013-09-22 19:34:50 +00:00
|
|
|
|
} else if (role == Qt::DecorationRole) {
|
2014-01-16 04:50:56 +00:00
|
|
|
|
switch (index.column()) {
|
2014-02-28 04:09:57 +00:00
|
|
|
|
case REMOVE:
|
2014-07-15 10:29:43 +00:00
|
|
|
|
if (rowCount() > 1)
|
2014-10-19 14:15:20 +00:00
|
|
|
|
return p.entered ? trashIcon() : QVariant();
|
|
|
|
|
}
|
|
|
|
|
} else if (role == Qt::SizeHintRole) {
|
|
|
|
|
switch (index.column()) {
|
|
|
|
|
case REMOVE:
|
|
|
|
|
if (rowCount() > 1)
|
|
|
|
|
return p.entered ? trashIcon().size() : QVariant();
|
2013-08-28 10:27:59 +00:00
|
|
|
|
}
|
2013-09-22 19:34:50 +00:00
|
|
|
|
} else if (role == Qt::FontRole) {
|
2014-04-17 08:54:55 +00:00
|
|
|
|
if (divepoints.at(index.row()).entered) {
|
|
|
|
|
return defaultModelFont();
|
|
|
|
|
} else {
|
|
|
|
|
QFont font = defaultModelFont();
|
|
|
|
|
font.setBold(true);
|
|
|
|
|
return font;
|
|
|
|
|
}
|
2013-09-02 19:21:08 +00:00
|
|
|
|
}
|
2013-08-26 12:14:19 +00:00
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
bool DivePlannerPointsModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
2013-08-30 10:14:30 +00:00
|
|
|
|
{
|
2014-06-01 21:17:06 +00:00
|
|
|
|
struct gasmix gas = { 0 };
|
2014-05-31 11:53:18 +00:00
|
|
|
|
int i, shift;
|
2014-01-16 04:50:56 +00:00
|
|
|
|
if (role == Qt::EditRole) {
|
2014-02-28 04:09:57 +00:00
|
|
|
|
divedatapoint &p = divepoints[index.row()];
|
2014-01-16 04:50:56 +00:00
|
|
|
|
switch (index.column()) {
|
2014-02-28 04:09:57 +00:00
|
|
|
|
case DEPTH:
|
2014-07-07 11:51:20 +00:00
|
|
|
|
if (value.toInt() >= 0)
|
|
|
|
|
p.depth = units_to_depth(value.toInt());
|
2014-02-28 04:09:57 +00:00
|
|
|
|
break;
|
2014-04-17 08:54:55 +00:00
|
|
|
|
case RUNTIME:
|
2014-02-28 04:09:57 +00:00
|
|
|
|
p.time = value.toInt() * 60;
|
|
|
|
|
break;
|
2014-04-17 08:54:55 +00:00
|
|
|
|
case DURATION:
|
2014-05-31 11:53:18 +00:00
|
|
|
|
i = index.row();
|
|
|
|
|
if (i)
|
|
|
|
|
shift = divepoints[i].time - divepoints[i - 1].time - value.toInt() * 60;
|
2014-04-17 08:54:55 +00:00
|
|
|
|
else
|
2014-05-31 11:53:18 +00:00
|
|
|
|
shift = divepoints[i].time - value.toInt() * 60;
|
|
|
|
|
while (i < divepoints.size())
|
|
|
|
|
divepoints[i++].time -= shift;
|
2014-04-17 08:54:55 +00:00
|
|
|
|
break;
|
2013-11-08 12:22:59 +00:00
|
|
|
|
case CCSETPOINT: {
|
|
|
|
|
int po2 = 0;
|
|
|
|
|
QByteArray gasv = value.toByteArray();
|
|
|
|
|
if (validate_po2(gasv.data(), &po2))
|
2014-10-19 14:07:07 +00:00
|
|
|
|
p.setpoint = po2;
|
2014-02-28 04:09:57 +00:00
|
|
|
|
} break;
|
2013-11-12 02:19:04 +00:00
|
|
|
|
case GAS:
|
2013-11-08 12:22:59 +00:00
|
|
|
|
QByteArray gasv = value.toByteArray();
|
2014-06-01 22:25:19 +00:00
|
|
|
|
if (validate_gas(gasv.data(), &gas))
|
|
|
|
|
p.gasmix = gas;
|
2013-11-08 12:22:59 +00:00
|
|
|
|
break;
|
2013-08-30 16:27:15 +00:00
|
|
|
|
}
|
|
|
|
|
editStop(index.row(), p);
|
|
|
|
|
}
|
2013-08-30 18:06:26 +00:00
|
|
|
|
return QAbstractItemModel::setData(index, value, role);
|
2013-08-30 10:14:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-26 12:14:19 +00:00
|
|
|
|
QVariant DivePlannerPointsModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
|
|
|
{
|
2013-09-22 19:34:50 +00:00
|
|
|
|
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
|
2014-01-16 04:50:56 +00:00
|
|
|
|
switch (section) {
|
2014-02-28 04:09:57 +00:00
|
|
|
|
case DEPTH:
|
2014-07-10 23:06:46 +00:00
|
|
|
|
return tr("Final depth");
|
2014-04-17 08:54:55 +00:00
|
|
|
|
case RUNTIME:
|
|
|
|
|
return tr("Run time");
|
2014-02-28 04:09:57 +00:00
|
|
|
|
case DURATION:
|
|
|
|
|
return tr("Duration");
|
|
|
|
|
case GAS:
|
2014-07-10 23:06:46 +00:00
|
|
|
|
return tr("Used gas");
|
2014-02-28 04:09:57 +00:00
|
|
|
|
case CCSETPOINT:
|
2014-07-10 23:06:46 +00:00
|
|
|
|
return tr("CC set point");
|
2013-08-26 12:14:19 +00:00
|
|
|
|
}
|
2013-09-22 19:34:50 +00:00
|
|
|
|
} else if (role == Qt::FontRole) {
|
2014-02-28 04:09:57 +00:00
|
|
|
|
return defaultModelFont();
|
2013-09-02 19:21:08 +00:00
|
|
|
|
}
|
2013-08-26 12:14:19 +00:00
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
Qt::ItemFlags DivePlannerPointsModel::flags(const QModelIndex &index) const
|
2013-08-30 10:14:30 +00:00
|
|
|
|
{
|
2014-05-31 11:53:18 +00:00
|
|
|
|
if (index.column() != REMOVE)
|
2014-04-17 08:54:55 +00:00
|
|
|
|
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
|
|
|
|
|
else
|
|
|
|
|
return QAbstractItemModel::flags(index);
|
2013-08-30 10:14:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
int DivePlannerPointsModel::rowCount(const QModelIndex &parent) const
|
2013-08-26 12:14:19 +00:00
|
|
|
|
{
|
2013-08-26 16:18:21 +00:00
|
|
|
|
return divepoints.count();
|
2013-08-26 12:14:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-05 15:06:17 +00:00
|
|
|
|
DivePlannerPointsModel::DivePlannerPointsModel(QObject *parent) : QAbstractTableModel(parent),
|
|
|
|
|
mode(NOTHING),
|
|
|
|
|
tempGFHigh(100),
|
|
|
|
|
tempGFLow(100)
|
2013-08-26 12:14:19 +00:00
|
|
|
|
{
|
2014-02-09 18:30:52 +00:00
|
|
|
|
memset(&diveplan, 0, sizeof(diveplan));
|
2013-08-26 12:14:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
DivePlannerPointsModel *DivePlannerPointsModel::instance()
|
2013-08-26 12:14:19 +00:00
|
|
|
|
{
|
2013-11-30 17:18:04 +00:00
|
|
|
|
static QScopedPointer<DivePlannerPointsModel> self(new DivePlannerPointsModel());
|
|
|
|
|
return self.data();
|
2013-08-26 12:14:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-04 16:34:08 +00:00
|
|
|
|
void DivePlannerPointsModel::emitDataChanged()
|
|
|
|
|
{
|
|
|
|
|
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-19 16:13:55 +00:00
|
|
|
|
void DivePlannerPointsModel::setBottomSac(double sac)
|
2013-08-26 16:18:21 +00:00
|
|
|
|
{
|
2014-08-19 16:13:55 +00:00
|
|
|
|
diveplan.bottomsac = units_to_sac(sac);
|
2014-07-17 03:32:06 +00:00
|
|
|
|
prefs.bottomsac = diveplan.bottomsac;
|
2014-02-28 04:09:57 +00:00
|
|
|
|
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
|
2013-08-26 16:18:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-19 16:13:55 +00:00
|
|
|
|
void DivePlannerPointsModel::setDecoSac(double sac)
|
2013-08-26 16:18:21 +00:00
|
|
|
|
{
|
2014-08-06 08:16:12 +00:00
|
|
|
|
diveplan.decosac = units_to_sac(sac);
|
2014-07-17 03:32:06 +00:00
|
|
|
|
prefs.decosac = diveplan.decosac;
|
2014-02-28 04:09:57 +00:00
|
|
|
|
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
|
2013-08-26 16:18:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-14 18:55:33 +00:00
|
|
|
|
void DivePlannerPointsModel::setGFHigh(const int gfhigh)
|
2013-08-26 16:18:21 +00:00
|
|
|
|
{
|
2014-08-05 15:06:17 +00:00
|
|
|
|
tempGFHigh = gfhigh;
|
|
|
|
|
// GFHigh <= 34 can cause infinite deco at 6m - don't trigger a recalculation
|
|
|
|
|
// for smaller GFHigh unless the user explicitly leaves the field
|
|
|
|
|
if (tempGFHigh > 34)
|
|
|
|
|
triggerGFHigh();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DivePlannerPointsModel::triggerGFHigh()
|
|
|
|
|
{
|
|
|
|
|
if (diveplan.gfhigh != tempGFHigh) {
|
|
|
|
|
diveplan.gfhigh = tempGFHigh;
|
|
|
|
|
plannerModel->emitDataChanged();
|
|
|
|
|
}
|
2013-08-26 16:18:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-14 18:55:33 +00:00
|
|
|
|
void DivePlannerPointsModel::setGFLow(const int ghflow)
|
2013-08-26 16:18:21 +00:00
|
|
|
|
{
|
2014-08-05 15:06:17 +00:00
|
|
|
|
tempGFLow = ghflow;
|
|
|
|
|
triggerGFLow();
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-16 14:05:00 +00:00
|
|
|
|
void DivePlannerPointsModel::setRebreatherMode(int mode)
|
2014-12-26 14:09:18 +00:00
|
|
|
|
{
|
2015-01-16 14:05:00 +00:00
|
|
|
|
int i;
|
|
|
|
|
displayed_dive.dc.divemode = (dive_comp_type) mode;
|
|
|
|
|
for (i=0; i < rowCount(); i++)
|
|
|
|
|
divepoints[i].setpoint = mode == CCR ? prefs.defaultsetpoint : 0;
|
|
|
|
|
emitDataChanged();
|
2014-12-26 14:09:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-05 15:06:17 +00:00
|
|
|
|
void DivePlannerPointsModel::triggerGFLow()
|
|
|
|
|
{
|
|
|
|
|
if (diveplan.gflow != tempGFLow) {
|
|
|
|
|
diveplan.gflow = tempGFLow;
|
|
|
|
|
plannerModel->emitDataChanged();
|
|
|
|
|
}
|
2013-08-26 16:18:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DivePlannerPointsModel::setSurfacePressure(int pressure)
|
|
|
|
|
{
|
|
|
|
|
diveplan.surface_pressure = pressure;
|
2014-02-28 04:09:57 +00:00
|
|
|
|
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
|
2013-08-26 16:18:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-12 22:33:40 +00:00
|
|
|
|
void DivePlannerPointsModel::setSalinity(int salinity)
|
|
|
|
|
{
|
|
|
|
|
diveplan.salinity = salinity;
|
|
|
|
|
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-03 20:24:56 +00:00
|
|
|
|
int DivePlannerPointsModel::getSurfacePressure()
|
|
|
|
|
{
|
|
|
|
|
return diveplan.surface_pressure;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-26 16:18:21 +00:00
|
|
|
|
void DivePlannerPointsModel::setLastStop6m(bool value)
|
|
|
|
|
{
|
2013-11-09 21:08:42 +00:00
|
|
|
|
set_last_stop(value);
|
2014-02-28 04:09:57 +00:00
|
|
|
|
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
|
2013-08-26 16:18:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-02 14:25:58 +00:00
|
|
|
|
void DivePlannerPointsModel::setVerbatim(bool value)
|
|
|
|
|
{
|
|
|
|
|
set_verbatim(value);
|
|
|
|
|
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DivePlannerPointsModel::setDisplayRuntime(bool value)
|
|
|
|
|
{
|
|
|
|
|
set_display_runtime(value);
|
|
|
|
|
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DivePlannerPointsModel::setDisplayDuration(bool value)
|
|
|
|
|
{
|
|
|
|
|
set_display_duration(value);
|
|
|
|
|
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DivePlannerPointsModel::setDisplayTransitions(bool value)
|
|
|
|
|
{
|
|
|
|
|
set_display_transitions(value);
|
|
|
|
|
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-23 17:21:29 +00:00
|
|
|
|
void DivePlannerPointsModel::setDropStoneMode(bool value)
|
|
|
|
|
{
|
2014-07-09 21:37:30 +00:00
|
|
|
|
prefs.drop_stone_mode = value;
|
|
|
|
|
if (prefs.drop_stone_mode) {
|
2014-06-23 17:21:29 +00:00
|
|
|
|
/* Remove the first entry if we enable drop_stone_mode */
|
|
|
|
|
if (rowCount() >= 2) {
|
|
|
|
|
beginRemoveRows(QModelIndex(), 0, 0);
|
|
|
|
|
divepoints.remove(0);
|
|
|
|
|
endRemoveRows();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/* Add a first entry if we disable drop_stone_mode */
|
|
|
|
|
beginInsertRows(QModelIndex(), 0, 0);
|
|
|
|
|
/* Copy the first current point */
|
|
|
|
|
divedatapoint p = divepoints.at(0);
|
2014-06-25 12:33:04 +00:00
|
|
|
|
p.time = p.depth / prefs.descrate;
|
2014-06-23 17:21:29 +00:00
|
|
|
|
divepoints.push_front(p);
|
|
|
|
|
endInsertRows();
|
|
|
|
|
}
|
|
|
|
|
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-28 15:07:28 +00:00
|
|
|
|
void DivePlannerPointsModel::setStartDate(const QDate &date)
|
|
|
|
|
{
|
|
|
|
|
startTime.setDate(date);
|
|
|
|
|
diveplan.when = startTime.toTime_t();
|
2014-08-20 03:10:27 +00:00
|
|
|
|
displayed_dive.when = diveplan.when;
|
2014-06-28 15:07:28 +00:00
|
|
|
|
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
void DivePlannerPointsModel::setStartTime(const QTime &t)
|
2013-08-26 16:18:21 +00:00
|
|
|
|
{
|
2014-06-28 15:07:28 +00:00
|
|
|
|
startTime.setTime(t);
|
|
|
|
|
diveplan.when = startTime.toTime_t();
|
2014-08-20 03:10:27 +00:00
|
|
|
|
displayed_dive.when = diveplan.when;
|
2014-02-28 04:09:57 +00:00
|
|
|
|
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
|
2013-08-26 16:18:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
bool divePointsLessThan(const divedatapoint &p1, const divedatapoint &p2)
|
2013-09-22 19:34:50 +00:00
|
|
|
|
{
|
2013-08-26 20:02:34 +00:00
|
|
|
|
return p1.time <= p2.time;
|
|
|
|
|
}
|
2013-09-22 19:34:50 +00:00
|
|
|
|
|
2014-06-02 01:18:29 +00:00
|
|
|
|
bool DivePlannerPointsModel::addGas(struct gasmix mix)
|
2013-11-12 02:19:04 +00:00
|
|
|
|
{
|
2014-05-25 16:01:16 +00:00
|
|
|
|
sanitize_gasmix(&mix);
|
|
|
|
|
|
2013-11-12 02:19:04 +00:00
|
|
|
|
for (int i = 0; i < MAX_CYLINDERS; i++) {
|
2014-07-03 21:45:01 +00:00
|
|
|
|
cylinder_t *cyl = &displayed_dive.cylinder[i];
|
2013-11-12 02:19:04 +00:00
|
|
|
|
if (cylinder_nodata(cyl)) {
|
2013-11-13 12:44:18 +00:00
|
|
|
|
fill_default_cylinder(cyl);
|
2014-06-02 01:18:29 +00:00
|
|
|
|
cyl->gasmix = mix;
|
2014-06-22 14:41:44 +00:00
|
|
|
|
/* The depth to change to that gas is given by the depth where its pO₂ is 1.6 bar.
|
2014-04-18 14:08:33 +00:00
|
|
|
|
* The user should be able to change this depth manually. */
|
2014-06-22 14:41:44 +00:00
|
|
|
|
pressure_t modpO2;
|
2015-01-16 12:02:26 +00:00
|
|
|
|
if (displayed_dive.dc.divemode == PSCR)
|
|
|
|
|
modpO2.mbar = prefs.decopo2 + (1000 - get_o2(&mix)) * SURFACE_PRESSURE *
|
|
|
|
|
prefs.o2consumption / prefs.decosac / prefs.pscr_ratio;
|
|
|
|
|
else
|
|
|
|
|
modpO2.mbar = prefs.decopo2;
|
2014-06-25 13:36:30 +00:00
|
|
|
|
cyl->depth = gas_mod(&mix, modpO2, M_OR_FT(3,10));
|
2014-06-25 12:00:03 +00:00
|
|
|
|
|
2014-07-03 05:38:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// FIXME -- need to get rid of stagingDIve
|
|
|
|
|
// the following now uses displayed_dive !!!!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CylindersModel::instance()->updateDive();
|
2013-11-12 02:19:04 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-05-25 16:01:16 +00:00
|
|
|
|
if (!gasmix_distance(&cyl->gasmix, &mix))
|
2013-11-12 02:19:04 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
qDebug("too many gases");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-17 08:54:55 +00:00
|
|
|
|
int DivePlannerPointsModel::lastEnteredPoint()
|
|
|
|
|
{
|
2014-04-17 15:06:11 +00:00
|
|
|
|
for (int i = divepoints.count() - 1; i >= 0; i--)
|
2014-04-17 08:54:55 +00:00
|
|
|
|
if (divepoints.at(i).entered)
|
|
|
|
|
return i;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-02 19:36:05 +00:00
|
|
|
|
int DivePlannerPointsModel::addStop(int milimeters, int seconds, gasmix *gas_in, int ccpoint, bool entered)
|
2013-08-26 16:18:21 +00:00
|
|
|
|
{
|
2014-06-02 01:18:29 +00:00
|
|
|
|
struct gasmix air = { 0 };
|
2014-06-02 19:36:05 +00:00
|
|
|
|
struct gasmix gas = { 0 };
|
|
|
|
|
bool usePrevious = false;
|
|
|
|
|
if (gas_in)
|
|
|
|
|
gas = *gas_in;
|
|
|
|
|
else
|
|
|
|
|
usePrevious = true;
|
2014-05-06 13:28:32 +00:00
|
|
|
|
if (recalcQ())
|
|
|
|
|
removeDeco();
|
|
|
|
|
|
2013-08-26 16:18:21 +00:00
|
|
|
|
int row = divepoints.count();
|
2014-01-16 04:50:56 +00:00
|
|
|
|
if (seconds == 0 && milimeters == 0 && row != 0) {
|
2013-11-15 02:54:13 +00:00
|
|
|
|
/* this is only possible if the user clicked on the 'plus' sign on the DivePoints Table */
|
2014-04-17 08:54:55 +00:00
|
|
|
|
const divedatapoint t = divepoints.at(lastEnteredPoint());
|
2013-11-15 02:54:13 +00:00
|
|
|
|
milimeters = t.depth;
|
2013-12-04 04:55:00 +00:00
|
|
|
|
seconds = t.time + 600; // 10 minutes.
|
2014-06-02 01:18:29 +00:00
|
|
|
|
gas = t.gasmix;
|
2014-10-19 14:07:07 +00:00
|
|
|
|
ccpoint = t.setpoint;
|
2013-12-04 04:55:00 +00:00
|
|
|
|
} else if (seconds == 0 && milimeters == 0 && row == 0) {
|
2013-11-15 02:54:13 +00:00
|
|
|
|
milimeters = M_OR_FT(5, 15); // 5m / 15ft
|
2014-02-28 04:09:57 +00:00
|
|
|
|
seconds = 600; // 10 min
|
2013-12-07 22:54:19 +00:00
|
|
|
|
//Default to the first defined gas, if we got one.
|
2014-07-03 21:45:01 +00:00
|
|
|
|
cylinder_t *cyl = &displayed_dive.cylinder[0];
|
2014-06-02 01:18:29 +00:00
|
|
|
|
if (cyl)
|
|
|
|
|
gas = cyl->gasmix;
|
2013-11-14 20:06:08 +00:00
|
|
|
|
}
|
2014-06-02 01:18:29 +00:00
|
|
|
|
if (!usePrevious)
|
|
|
|
|
if (!addGas(gas))
|
2013-11-12 02:19:04 +00:00
|
|
|
|
qDebug("addGas failed"); // FIXME add error propagation
|
2013-09-09 22:57:22 +00:00
|
|
|
|
|
2013-08-26 19:55:30 +00:00
|
|
|
|
// check if there's already a new stop before this one:
|
2013-11-09 11:33:33 +00:00
|
|
|
|
for (int i = 0; i < row; i++) {
|
2014-02-28 04:09:57 +00:00
|
|
|
|
const divedatapoint &dp = divepoints.at(i);
|
2013-12-04 04:55:00 +00:00
|
|
|
|
if (dp.time == seconds) {
|
2013-11-08 12:22:59 +00:00
|
|
|
|
row = i;
|
|
|
|
|
beginRemoveRows(QModelIndex(), row, row);
|
|
|
|
|
divepoints.remove(row);
|
|
|
|
|
endRemoveRows();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2014-02-28 04:09:57 +00:00
|
|
|
|
if (dp.time > seconds) {
|
2013-08-26 20:02:34 +00:00
|
|
|
|
row = i;
|
|
|
|
|
break;
|
2013-08-26 19:55:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-07-05 11:54:08 +00:00
|
|
|
|
// Previous, actually means next as we are typically subdiving a segment and the gas for
|
|
|
|
|
// the segment is determined by the waypoint at the end.
|
2014-06-02 01:18:29 +00:00
|
|
|
|
if (usePrevious) {
|
2014-07-05 11:54:08 +00:00
|
|
|
|
if (row < divepoints.count()) {
|
|
|
|
|
gas = divepoints.at(row).gasmix;
|
2014-07-15 10:20:23 +00:00
|
|
|
|
} else if (row > 0) {
|
|
|
|
|
gas = divepoints.at(row - 1).gasmix;
|
2013-11-15 02:54:13 +00:00
|
|
|
|
} else {
|
2014-07-05 11:54:08 +00:00
|
|
|
|
if (!addGas(air))
|
|
|
|
|
qDebug("addGas failed"); // FIXME add error propagation
|
|
|
|
|
|
2013-11-15 02:54:13 +00:00
|
|
|
|
}
|
2013-11-11 09:13:55 +00:00
|
|
|
|
}
|
2014-04-18 14:08:33 +00:00
|
|
|
|
|
2013-08-26 19:55:30 +00:00
|
|
|
|
// add the new stop
|
2013-08-26 16:18:21 +00:00
|
|
|
|
beginInsertRows(QModelIndex(), row, row);
|
|
|
|
|
divedatapoint point;
|
2013-09-22 19:37:49 +00:00
|
|
|
|
point.depth = milimeters;
|
2013-12-04 04:55:00 +00:00
|
|
|
|
point.time = seconds;
|
2014-06-02 01:18:29 +00:00
|
|
|
|
point.gasmix = gas;
|
2014-10-19 14:07:07 +00:00
|
|
|
|
point.setpoint = ccpoint;
|
2014-03-12 15:49:42 +00:00
|
|
|
|
point.entered = entered;
|
2014-06-11 21:07:57 +00:00
|
|
|
|
point.next = NULL;
|
2014-02-28 04:09:57 +00:00
|
|
|
|
divepoints.append(point);
|
2013-08-26 20:02:34 +00:00
|
|
|
|
std::sort(divepoints.begin(), divepoints.end(), divePointsLessThan);
|
2013-08-26 16:18:21 +00:00
|
|
|
|
endInsertRows();
|
|
|
|
|
return row;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-26 17:54:07 +00:00
|
|
|
|
void DivePlannerPointsModel::editStop(int row, divedatapoint newData)
|
|
|
|
|
{
|
2015-02-03 18:44:36 +00:00
|
|
|
|
/*
|
|
|
|
|
* When moving divepoints rigorously, we might end up with index
|
|
|
|
|
* out of range, thus returning the last one instead.
|
|
|
|
|
*/
|
|
|
|
|
if (row >= divepoints.count())
|
|
|
|
|
return;
|
2013-08-26 17:54:07 +00:00
|
|
|
|
divepoints[row] = newData;
|
2013-08-26 20:15:48 +00:00
|
|
|
|
std::sort(divepoints.begin(), divepoints.end(), divePointsLessThan);
|
2014-02-28 04:09:57 +00:00
|
|
|
|
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
|
2013-08-26 17:54:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-22 18:01:18 +00:00
|
|
|
|
int DivePlannerPointsModel::size()
|
|
|
|
|
{
|
|
|
|
|
return divepoints.size();
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-26 17:17:39 +00:00
|
|
|
|
divedatapoint DivePlannerPointsModel::at(int row)
|
|
|
|
|
{
|
2015-02-03 18:44:36 +00:00
|
|
|
|
/*
|
|
|
|
|
* When moving divepoints rigorously, we might end up with index
|
|
|
|
|
* out of range, thus returning the last one instead.
|
|
|
|
|
*/
|
|
|
|
|
if (row >= divepoints.count())
|
|
|
|
|
return divepoints.at(divepoints.count() - 1);
|
2013-08-26 17:17:39 +00:00
|
|
|
|
return divepoints.at(row);
|
|
|
|
|
}
|
2013-08-30 19:08:55 +00:00
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
void DivePlannerPointsModel::remove(const QModelIndex &index)
|
2013-08-30 19:08:55 +00:00
|
|
|
|
{
|
2014-08-21 21:01:56 +00:00
|
|
|
|
int i;
|
|
|
|
|
int rows = rowCount();
|
2014-07-15 10:29:43 +00:00
|
|
|
|
if (index.column() != REMOVE || rowCount() == 1)
|
2013-08-30 19:08:55 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2014-05-30 02:49:43 +00:00
|
|
|
|
divedatapoint dp = at(index.row());
|
|
|
|
|
if (!dp.entered)
|
|
|
|
|
return;
|
|
|
|
|
|
2014-08-21 21:01:56 +00:00
|
|
|
|
if (QApplication::keyboardModifiers() & Qt::ControlModifier) {
|
|
|
|
|
beginRemoveRows(QModelIndex(), index.row(), rows - 1);
|
|
|
|
|
for (i = rows - 1; i >= index.row(); i--)
|
|
|
|
|
divepoints.remove(i);
|
|
|
|
|
} else {
|
|
|
|
|
beginRemoveRows(QModelIndex(), index.row(), index.row());
|
|
|
|
|
divepoints.remove(index.row());
|
|
|
|
|
}
|
2013-08-30 19:08:55 +00:00
|
|
|
|
endRemoveRows();
|
|
|
|
|
}
|
2013-09-09 10:18:22 +00:00
|
|
|
|
|
2014-05-22 18:40:22 +00:00
|
|
|
|
struct diveplan &DivePlannerPointsModel::getDiveplan()
|
2013-09-09 10:18:22 +00:00
|
|
|
|
{
|
|
|
|
|
return diveplan;
|
|
|
|
|
}
|
2013-09-16 14:38:41 +00:00
|
|
|
|
|
|
|
|
|
void DivePlannerPointsModel::cancelPlan()
|
|
|
|
|
{
|
2013-09-22 19:34:50 +00:00
|
|
|
|
if (mode == PLAN && rowCount()) {
|
2014-07-10 23:06:46 +00:00
|
|
|
|
if (QMessageBox::warning(MainWindow::instance(), TITLE_OR_TEXT(tr("Discard the plan?"),
|
2014-02-28 04:09:57 +00:00
|
|
|
|
tr("You are about to discard your plan.")),
|
|
|
|
|
QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Discard) != QMessageBox::Discard) {
|
2013-10-05 20:55:01 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2013-09-16 14:38:41 +00:00
|
|
|
|
}
|
2013-11-09 00:09:46 +00:00
|
|
|
|
setPlanMode(NOTHING);
|
2014-08-19 16:41:09 +00:00
|
|
|
|
free_dps(&diveplan);
|
2014-07-03 21:45:01 +00:00
|
|
|
|
|
2014-05-28 18:43:32 +00:00
|
|
|
|
emit planCanceled();
|
2013-11-09 00:09:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DivePlannerPointsModel::Mode DivePlannerPointsModel::currentMode() const
|
|
|
|
|
{
|
|
|
|
|
return mode;
|
|
|
|
|
}
|
2013-09-16 14:38:41 +00:00
|
|
|
|
|
2013-12-24 12:18:56 +00:00
|
|
|
|
QVector<QPair<int, int> > DivePlannerPointsModel::collectGases(struct dive *d)
|
2013-11-13 12:45:54 +00:00
|
|
|
|
{
|
2013-12-24 12:18:56 +00:00
|
|
|
|
QVector<QPair<int, int> > l;
|
2013-11-13 12:45:54 +00:00
|
|
|
|
for (int i = 0; i < MAX_CYLINDERS; i++) {
|
|
|
|
|
cylinder_t *cyl = &d->cylinder[i];
|
|
|
|
|
if (!cylinder_nodata(cyl))
|
2014-05-25 16:01:16 +00:00
|
|
|
|
l.push_back(qMakePair(get_o2(&cyl->gasmix), get_he(&cyl->gasmix)));
|
2013-11-13 12:45:54 +00:00
|
|
|
|
}
|
|
|
|
|
return l;
|
|
|
|
|
}
|
|
|
|
|
void DivePlannerPointsModel::rememberTanks()
|
|
|
|
|
{
|
2014-07-03 21:45:01 +00:00
|
|
|
|
oldGases = collectGases(&displayed_dive);
|
2013-11-13 12:45:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-01 22:25:19 +00:00
|
|
|
|
bool DivePlannerPointsModel::tankInUse(struct gasmix gasmix)
|
2013-11-13 12:45:54 +00:00
|
|
|
|
{
|
|
|
|
|
for (int j = 0; j < rowCount(); j++) {
|
2014-02-28 04:09:57 +00:00
|
|
|
|
divedatapoint &p = divepoints[j];
|
2013-11-13 12:45:54 +00:00
|
|
|
|
if (p.time == 0) // special entries that hold the available gases
|
|
|
|
|
continue;
|
2014-04-17 08:54:55 +00:00
|
|
|
|
if (!p.entered) // removing deco gases is ok
|
|
|
|
|
continue;
|
2014-06-01 22:25:19 +00:00
|
|
|
|
if (gasmix_distance(&p.gasmix, &gasmix) < 200)
|
2013-11-13 12:45:54 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DivePlannerPointsModel::tanksUpdated()
|
|
|
|
|
{
|
2013-11-14 12:58:04 +00:00
|
|
|
|
// we don't know exactly what changed - what we care about is
|
|
|
|
|
// "did a gas change on us". So we look through the diveplan to
|
|
|
|
|
// see if there is a gas that is now missing and if there is, we
|
|
|
|
|
// replace it with the matching new gas.
|
2014-07-03 21:45:01 +00:00
|
|
|
|
QVector<QPair<int, int> > gases = collectGases(&displayed_dive);
|
2013-12-24 12:18:56 +00:00
|
|
|
|
if (gases.count() == oldGases.count()) {
|
2013-11-14 12:58:04 +00:00
|
|
|
|
// either nothing relevant changed, or exactly ONE gasmix changed
|
2013-12-24 12:18:56 +00:00
|
|
|
|
for (int i = 0; i < gases.count(); i++) {
|
2013-11-14 12:58:04 +00:00
|
|
|
|
if (gases.at(i) != oldGases.at(i)) {
|
|
|
|
|
if (oldGases.count(oldGases.at(i)) > 1) {
|
|
|
|
|
// we had this gas more than once, so don't
|
|
|
|
|
// change segments that used this gas as it still exists
|
2013-11-13 12:45:54 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2013-11-14 12:58:04 +00:00
|
|
|
|
for (int j = 0; j < rowCount(); j++) {
|
2014-02-28 04:09:57 +00:00
|
|
|
|
divedatapoint &p = divepoints[j];
|
2014-06-01 22:25:19 +00:00
|
|
|
|
struct gasmix gas;
|
|
|
|
|
gas.o2.permille = oldGases.at(i).first;
|
|
|
|
|
gas.he.permille = oldGases.at(i).second;
|
|
|
|
|
if (gasmix_distance(&gas, &p.gasmix) < 200) {
|
|
|
|
|
p.gasmix.o2.permille = gases.at(i).first;
|
|
|
|
|
p.gasmix.he.permille = gases.at(i).second;
|
2013-11-14 12:58:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2013-11-13 12:45:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-02-28 04:09:57 +00:00
|
|
|
|
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
|
2013-11-13 12:45:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-09 00:09:46 +00:00
|
|
|
|
void DivePlannerPointsModel::clear()
|
|
|
|
|
{
|
2014-05-30 23:12:35 +00:00
|
|
|
|
bool oldRecalc = setRecalc(false);
|
2014-07-03 05:38:08 +00:00
|
|
|
|
|
|
|
|
|
CylindersModel::instance()->updateDive();
|
2013-12-09 23:02:06 +00:00
|
|
|
|
if (rowCount() > 0) {
|
|
|
|
|
beginRemoveRows(QModelIndex(), 0, rowCount() - 1);
|
|
|
|
|
divepoints.clear();
|
|
|
|
|
endRemoveRows();
|
|
|
|
|
}
|
2013-11-10 12:02:53 +00:00
|
|
|
|
CylindersModel::instance()->clear();
|
2014-05-30 23:12:35 +00:00
|
|
|
|
setRecalc(oldRecalc);
|
2013-09-16 14:38:41 +00:00
|
|
|
|
}
|
2013-09-16 15:11:06 +00:00
|
|
|
|
|
|
|
|
|
void DivePlannerPointsModel::createTemporaryPlan()
|
|
|
|
|
{
|
|
|
|
|
// Get the user-input and calculate the dive info
|
2014-08-19 16:41:09 +00:00
|
|
|
|
free_dps(&diveplan);
|
2013-09-16 15:11:06 +00:00
|
|
|
|
int lastIndex = -1;
|
2013-09-22 19:34:50 +00:00
|
|
|
|
for (int i = 0; i < rowCount(); i++) {
|
2013-09-16 15:11:06 +00:00
|
|
|
|
divedatapoint p = at(i);
|
|
|
|
|
int deltaT = lastIndex != -1 ? p.time - at(lastIndex).time : p.time;
|
|
|
|
|
lastIndex = i;
|
2014-07-09 21:37:30 +00:00
|
|
|
|
if (i == 0 && prefs.drop_stone_mode) {
|
2014-06-23 17:21:29 +00:00
|
|
|
|
/* Okay, we add a fist segment where we go down to depth */
|
2014-10-19 14:07:07 +00:00
|
|
|
|
plan_add_segment(&diveplan, p.depth / prefs.descrate, p.depth, p.gasmix, p.setpoint, true);
|
2014-06-25 12:33:04 +00:00
|
|
|
|
deltaT -= p.depth / prefs.descrate;
|
2014-06-23 17:21:29 +00:00
|
|
|
|
}
|
2014-04-17 08:54:55 +00:00
|
|
|
|
if (p.entered)
|
2014-10-19 14:07:07 +00:00
|
|
|
|
plan_add_segment(&diveplan, deltaT, p.depth, p.gasmix, p.setpoint, true);
|
2013-09-16 15:11:06 +00:00
|
|
|
|
}
|
2014-07-03 21:45:01 +00:00
|
|
|
|
|
|
|
|
|
// what does the cache do???
|
2013-09-16 15:11:06 +00:00
|
|
|
|
char *cache = NULL;
|
2013-12-07 22:54:15 +00:00
|
|
|
|
struct divedatapoint *dp = NULL;
|
2013-11-12 02:19:04 +00:00
|
|
|
|
for (int i = 0; i < MAX_CYLINDERS; i++) {
|
2014-07-03 21:45:01 +00:00
|
|
|
|
cylinder_t *cyl = &displayed_dive.cylinder[i];
|
2013-11-12 02:19:04 +00:00
|
|
|
|
if (cyl->depth.mm) {
|
2014-06-01 22:25:19 +00:00
|
|
|
|
dp = create_dp(0, cyl->depth.mm, cyl->gasmix, 0);
|
2014-01-26 15:22:02 +00:00
|
|
|
|
if (diveplan.dp) {
|
2014-10-19 14:07:07 +00:00
|
|
|
|
dp->next = diveplan.dp;
|
|
|
|
|
diveplan.dp = dp;
|
2014-01-26 15:22:02 +00:00
|
|
|
|
} else {
|
2013-12-19 21:11:31 +00:00
|
|
|
|
dp->next = NULL;
|
2014-01-26 15:22:02 +00:00
|
|
|
|
diveplan.dp = dp;
|
|
|
|
|
}
|
2013-11-12 02:19:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#if DEBUG_PLAN
|
|
|
|
|
dump_plan(&diveplan);
|
|
|
|
|
#endif
|
2014-05-30 22:40:13 +00:00
|
|
|
|
if (plannerModel->recalcQ() && !diveplan_empty(&diveplan)) {
|
2014-07-03 21:45:01 +00:00
|
|
|
|
plan(&diveplan, &cache, isPlanner(), false);
|
2014-07-03 23:41:15 +00:00
|
|
|
|
MainWindow::instance()->setPlanNotes(displayed_dive.notes);
|
2013-11-07 08:25:42 +00:00
|
|
|
|
}
|
2014-03-06 22:26:33 +00:00
|
|
|
|
// throw away the cache
|
|
|
|
|
free(cache);
|
2013-09-16 15:11:06 +00:00
|
|
|
|
#if DEBUG_PLAN
|
2014-07-03 21:45:01 +00:00
|
|
|
|
save_dive(stderr, &displayed_dive);
|
2013-09-16 15:11:06 +00:00
|
|
|
|
dump_plan(&diveplan);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DivePlannerPointsModel::deleteTemporaryPlan()
|
|
|
|
|
{
|
2014-08-19 16:41:09 +00:00
|
|
|
|
free_dps(&diveplan);
|
2013-09-16 15:11:06 +00:00
|
|
|
|
}
|
2013-09-16 15:30:58 +00:00
|
|
|
|
|
2014-11-04 11:15:27 +00:00
|
|
|
|
void DivePlannerPointsModel::savePlan()
|
|
|
|
|
{
|
|
|
|
|
createPlan(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DivePlannerPointsModel::saveDuplicatePlan()
|
|
|
|
|
{
|
|
|
|
|
createPlan(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DivePlannerPointsModel::createPlan(bool replanCopy)
|
2013-09-16 15:30:58 +00:00
|
|
|
|
{
|
2014-07-03 21:45:01 +00:00
|
|
|
|
// Ok, so, here the diveplan creates a dive
|
2013-09-22 19:34:50 +00:00
|
|
|
|
char *cache = NULL;
|
2014-04-24 14:42:10 +00:00
|
|
|
|
bool oldRecalc = plannerModel->setRecalc(false);
|
|
|
|
|
removeDeco();
|
2013-09-16 15:30:58 +00:00
|
|
|
|
createTemporaryPlan();
|
2014-04-24 14:42:10 +00:00
|
|
|
|
plannerModel->setRecalc(oldRecalc);
|
|
|
|
|
|
2014-04-17 02:56:42 +00:00
|
|
|
|
//TODO: C-based function here?
|
2014-07-03 21:45:01 +00:00
|
|
|
|
plan(&diveplan, &cache, isPlanner(), true);
|
2014-10-27 19:35:19 +00:00
|
|
|
|
if (!current_dive || displayed_dive.id != current_dive->id) {
|
2014-08-19 20:03:53 +00:00
|
|
|
|
// we were planning a new dive, not re-planning an existing on
|
|
|
|
|
record_dive(clone_dive(&displayed_dive));
|
2014-10-27 19:35:19 +00:00
|
|
|
|
} else if (current_dive && displayed_dive.id == current_dive->id) {
|
|
|
|
|
// we are replanning a dive - make sure changes are reflected
|
|
|
|
|
// correctly in the dive structure and copy it back into the dive table
|
2014-11-03 21:37:59 +00:00
|
|
|
|
displayed_dive.maxdepth.mm = 0;
|
|
|
|
|
displayed_dive.dc.maxdepth.mm = 0;
|
2014-10-27 19:35:19 +00:00
|
|
|
|
fixup_dive(&displayed_dive);
|
2014-11-04 11:15:27 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
2014-10-27 19:35:19 +00:00
|
|
|
|
copy_dive(&displayed_dive, current_dive);
|
|
|
|
|
}
|
2014-01-15 08:30:42 +00:00
|
|
|
|
mark_divelist_changed(true);
|
2013-09-16 15:30:58 +00:00
|
|
|
|
|
2013-09-16 22:21:13 +00:00
|
|
|
|
// Remove and clean the diveplan, so we don't delete
|
|
|
|
|
// the dive by mistake.
|
2014-08-19 16:41:09 +00:00
|
|
|
|
free_dps(&diveplan);
|
2013-11-09 00:09:46 +00:00
|
|
|
|
setPlanMode(NOTHING);
|
2014-05-28 18:54:04 +00:00
|
|
|
|
planCreated();
|
2013-09-16 15:30:58 +00:00
|
|
|
|
}
|
2015-02-09 18:37:26 +00:00
|
|
|
|
|
|
|
|
|
PlannerDetails::PlannerDetails(QWidget *parent) : QWidget(parent)
|
|
|
|
|
{
|
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
}
|