source: subsurface/desktop-widgets/diveplanner.cpp @ 9021a44

Last change on this file since 9021a44 was 9021a44, checked in by Dirk Hohndel <dirk@…>, 8 months ago

Add SPDX header to desktop widgets

Signed-off-by: Dirk Hohndel <dirk@…>

  • Property mode set to 100644
File size: 21.2 KB
Line 
1// SPDX-License-Identifier: GPL-2.0
2#include "desktop-widgets/diveplanner.h"
3#include "desktop-widgets/modeldelegates.h"
4#include "desktop-widgets/mainwindow.h"
5#include "core/planner.h"
6#include "core/helpers.h"
7#include "core/subsurface-qt/SettingsObjectWrapper.h"
8
9#include "qt-models/cylindermodel.h"
10#include "qt-models/models.h"
11#include "profile-widget/profilewidget2.h"
12#include "qt-models/diveplannermodel.h"
13
14#include <QGraphicsSceneMouseEvent>
15#include <QMessageBox>
16#include <QSettings>
17#include <QShortcut>
18
19#define TIME_INITIAL_MAX 30
20
21#define MAX_DEPTH M_OR_FT(150, 450)
22#define MIN_DEPTH M_OR_FT(20, 60)
23
24#define UNIT_FACTOR ((prefs.units.length == units::METERS) ? 1000.0 / 60.0 : feet_to_mm(1.0) / 60.0)
25
26static DivePlannerPointsModel* plannerModel = DivePlannerPointsModel::instance();
27
28DiveHandler::DiveHandler() : QGraphicsEllipseItem()
29{
30        setRect(-5, -5, 10, 10);
31        setFlags(ItemIgnoresTransformations | ItemIsSelectable | ItemIsMovable | ItemSendsGeometryChanges);
32        setBrush(Qt::white);
33        setZValue(2);
34        t.start();
35}
36
37int DiveHandler::parentIndex()
38{
39        ProfileWidget2 *view = qobject_cast<ProfileWidget2 *>(scene()->views().first());
40        return view->handles.indexOf(this);
41}
42
43void DiveHandler::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
44{
45        QMenu m;
46        // Don't have a gas selection for the last point
47        QModelIndex index = plannerModel->index(parentIndex(), DivePlannerPointsModel::GAS);
48        if (index.sibling(index.row() + 1, index.column()).isValid()) {
49                GasSelectionModel *model = GasSelectionModel::instance();
50                model->repopulate();
51                int rowCount = model->rowCount();
52                for (int i = 0; i < rowCount; i++) {
53                        QAction *action = new QAction(&m);
54                        action->setText(model->data(model->index(i, 0), Qt::DisplayRole).toString());
55                        action->setData(i);
56                        connect(action, SIGNAL(triggered(bool)), this, SLOT(changeGas()));
57                        m.addAction(action);
58                }
59        }
60        // don't allow removing the last point
61        if (plannerModel->rowCount() > 1) {
62                m.addSeparator();
63                m.addAction(QObject::tr("Remove this point"), this, SLOT(selfRemove()));
64                m.exec(event->screenPos());
65        }
66}
67
68void DiveHandler::selfRemove()
69{
70        setSelected(true);
71        ProfileWidget2 *view = qobject_cast<ProfileWidget2 *>(scene()->views().first());
72        view->keyDeleteAction();
73}
74
75void DiveHandler::changeGas()
76{
77        QAction *action = qobject_cast<QAction *>(sender());
78        QModelIndex index = plannerModel->index(parentIndex(), DivePlannerPointsModel::GAS);
79        plannerModel->gaschange(index.sibling(index.row() + 1, index.column()), action->data().toInt());
80}
81
82void DiveHandler::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
83{
84        if (t.elapsed() < 40)
85                return;
86        t.start();
87
88        ProfileWidget2 *view = qobject_cast<ProfileWidget2*>(scene()->views().first());
89        if(view->isPointOutOfBoundaries(event->scenePos()))
90                return;
91
92        QGraphicsEllipseItem::mouseMoveEvent(event);
93        emit moved();
94}
95
96void DiveHandler::mousePressEvent(QGraphicsSceneMouseEvent *event)
97{
98        QGraphicsItem::mousePressEvent(event);
99        emit clicked();
100}
101
102void DiveHandler::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
103{
104        QGraphicsItem::mouseReleaseEvent(event);
105        emit released();
106}
107
108DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f)
109{
110        ui.setupUi(this);
111        ui.dateEdit->setDisplayFormat(prefs.date_format);
112        ui.tableWidget->setTitle(tr("Dive planner points"));
113        ui.tableWidget->setModel(plannerModel);
114        plannerModel->setRecalc(true);
115        ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::GAS, new AirTypesDelegate(this));
116        ui.cylinderTableWidget->setTitle(tr("Available gases"));
117        ui.cylinderTableWidget->setBtnToolTip(tr("Add cylinder"));
118        ui.cylinderTableWidget->setModel(CylindersModel::instance());
119        QTableView *view = ui.cylinderTableWidget->view();
120        view->setColumnHidden(CylindersModel::START, true);
121        view->setColumnHidden(CylindersModel::END, true);
122        view->setColumnHidden(CylindersModel::DEPTH, false);
123        view->setItemDelegateForColumn(CylindersModel::TYPE, new TankInfoDelegate(this));
124        connect(ui.cylinderTableWidget, SIGNAL(addButtonClicked()), plannerModel, SLOT(addCylinder_clicked()));
125        connect(ui.tableWidget, SIGNAL(addButtonClicked()), plannerModel, SLOT(addStop()));
126
127        connect(CylindersModel::instance(), SIGNAL(dataChanged(QModelIndex, QModelIndex)),
128                GasSelectionModel::instance(), SLOT(repopulate()));
129        connect(CylindersModel::instance(), SIGNAL(rowsInserted(QModelIndex, int, int)),
130                GasSelectionModel::instance(), SLOT(repopulate()));
131        connect(CylindersModel::instance(), SIGNAL(rowsRemoved(QModelIndex, int, int)),
132                GasSelectionModel::instance(), SLOT(repopulate()));
133        connect(CylindersModel::instance(), SIGNAL(dataChanged(QModelIndex, QModelIndex)),
134                plannerModel, SLOT(emitDataChanged()));
135        connect(CylindersModel::instance(), SIGNAL(dataChanged(QModelIndex, QModelIndex)),
136                plannerModel, SIGNAL(cylinderModelEdited()));
137        connect(CylindersModel::instance(), SIGNAL(rowsInserted(QModelIndex, int, int)),
138                plannerModel, SIGNAL(cylinderModelEdited()));
139        connect(CylindersModel::instance(), SIGNAL(rowsRemoved(QModelIndex, int, int)),
140                plannerModel, SIGNAL(cylinderModelEdited()));
141        connect(plannerModel, SIGNAL(calculatedPlanNotes()), MainWindow::instance(), SLOT(setPlanNotes()));
142
143
144        ui.tableWidget->setBtnToolTip(tr("Add dive data point"));
145        connect(ui.startTime, SIGNAL(timeChanged(QTime)), plannerModel, SLOT(setStartTime(QTime)));
146        connect(ui.dateEdit, SIGNAL(dateChanged(QDate)), plannerModel, SLOT(setStartDate(QDate)));
147        connect(ui.ATMPressure, SIGNAL(valueChanged(int)), this, SLOT(atmPressureChanged(int)));
148        connect(ui.atmHeight, SIGNAL(valueChanged(int)), this, SLOT(heightChanged(int)));
149        connect(ui.salinity, SIGNAL(valueChanged(double)), this, SLOT(salinityChanged(double)));
150        connect(plannerModel, SIGNAL(startTimeChanged(QDateTime)), this, SLOT(setupStartTime(QDateTime)));
151
152        // Creating (and canceling) the plan
153        replanButton = ui.buttonBox->addButton(tr("Save new"), QDialogButtonBox::ActionRole);
154        connect(replanButton, SIGNAL(clicked()), plannerModel, SLOT(saveDuplicatePlan()));
155        connect(ui.buttonBox, SIGNAL(accepted()), plannerModel, SLOT(savePlan()));
156        connect(ui.buttonBox, SIGNAL(rejected()), plannerModel, SLOT(cancelPlan()));
157        QShortcut *closeKey = new QShortcut(QKeySequence(Qt::Key_Escape), this);
158        connect(closeKey, SIGNAL(activated()), plannerModel, SLOT(cancelPlan()));
159
160        // This makes shure the spinbox gets a setMinimum(0) on it so we can't have negative time or depth.
161        ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::DEPTH, new SpinBoxDelegate(0, INT_MAX, 1, this));
162        ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::RUNTIME, new SpinBoxDelegate(0, INT_MAX, 1, this));
163        ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::DURATION, new SpinBoxDelegate(0, INT_MAX, 1, this));
164        ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::CCSETPOINT, new DoubleSpinBoxDelegate(0, 2, 0.1, this));
165
166        /* set defaults. */
167        ui.ATMPressure->setValue(1013);
168        ui.atmHeight->setValue(0);
169
170        setMinimumWidth(0);
171        setMinimumHeight(0);
172}
173
174void DivePlannerWidget::setReplanButton(bool replan)
175{
176        replanButton->setVisible(replan);
177}
178
179void DivePlannerWidget::setupStartTime(QDateTime startTime)
180{
181        ui.startTime->setTime(startTime.time());
182        ui.dateEdit->setDate(startTime.date());
183}
184
185void DivePlannerWidget::setSurfacePressure(int surface_pressure)
186{
187        ui.ATMPressure->setValue(surface_pressure);
188}
189
190void PlannerSettingsWidget::setDiveMode(int mode)
191{
192        ui.rebreathermode->setCurrentIndex(mode);
193}
194
195void DivePlannerWidget::setSalinity(int salinity)
196{
197        ui.salinity->setValue(salinity / 10000.0);
198}
199
200void DivePlannerWidget::settingsChanged()
201{
202        // Adopt units
203        if (get_units()->length == units::FEET) {
204                ui.atmHeight->setSuffix("ft");
205                ui.atmHeight->setMinimum(-300);
206                ui.atmHeight->setMaximum(10000);
207        } else {
208                ui.atmHeight->setSuffix(("m"));
209                ui.atmHeight->setMinimum(-100);
210                ui.atmHeight->setMaximum(3000);
211        }
212        ui.atmHeight->blockSignals(true);
213        ui.atmHeight->setValue((int) get_depth_units((int) (log(1013.0 / plannerModel->getSurfacePressure()) * 7800000), NULL,NULL));
214        ui.atmHeight->blockSignals(false);
215}
216
217void DivePlannerWidget::atmPressureChanged(const int pressure)
218{
219        plannerModel->setSurfacePressure(pressure);
220        ui.atmHeight->blockSignals(true);
221        ui.atmHeight->setValue((int) get_depth_units((int) (log(1013.0 / pressure) * 7800000), NULL,NULL));
222        ui.atmHeight->blockSignals(false);
223}
224
225void DivePlannerWidget::heightChanged(const int height)
226{
227        int pressure = (int) (1013.0 * exp(- (double) units_to_depth((double) height).mm / 7800000.0));
228        ui.ATMPressure->blockSignals(true);
229        ui.ATMPressure->setValue(pressure);
230        ui.ATMPressure->blockSignals(false);
231        plannerModel->setSurfacePressure(pressure);
232}
233
234void DivePlannerWidget::salinityChanged(const double salinity)
235{
236        /* Salinity is expressed in weight in grams per 10l */
237        plannerModel->setSalinity(lrint(10000 * salinity));
238}
239
240void PlannerSettingsWidget::bottomSacChanged(const double bottomSac)
241{
242        plannerModel->setBottomSac(bottomSac);
243}
244
245void PlannerSettingsWidget::decoSacChanged(const double decosac)
246{
247        plannerModel->setDecoSac(decosac);
248}
249
250void PlannerSettingsWidget::disableDecoElements(int mode)
251{
252        if (mode == RECREATIONAL) {
253                ui.gflow->setDisabled(false);
254                ui.gfhigh->setDisabled(false);
255                ui.lastStop->setDisabled(true);
256                ui.backgasBreaks->setDisabled(true);
257                ui.bottompo2->setDisabled(false);
258                ui.decopo2->setDisabled(true);
259                ui.reserve_gas->setDisabled(false);
260                ui.vpmb_conservatism->setDisabled(true);
261                ui.switch_at_req_stop->setDisabled(true);
262                ui.min_switch_duration->setDisabled(true);
263                ui.sacfactor->setDisabled(true);
264                ui.problemsolvingtime->setDisabled(true);
265                ui.sacfactor->blockSignals(true);
266                ui.problemsolvingtime->blockSignals(true);
267                ui.sacfactor->setValue(2.0);
268                ui.problemsolvingtime->setValue(0);
269                ui.sacfactor->blockSignals(false);
270                ui.problemsolvingtime->blockSignals(false);
271        }
272        else if (mode == VPMB) {
273                ui.gflow->setDisabled(true);
274                ui.gfhigh->setDisabled(true);
275                ui.lastStop->setDisabled(false);
276                ui.backgasBreaks->setDisabled(false);
277                ui.bottompo2->setDisabled(false);
278                ui.decopo2->setDisabled(false);
279                ui.reserve_gas->setDisabled(true);
280                ui.vpmb_conservatism->setDisabled(false);
281                ui.switch_at_req_stop->setDisabled(false);
282                ui.min_switch_duration->setDisabled(false);
283                ui.sacfactor->setDisabled(false);
284                ui.problemsolvingtime->setDisabled(false);
285                ui.sacfactor->setValue(prefs.sacfactor / 100.0);
286                ui.problemsolvingtime->setValue(prefs.problemsolvingtime);
287        }
288        else if (mode == BUEHLMANN) {
289                ui.gflow->setDisabled(false);
290                ui.gfhigh->setDisabled(false);
291                ui.lastStop->setDisabled(false);
292                ui.backgasBreaks->setDisabled(false);
293                ui.bottompo2->setDisabled(false);
294                ui.decopo2->setDisabled(false);
295                ui.reserve_gas->setDisabled(true);
296                ui.vpmb_conservatism->setDisabled(true);
297                ui.switch_at_req_stop->setDisabled(false);
298                ui.min_switch_duration->setDisabled(false);
299                ui.sacfactor->setDisabled(false);
300                ui.problemsolvingtime->setDisabled(false);
301                ui.sacfactor->setValue(prefs.sacfactor / 100.0);
302                ui.problemsolvingtime->setValue(prefs.problemsolvingtime);
303        }
304}
305
306void DivePlannerWidget::printDecoPlan()
307{
308        MainWindow::instance()->printPlan();
309}
310
311PlannerSettingsWidget::PlannerSettingsWidget(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f)
312{
313        ui.setupUi(this);
314        QStringList rebreather_modes;
315
316        plannerModel->getDiveplan().bottomsac = prefs.bottomsac;
317        plannerModel->getDiveplan().decosac = prefs.decosac;
318
319        updateUnitsUI();
320        ui.lastStop->setChecked(prefs.last_stop);
321        ui.verbatim_plan->setChecked(prefs.verbatim_plan);
322        ui.display_duration->setChecked(prefs.display_duration);
323        ui.display_runtime->setChecked(prefs.display_runtime);
324        ui.display_transitions->setChecked(prefs.display_transitions);
325        ui.safetystop->setChecked(prefs.safetystop);
326        ui.sacfactor->setValue(prefs.sacfactor / 100.0);
327        ui.problemsolvingtime->setValue(prefs.problemsolvingtime);
328        ui.bottompo2->setValue(prefs.bottompo2 / 1000.0);
329        ui.decopo2->setValue(prefs.decopo2 / 1000.0);
330        ui.backgasBreaks->setChecked(prefs.doo2breaks);
331        ui.drop_stone_mode->setChecked(prefs.drop_stone_mode);
332        ui.switch_at_req_stop->setChecked(prefs.switch_at_req_stop);
333        ui.min_switch_duration->setValue(prefs.min_switch_duration / 60);
334        ui.recreational_deco->setChecked(prefs.planner_deco_mode == RECREATIONAL);
335        ui.buehlmann_deco->setChecked(prefs.planner_deco_mode == BUEHLMANN);
336        ui.vpmb_deco->setChecked(prefs.planner_deco_mode == VPMB);
337        disableDecoElements((int) prefs.planner_deco_mode);
338
339        // should be the same order as in dive_comp_type!
340        rebreather_modes << tr("Open circuit") << tr("CCR") << tr("pSCR");
341        ui.rebreathermode->insertItems(0, rebreather_modes);
342
343        modeMapper = new QSignalMapper(this);
344        connect(modeMapper, SIGNAL(mapped(int)) , plannerModel, SLOT(setDecoMode(int)));
345        modeMapper->setMapping(ui.recreational_deco, int(RECREATIONAL));
346        modeMapper->setMapping(ui.buehlmann_deco, int(BUEHLMANN));
347        modeMapper->setMapping(ui.vpmb_deco, int(VPMB));
348
349        connect(ui.recreational_deco, SIGNAL(clicked()), modeMapper, SLOT(map()));
350        connect(ui.buehlmann_deco, SIGNAL(clicked()), modeMapper, SLOT(map()));
351        connect(ui.vpmb_deco, SIGNAL(clicked()), modeMapper, SLOT(map()));
352
353        connect(ui.lastStop, SIGNAL(toggled(bool)), plannerModel, SLOT(setLastStop6m(bool)));
354        connect(ui.verbatim_plan, SIGNAL(toggled(bool)), plannerModel, SLOT(setVerbatim(bool)));
355        connect(ui.display_duration, SIGNAL(toggled(bool)), plannerModel, SLOT(setDisplayDuration(bool)));
356        connect(ui.display_runtime, SIGNAL(toggled(bool)), plannerModel, SLOT(setDisplayRuntime(bool)));
357        connect(ui.display_transitions, SIGNAL(toggled(bool)), plannerModel, SLOT(setDisplayTransitions(bool)));
358        connect(ui.safetystop, SIGNAL(toggled(bool)), plannerModel, SLOT(setSafetyStop(bool)));
359        connect(ui.reserve_gas, SIGNAL(valueChanged(int)), plannerModel, SLOT(setReserveGas(int)));
360        connect(ui.ascRate75, SIGNAL(valueChanged(int)), plannerModel, SLOT(emitDataChanged()));
361        connect(ui.ascRate50, SIGNAL(valueChanged(int)), plannerModel, SLOT(emitDataChanged()));
362        connect(ui.ascRateStops, SIGNAL(valueChanged(int)), plannerModel, SLOT(emitDataChanged()));
363        connect(ui.ascRateLast6m, SIGNAL(valueChanged(int)), plannerModel, SLOT(emitDataChanged()));
364        connect(ui.descRate, SIGNAL(valueChanged(int)), plannerModel, SLOT(emitDataChanged()));
365        connect(ui.ascRate75, SIGNAL(editingFinished()), plannerModel, SLOT(emitDataChanged()));
366        connect(ui.ascRate50, SIGNAL(editingFinished()), plannerModel, SLOT(emitDataChanged()));
367        connect(ui.ascRateStops, SIGNAL(editingFinished()), plannerModel, SLOT(emitDataChanged()));
368        connect(ui.ascRateLast6m, SIGNAL(editingFinished()), plannerModel, SLOT(emitDataChanged()));
369        connect(ui.descRate, SIGNAL(editingFinished()), plannerModel, SLOT(emitDataChanged()));
370        connect(ui.drop_stone_mode, SIGNAL(toggled(bool)), plannerModel, SLOT(setDropStoneMode(bool)));
371        connect(ui.gfhigh, SIGNAL(valueChanged(int)), plannerModel, SLOT(setGFHigh(int)));
372        connect(ui.gflow, SIGNAL(valueChanged(int)), plannerModel, SLOT(setGFLow(int)));
373        connect(ui.gfhigh, SIGNAL(editingFinished()), plannerModel, SLOT(triggerGFHigh()));
374        connect(ui.gflow, SIGNAL(editingFinished()), plannerModel, SLOT(triggerGFLow()));
375        connect(ui.vpmb_conservatism, SIGNAL(valueChanged(int)), plannerModel, SLOT(setVpmbConservatism(int)));
376        connect(ui.backgasBreaks, SIGNAL(toggled(bool)), this, SLOT(setBackgasBreaks(bool)));
377        connect(ui.switch_at_req_stop, SIGNAL(toggled(bool)), plannerModel, SLOT(setSwitchAtReqStop(bool)));
378        connect(ui.min_switch_duration, SIGNAL(valueChanged(int)), plannerModel, SLOT(setMinSwitchDuration(int)));
379        connect(ui.rebreathermode, SIGNAL(currentIndexChanged(int)), plannerModel, SLOT(setRebreatherMode(int)));
380
381        connect(ui.bottompo2, SIGNAL(valueChanged(double)), CylindersModel::instance(), SLOT(updateBestMixes()));
382        connect(ui.bestmixEND, SIGNAL(valueChanged(int)), CylindersModel::instance(), SLOT(updateBestMixes()));
383
384        connect(modeMapper, SIGNAL(mapped(int)), this, SLOT(disableDecoElements(int)));
385        connect(ui.ascRate75, SIGNAL(valueChanged(int)), this, SLOT(setAscRate75(int)));
386        connect(ui.ascRate50, SIGNAL(valueChanged(int)), this, SLOT(setAscRate50(int)));
387        connect(ui.descRate, SIGNAL(valueChanged(int)), this, SLOT(setDescRate(int)));
388        connect(ui.ascRateStops, SIGNAL(valueChanged(int)), this, SLOT(setAscRateStops(int)));
389        connect(ui.ascRateLast6m, SIGNAL(valueChanged(int)), this, SLOT(setAscRateLast6m(int)));
390        connect(ui.sacfactor, SIGNAL(valueChanged(double)), this, SLOT(sacFactorChanged(double)));
391        connect(ui.problemsolvingtime, SIGNAL(valueChanged(int)), this, SLOT(problemSolvingTimeChanged(int)));
392        connect(ui.bottompo2, SIGNAL(valueChanged(double)), this, SLOT(setBottomPo2(double)));
393        connect(ui.decopo2, SIGNAL(valueChanged(double)), this, SLOT(setDecoPo2(double)));
394        connect(ui.bestmixEND, SIGNAL(valueChanged(int)), this, SLOT(setBestmixEND(int)));
395        connect(ui.bottomSAC, SIGNAL(valueChanged(double)), this, SLOT(bottomSacChanged(double)));
396        connect(ui.decoStopSAC, SIGNAL(valueChanged(double)), this, SLOT(decoSacChanged(double)));
397
398        settingsChanged();
399        ui.gflow->setValue(prefs.gflow);
400        ui.gfhigh->setValue(prefs.gfhigh);
401        ui.vpmb_conservatism->setValue(prefs.vpmb_conservatism);
402
403        setMinimumWidth(0);
404        setMinimumHeight(0);
405}
406
407void PlannerSettingsWidget::updateUnitsUI()
408{
409        ui.ascRate75->setValue(lrint(prefs.ascrate75 / UNIT_FACTOR));
410        ui.ascRate50->setValue(lrint(prefs.ascrate50 / UNIT_FACTOR));
411        ui.ascRateStops->setValue(lrint(prefs.ascratestops / UNIT_FACTOR));
412        ui.ascRateLast6m->setValue(lrint(prefs.ascratelast6m / UNIT_FACTOR));
413        ui.descRate->setValue(lrint(prefs.descrate / UNIT_FACTOR));
414        ui.bestmixEND->setValue(lrint(get_depth_units(prefs.bestmixend.mm, NULL, NULL)));
415}
416
417PlannerSettingsWidget::~PlannerSettingsWidget()
418{
419}
420
421void PlannerSettingsWidget::settingsChanged()
422{
423        QString vs;
424        // don't recurse into setting the value from the ui when setting the ui from the value
425        ui.bottomSAC->blockSignals(true);
426        ui.decoStopSAC->blockSignals(true);
427        if (get_units()->length == units::FEET) {
428                vs.append(tr("ft/min"));
429                ui.lastStop->setText(tr("Last stop at 20ft"));
430                ui.asc50to6->setText(tr("50% avg. depth to 20ft"));
431                ui.asc6toSurf->setText(tr("20ft to surface"));
432                ui.bestmixEND->setSuffix(tr("ft"));
433        } else {
434                vs.append(tr("m/min"));
435                ui.lastStop->setText(tr("Last stop at 6m"));
436                ui.asc50to6->setText(tr("50% avg. depth to 6m"));
437                ui.asc6toSurf->setText(tr("6m to surface"));
438                ui.bestmixEND->setSuffix(tr("m"));
439        }
440        if(get_units()->volume == units::CUFT) {
441                ui.bottomSAC->setSuffix(tr("cuft/min"));
442                ui.decoStopSAC->setSuffix(tr("cuft/min"));
443                ui.bottomSAC->setDecimals(2);
444                ui.bottomSAC->setSingleStep(0.1);
445                ui.decoStopSAC->setDecimals(2);
446                ui.decoStopSAC->setSingleStep(0.1);
447                ui.bottomSAC->setValue(ml_to_cuft(prefs.bottomsac));
448                ui.decoStopSAC->setValue(ml_to_cuft(prefs.decosac));
449        } else {
450                ui.bottomSAC->setSuffix(tr("ℓ/min"));
451                ui.decoStopSAC->setSuffix(tr("ℓ/min"));
452                ui.bottomSAC->setDecimals(0);
453                ui.bottomSAC->setSingleStep(1);
454                ui.decoStopSAC->setDecimals(0);
455                ui.decoStopSAC->setSingleStep(1);
456                ui.bottomSAC->setValue((double) prefs.bottomsac / 1000.0);
457                ui.decoStopSAC->setValue((double) prefs.decosac / 1000.0);
458        }
459        if(get_units()->pressure == units::BAR) {
460                ui.reserve_gas->setSuffix(tr("bar"));
461                ui.reserve_gas->setSingleStep(1);
462                ui.reserve_gas->setValue(prefs.reserve_gas / 1000);
463                ui.reserve_gas->setMaximum(300);
464        } else {
465                ui.reserve_gas->setSuffix(tr("psi"));
466                ui.reserve_gas->setSingleStep(10);
467                ui.reserve_gas->setMaximum(5000);
468                ui.reserve_gas->setValue(mbar_to_PSI(prefs.reserve_gas));
469        }
470
471        ui.bottomSAC->blockSignals(false);
472        ui.decoStopSAC->blockSignals(false);
473        updateUnitsUI();
474        ui.ascRate75->setSuffix(vs);
475        ui.ascRate50->setSuffix(vs);
476        ui.ascRateStops->setSuffix(vs);
477        ui.ascRateLast6m->setSuffix(vs);
478        ui.descRate->setSuffix(vs);
479}
480
481void PlannerSettingsWidget::printDecoPlan()
482{
483}
484
485void PlannerSettingsWidget::setAscRate75(int rate)
486{
487        SettingsObjectWrapper::instance()->planner_settings->setAscrate75(lrint(rate * UNIT_FACTOR));
488}
489
490void PlannerSettingsWidget::setAscRate50(int rate)
491{
492        SettingsObjectWrapper::instance()->planner_settings->setAscrate50(lrint(rate * UNIT_FACTOR));
493}
494
495void PlannerSettingsWidget::setAscRateStops(int rate)
496{
497        SettingsObjectWrapper::instance()->planner_settings->setAscratestops(lrint(rate * UNIT_FACTOR));
498}
499
500void PlannerSettingsWidget::setAscRateLast6m(int rate)
501{
502        SettingsObjectWrapper::instance()->planner_settings->setAscratelast6m(lrint(rate * UNIT_FACTOR));
503}
504
505void PlannerSettingsWidget::setDescRate(int rate)
506{
507        SettingsObjectWrapper::instance()->planner_settings->setDescrate(lrint(rate * UNIT_FACTOR));
508}
509
510void PlannerSettingsWidget::sacFactorChanged(const double factor)
511{
512    plannerModel->setSacFactor(factor);
513}
514
515void PlannerSettingsWidget::problemSolvingTimeChanged(const int minutes)
516{
517        plannerModel->setProblemSolvingTime(minutes);
518}
519
520void PlannerSettingsWidget::setBottomPo2(double po2)
521{
522        SettingsObjectWrapper::instance()->planner_settings->setBottompo2((int) (po2 * 1000.0));
523}
524
525void PlannerSettingsWidget::setDecoPo2(double po2)
526{
527        pressure_t olddecopo2;
528        olddecopo2.mbar = prefs.decopo2;
529        SettingsObjectWrapper::instance()->planner_settings->setDecopo2((int) (po2 * 1000.0));
530        CylindersModel::instance()->updateDecoDepths(olddecopo2);
531}
532
533void PlannerSettingsWidget::setBestmixEND(int depth)
534{
535        SettingsObjectWrapper::instance()->planner_settings->setBestmixend(units_to_depth(depth).mm);
536}
537
538void PlannerSettingsWidget::setBackgasBreaks(bool dobreaks)
539{
540        SettingsObjectWrapper::instance()->planner_settings->setDoo2breaks(dobreaks);
541        plannerModel->emitDataChanged();
542}
543
544PlannerDetails::PlannerDetails(QWidget *parent) : QWidget(parent)
545{
546        ui.setupUi(this);
547}
Note: See TracBrowser for help on using the repository browser.