2016-04-05 05:02:03 +00:00
|
|
|
|
#include "desktop-widgets/diveplanner.h"
|
|
|
|
|
#include "desktop-widgets/modeldelegates.h"
|
|
|
|
|
#include "desktop-widgets/mainwindow.h"
|
|
|
|
|
#include "core/planner.h"
|
|
|
|
|
#include "core/helpers.h"
|
|
|
|
|
#include "qt-models/cylindermodel.h"
|
|
|
|
|
#include "qt-models/models.h"
|
2015-09-03 18:56:37 +00:00
|
|
|
|
#include "profile-widget/profilewidget2.h"
|
2016-04-05 05:02:03 +00:00
|
|
|
|
#include "qt-models/diveplannermodel.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)
|
|
|
|
|
|
2015-05-28 19:23:49 +00:00
|
|
|
|
static DivePlannerPointsModel* plannerModel = DivePlannerPointsModel::instance();
|
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;
|
2015-09-11 13:54:17 +00:00
|
|
|
|
// Don't have a gas selection for the last point
|
|
|
|
|
QModelIndex index = plannerModel->index(parentIndex(), DivePlannerPointsModel::GAS);
|
|
|
|
|
if (index.sibling(index.row() + 1, index.column()).isValid()) {
|
|
|
|
|
GasSelectionModel *model = GasSelectionModel::instance();
|
|
|
|
|
model->repopulate();
|
|
|
|
|
int rowCount = model->rowCount();
|
|
|
|
|
for (int i = 0; i < rowCount; i++) {
|
|
|
|
|
QAction *action = new QAction(&m);
|
|
|
|
|
action->setText(model->data(model->index(i, 0), Qt::DisplayRole).toString());
|
|
|
|
|
connect(action, SIGNAL(triggered(bool)), this, SLOT(changeGas()));
|
|
|
|
|
m.addAction(action);
|
|
|
|
|
}
|
2013-11-19 22:42:05 +00:00
|
|
|
|
}
|
2014-07-15 10:29:43 +00:00
|
|
|
|
// don't allow removing the last point
|
2015-05-28 19:23:49 +00:00
|
|
|
|
if (plannerModel->rowCount() > 1) {
|
2014-07-15 10:29:43 +00:00
|
|
|
|
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);
|
2015-05-14 21:42:09 +00:00
|
|
|
|
plannerModel->gaschange(index.sibling(index.row() + 1, index.column()), action->text());
|
2013-11-19 22:42:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
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);
|
2015-10-29 23:57:43 +00:00
|
|
|
|
ui.dateEdit->setDisplayFormat(prefs.date_format);
|
2014-07-10 23:06:46 +00:00
|
|
|
|
ui.tableWidget->setTitle(tr("Dive planner points"));
|
2015-05-28 19:23:49 +00:00
|
|
|
|
ui.tableWidget->setModel(plannerModel);
|
|
|
|
|
plannerModel->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));
|
2015-05-28 19:23:49 +00:00
|
|
|
|
connect(ui.cylinderTableWidget, SIGNAL(addButtonClicked()), plannerModel, SLOT(addCylinder_clicked()));
|
|
|
|
|
connect(ui.tableWidget, SIGNAL(addButtonClicked()), plannerModel, 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()));
|
2015-06-16 12:37:02 +00:00
|
|
|
|
connect(plannerModel, SIGNAL(calculatedPlanNotes()), MainWindow::instance(), SLOT(setPlanNotes()));
|
|
|
|
|
|
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)));
|
2015-05-28 19:23:49 +00:00
|
|
|
|
connect(plannerModel, 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
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2015-08-15 13:16:51 +00:00
|
|
|
|
void PlannerSettingsWidget::disableDecoElements(int mode)
|
2015-04-26 19:40:36 +00:00
|
|
|
|
{
|
2015-08-15 13:16:51 +00:00
|
|
|
|
if (mode == RECREATIONAL) {
|
|
|
|
|
ui.gflow->setDisabled(false);
|
|
|
|
|
ui.gfhigh->setDisabled(false);
|
|
|
|
|
ui.lastStop->setDisabled(true);
|
|
|
|
|
ui.backgasBreaks->setDisabled(true);
|
|
|
|
|
ui.bottompo2->setDisabled(true);
|
|
|
|
|
ui.decopo2->setDisabled(true);
|
|
|
|
|
ui.reserve_gas->setDisabled(false);
|
|
|
|
|
ui.conservatism_lvl->setDisabled(true);
|
2015-08-22 17:40:20 +00:00
|
|
|
|
ui.switch_at_req_stop->setDisabled(true);
|
|
|
|
|
ui.min_switch_duration->setDisabled(true);
|
2015-07-07 18:29:37 +00:00
|
|
|
|
}
|
2015-08-15 13:16:51 +00:00
|
|
|
|
else if (mode == VPMB) {
|
|
|
|
|
ui.gflow->setDisabled(true);
|
|
|
|
|
ui.gfhigh->setDisabled(true);
|
|
|
|
|
ui.lastStop->setDisabled(false);
|
|
|
|
|
ui.backgasBreaks->setDisabled(false);
|
|
|
|
|
ui.bottompo2->setDisabled(false);
|
|
|
|
|
ui.decopo2->setDisabled(false);
|
|
|
|
|
ui.reserve_gas->setDisabled(true);
|
|
|
|
|
ui.conservatism_lvl->setDisabled(false);
|
2015-08-22 17:40:20 +00:00
|
|
|
|
ui.switch_at_req_stop->setDisabled(false);
|
|
|
|
|
ui.min_switch_duration->setDisabled(false);
|
2015-07-07 18:29:37 +00:00
|
|
|
|
}
|
2015-08-15 13:16:51 +00:00
|
|
|
|
else if (mode == BUEHLMANN) {
|
|
|
|
|
ui.gflow->setDisabled(false);
|
|
|
|
|
ui.gfhigh->setDisabled(false);
|
|
|
|
|
ui.lastStop->setDisabled(false);
|
|
|
|
|
ui.backgasBreaks->setDisabled(false);
|
|
|
|
|
ui.bottompo2->setDisabled(false);
|
|
|
|
|
ui.decopo2->setDisabled(false);
|
|
|
|
|
ui.reserve_gas->setDisabled(true);
|
|
|
|
|
ui.conservatism_lvl->setDisabled(true);
|
2015-08-22 17:40:20 +00:00
|
|
|
|
ui.switch_at_req_stop->setDisabled(false);
|
|
|
|
|
ui.min_switch_duration->setDisabled(false);
|
2015-07-07 18:29:37 +00:00
|
|
|
|
}
|
2015-04-26 19:40:36 +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;
|
2015-07-24 11:42:12 +00:00
|
|
|
|
QStringList rebreather_modes;
|
2014-07-15 18:39:13 +00:00
|
|
|
|
s.beginGroup("Planner");
|
2015-03-24 21:57:22 +00:00
|
|
|
|
prefs.last_stop = s.value("last_stop", prefs.last_stop).toBool();
|
|
|
|
|
prefs.verbatim_plan = s.value("verbatim_plan", prefs.verbatim_plan).toBool();
|
|
|
|
|
prefs.display_duration = s.value("display_duration", prefs.display_duration).toBool();
|
|
|
|
|
prefs.display_runtime = s.value("display_runtime", prefs.display_runtime).toBool();
|
|
|
|
|
prefs.display_transitions = s.value("display_transitions", prefs.display_transitions).toBool();
|
2015-07-03 21:07:58 +00:00
|
|
|
|
prefs.deco_mode = deco_mode(s.value("deco_mode", prefs.deco_mode).toInt());
|
2015-04-02 08:32:14 +00:00
|
|
|
|
prefs.safetystop = s.value("safetystop", prefs.safetystop).toBool();
|
2015-04-09 15:41:41 +00:00
|
|
|
|
prefs.reserve_gas = s.value("reserve_gas", prefs.reserve_gas).toInt();
|
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();
|
2015-06-22 11:48:42 +00:00
|
|
|
|
prefs.switch_at_req_stop = s.value("switch_at_req_stop", prefs.switch_at_req_stop).toBool();
|
2015-06-19 10:25:03 +00:00
|
|
|
|
prefs.min_switch_duration = s.value("min_switch_duration", prefs.min_switch_duration).toInt();
|
2014-07-19 11:36:57 +00:00
|
|
|
|
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();
|
2015-08-15 13:16:51 +00:00
|
|
|
|
prefs.conservatism_level = s.value("conservatism", prefs.conservatism_level).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();
|
2015-03-24 21:57:22 +00:00
|
|
|
|
ui.lastStop->setChecked(prefs.last_stop);
|
|
|
|
|
ui.verbatim_plan->setChecked(prefs.verbatim_plan);
|
|
|
|
|
ui.display_duration->setChecked(prefs.display_duration);
|
|
|
|
|
ui.display_runtime->setChecked(prefs.display_runtime);
|
|
|
|
|
ui.display_transitions->setChecked(prefs.display_transitions);
|
2015-04-02 08:32:14 +00:00
|
|
|
|
ui.safetystop->setChecked(prefs.safetystop);
|
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-06-22 11:48:42 +00:00
|
|
|
|
ui.switch_at_req_stop->setChecked(prefs.switch_at_req_stop);
|
2015-06-19 10:25:03 +00:00
|
|
|
|
ui.min_switch_duration->setValue(prefs.min_switch_duration / 60);
|
2015-07-03 21:07:58 +00:00
|
|
|
|
ui.recreational_deco->setChecked(prefs.deco_mode == RECREATIONAL);
|
|
|
|
|
ui.buehlmann_deco->setChecked(prefs.deco_mode == BUEHLMANN);
|
|
|
|
|
ui.vpmb_deco->setChecked(prefs.deco_mode == VPMB);
|
2015-08-15 13:16:51 +00:00
|
|
|
|
ui.conservatism_lvl->setValue(prefs.conservatism_level);
|
|
|
|
|
disableDecoElements((int) prefs.deco_mode);
|
2015-07-03 21:07:58 +00:00
|
|
|
|
|
2015-01-16 14:05:00 +00:00
|
|
|
|
// should be the same order as in dive_comp_type!
|
2015-07-24 11:42:12 +00:00
|
|
|
|
rebreather_modes << tr("Open circuit") << tr("CCR") << tr("pSCR");
|
|
|
|
|
ui.rebreathermode->insertItems(0, rebreather_modes);
|
2014-06-24 22:08:36 +00:00
|
|
|
|
|
2015-07-03 21:07:58 +00:00
|
|
|
|
modeMapper = new QSignalMapper(this);
|
|
|
|
|
connect(modeMapper, SIGNAL(mapped(int)) , plannerModel, SLOT(setDecoMode(int)));
|
|
|
|
|
modeMapper->setMapping(ui.recreational_deco, int(RECREATIONAL));
|
|
|
|
|
modeMapper->setMapping(ui.buehlmann_deco, int(BUEHLMANN));
|
|
|
|
|
modeMapper->setMapping(ui.vpmb_deco, int(VPMB));
|
2015-09-03 18:56:37 +00:00
|
|
|
|
|
2015-07-03 21:07:58 +00:00
|
|
|
|
connect(ui.recreational_deco, SIGNAL(clicked()), modeMapper, SLOT(map()));
|
|
|
|
|
connect(ui.buehlmann_deco, SIGNAL(clicked()), modeMapper, SLOT(map()));
|
|
|
|
|
connect(ui.vpmb_deco, SIGNAL(clicked()), modeMapper, SLOT(map()));
|
2015-09-03 18:56:37 +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)));
|
2015-04-02 08:32:14 +00:00
|
|
|
|
connect(ui.safetystop, SIGNAL(toggled(bool)), plannerModel, SLOT(setSafetyStop(bool)));
|
2015-04-09 15:41:41 +00:00
|
|
|
|
connect(ui.reserve_gas, SIGNAL(valueChanged(int)), plannerModel, SLOT(setReserveGas(int)));
|
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()));
|
2015-08-15 13:16:51 +00:00
|
|
|
|
connect(ui.conservatism_lvl, SIGNAL(valueChanged(int)), plannerModel, SLOT(setConservatism(int)));
|
2014-07-02 20:07:38 +00:00
|
|
|
|
connect(ui.backgasBreaks, SIGNAL(toggled(bool)), this, SLOT(setBackgasBreaks(bool)));
|
2015-06-22 11:48:42 +00:00
|
|
|
|
connect(ui.switch_at_req_stop, SIGNAL(toggled(bool)), plannerModel, SLOT(setSwitchAtReqStop(bool)));
|
2015-06-19 10:25:03 +00:00
|
|
|
|
connect(ui.min_switch_duration, SIGNAL(valueChanged(int)), plannerModel, SLOT(setMinSwitchDuration(int)));
|
2015-01-16 14:05:00 +00:00
|
|
|
|
connect(ui.rebreathermode, SIGNAL(currentIndexChanged(int)), plannerModel, SLOT(setRebreatherMode(int)));
|
2015-08-15 13:16:51 +00:00
|
|
|
|
connect(modeMapper, SIGNAL(mapped(int)), this, SLOT(disableDecoElements(int)));
|
2015-04-26 19:40:36 +00:00
|
|
|
|
|
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");
|
2015-03-24 21:57:22 +00:00
|
|
|
|
s.setValue("last_stop", prefs.last_stop);
|
|
|
|
|
s.setValue("verbatim_plan", prefs.verbatim_plan);
|
|
|
|
|
s.setValue("display_duration", prefs.display_duration);
|
|
|
|
|
s.setValue("display_runtime", prefs.display_runtime);
|
|
|
|
|
s.setValue("display_transitions", prefs.display_transitions);
|
2015-04-02 08:32:14 +00:00
|
|
|
|
s.setValue("safetystop", prefs.safetystop);
|
2015-04-09 15:41:41 +00:00
|
|
|
|
s.setValue("reserve_gas", prefs.reserve_gas);
|
2014-07-15 18:39:13 +00:00
|
|
|
|
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);
|
2015-06-22 11:48:42 +00:00
|
|
|
|
s.setValue("switch_at_req_stop", prefs.switch_at_req_stop);
|
2015-06-19 10:25:03 +00:00
|
|
|
|
s.setValue("min_switch_duration", prefs.min_switch_duration);
|
2014-07-17 03:32:06 +00:00
|
|
|
|
s.setValue("bottomsac", prefs.bottomsac);
|
|
|
|
|
s.setValue("decosac", prefs.decosac);
|
2015-07-03 21:07:58 +00:00
|
|
|
|
s.setValue("deco_mode", int(prefs.deco_mode));
|
2015-08-15 13:16:51 +00:00
|
|
|
|
s.setValue("conservatism", prefs.conservatism_level);
|
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
|
|
|
|
}
|
2016-03-22 22:44:59 +00:00
|
|
|
|
if(get_units()->pressure == units::BAR) {
|
|
|
|
|
ui.reserve_gas->setSuffix(tr("bar"));
|
|
|
|
|
ui.reserve_gas->setSingleStep(1);
|
|
|
|
|
ui.reserve_gas->setValue(prefs.reserve_gas / 1000);
|
2016-03-23 15:59:18 +00:00
|
|
|
|
ui.reserve_gas->setMaximum(300);
|
2016-03-22 22:44:59 +00:00
|
|
|
|
} else {
|
|
|
|
|
ui.reserve_gas->setSuffix(tr("psi"));
|
|
|
|
|
ui.reserve_gas->setSingleStep(10);
|
2016-03-23 15:59:18 +00:00
|
|
|
|
ui.reserve_gas->setMaximum(5000);
|
2016-03-22 22:44:59 +00:00
|
|
|
|
ui.reserve_gas->setValue(mbar_to_PSI(prefs.reserve_gas));
|
|
|
|
|
}
|
|
|
|
|
|
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::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
|
|
|
|
}
|
|
|
|
|
|
2015-02-09 18:37:26 +00:00
|
|
|
|
PlannerDetails::PlannerDetails(QWidget *parent) : QWidget(parent)
|
|
|
|
|
{
|
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
}
|