2021-04-12 21:34:28 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
|
|
|
#include "profilewidget.h"
|
|
|
|
#include "profile-widget/profilewidget2.h"
|
2022-02-19 10:58:36 +00:00
|
|
|
#include "commands/command.h"
|
2021-08-03 07:51:37 +00:00
|
|
|
#include "core/color.h"
|
2024-05-25 06:16:57 +00:00
|
|
|
#include "core/event.h"
|
|
|
|
#include "core/sample.h"
|
2022-04-04 16:57:28 +00:00
|
|
|
#include "core/selection.h"
|
2021-04-12 21:34:28 +00:00
|
|
|
#include "core/settings/qPrefTechnicalDetails.h"
|
|
|
|
#include "core/settings/qPrefPartialPressureGas.h"
|
2022-02-19 10:58:36 +00:00
|
|
|
#include "core/subsurface-string.h"
|
2021-04-12 21:34:28 +00:00
|
|
|
#include "qt-models/diveplannermodel.h"
|
|
|
|
|
|
|
|
#include <QToolBar>
|
|
|
|
#include <QHBoxLayout>
|
2021-06-30 05:17:40 +00:00
|
|
|
#include <QStackedWidget>
|
|
|
|
#include <QLabel>
|
|
|
|
|
|
|
|
// A resizing display of the Subsurface logo when no dive is shown
|
|
|
|
class EmptyView : public QLabel {
|
|
|
|
public:
|
|
|
|
EmptyView(QWidget *parent = nullptr);
|
|
|
|
~EmptyView();
|
|
|
|
private:
|
|
|
|
QPixmap logo;
|
|
|
|
void update();
|
|
|
|
void resizeEvent(QResizeEvent *) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
EmptyView::EmptyView(QWidget *parent) : QLabel(parent),
|
|
|
|
logo(":poster-icon")
|
|
|
|
{
|
|
|
|
QPalette pal;
|
|
|
|
pal.setColor(QPalette::Window, getColor(::BACKGROUND));
|
|
|
|
setAutoFillBackground(true);
|
|
|
|
setPalette(pal);
|
|
|
|
setMinimumSize(1,1);
|
|
|
|
setAlignment(Qt::AlignHCenter);
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
EmptyView::~EmptyView()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmptyView::update()
|
|
|
|
{
|
|
|
|
setPixmap(logo.scaled(size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmptyView::resizeEvent(QResizeEvent *)
|
|
|
|
{
|
|
|
|
update();
|
|
|
|
}
|
2021-04-12 21:34:28 +00:00
|
|
|
|
2024-05-25 07:03:39 +00:00
|
|
|
ProfileWidget::ProfileWidget() : d(nullptr), dc(0), placingCommand(false)
|
2021-04-12 21:34:28 +00:00
|
|
|
{
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
|
|
|
// what is a sane order for those icons? we should have the ones the user is
|
|
|
|
// most likely to want towards the top so they are always visible
|
|
|
|
// and the ones that someone likely sets and then never touches again towards the bottom
|
2023-06-18 03:28:51 +00:00
|
|
|
toolbarActions = { ui.profInfobox, // show / hide the infobox
|
|
|
|
ui.profCalcCeiling, ui.profCalcAllTissues, // various ceilings
|
2021-04-12 21:34:28 +00:00
|
|
|
ui.profIncrement3m, ui.profDcCeiling,
|
|
|
|
ui.profPhe, ui.profPn2, ui.profPO2, // partial pressure graphs
|
|
|
|
ui.profRuler, ui.profScaled, // measuring and scaling
|
|
|
|
ui.profTogglePicture, ui.profTankbar,
|
|
|
|
ui.profMod, ui.profDeco, ui.profNdl_tts, // various values that a user is either interested in or not
|
|
|
|
ui.profEad, ui.profSAC,
|
|
|
|
ui.profHR, // very few dive computers support this
|
|
|
|
ui.profTissues }; // maybe less frequently used
|
|
|
|
|
2021-06-30 05:17:40 +00:00
|
|
|
emptyView.reset(new EmptyView);
|
|
|
|
|
2021-05-31 20:29:00 +00:00
|
|
|
view.reset(new ProfileWidget2(DivePlannerPointsModel::instance(), 1.0, this));
|
2021-04-12 21:34:28 +00:00
|
|
|
QToolBar *toolBar = new QToolBar(this);
|
|
|
|
for (QAction *a: toolbarActions)
|
|
|
|
toolBar->addAction(a);
|
|
|
|
toolBar->setOrientation(Qt::Vertical);
|
|
|
|
toolBar->setIconSize(QSize(24, 24));
|
2021-06-30 05:17:40 +00:00
|
|
|
|
|
|
|
stack = new QStackedWidget(this);
|
|
|
|
stack->addWidget(emptyView.get());
|
|
|
|
stack->addWidget(view.get());
|
|
|
|
|
2021-04-12 21:34:28 +00:00
|
|
|
QHBoxLayout *layout = new QHBoxLayout(this);
|
|
|
|
layout->setSpacing(0);
|
2022-02-10 01:00:48 +00:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
2021-04-12 21:34:28 +00:00
|
|
|
layout->setMargin(0);
|
2022-02-10 01:00:48 +00:00
|
|
|
#endif
|
2021-04-12 21:34:28 +00:00
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
layout->addWidget(toolBar);
|
2021-06-30 05:17:40 +00:00
|
|
|
layout->addWidget(stack);
|
2021-04-12 21:34:28 +00:00
|
|
|
setLayout(layout);
|
|
|
|
|
|
|
|
// Toolbar Connections related to the Profile Update
|
|
|
|
auto tec = qPrefTechnicalDetails::instance();
|
|
|
|
connect(ui.profCalcAllTissues, &QAction::triggered, tec, &qPrefTechnicalDetails::set_calcalltissues);
|
|
|
|
connect(ui.profCalcCeiling, &QAction::triggered, tec, &qPrefTechnicalDetails::set_calcceiling);
|
|
|
|
connect(ui.profDcCeiling, &QAction::triggered, tec, &qPrefTechnicalDetails::set_dcceiling);
|
|
|
|
connect(ui.profEad, &QAction::triggered, tec, &qPrefTechnicalDetails::set_ead);
|
|
|
|
connect(ui.profIncrement3m, &QAction::triggered, tec, &qPrefTechnicalDetails::set_calcceiling3m);
|
|
|
|
connect(ui.profMod, &QAction::triggered, tec, &qPrefTechnicalDetails::set_mod);
|
|
|
|
connect(ui.profNdl_tts, &QAction::triggered, tec, &qPrefTechnicalDetails::set_calcndltts);
|
|
|
|
connect(ui.profDeco, &QAction::triggered, tec, &qPrefTechnicalDetails::set_decoinfo);
|
|
|
|
connect(ui.profHR, &QAction::triggered, tec, &qPrefTechnicalDetails::set_hrgraph);
|
|
|
|
connect(ui.profRuler, &QAction::triggered, tec, &qPrefTechnicalDetails::set_rulergraph);
|
|
|
|
connect(ui.profSAC, &QAction::triggered, tec, &qPrefTechnicalDetails::set_show_sac);
|
|
|
|
connect(ui.profScaled, &QAction::triggered, tec, &qPrefTechnicalDetails::set_zoomed_plot);
|
|
|
|
connect(ui.profTogglePicture, &QAction::triggered, tec, &qPrefTechnicalDetails::set_show_pictures_in_profile);
|
|
|
|
connect(ui.profTankbar, &QAction::triggered, tec, &qPrefTechnicalDetails::set_tankbar);
|
|
|
|
connect(ui.profTissues, &QAction::triggered, tec, &qPrefTechnicalDetails::set_percentagegraph);
|
2023-06-18 03:28:51 +00:00
|
|
|
connect(ui.profInfobox, &QAction::triggered, tec, &qPrefTechnicalDetails::set_infobox);
|
2021-04-12 21:34:28 +00:00
|
|
|
|
|
|
|
connect(ui.profTissues, &QAction::triggered, this, &ProfileWidget::unsetProfHR);
|
|
|
|
connect(ui.profHR, &QAction::triggered, this, &ProfileWidget::unsetProfTissues);
|
|
|
|
|
|
|
|
auto pp_gas = qPrefPartialPressureGas::instance();
|
|
|
|
connect(ui.profPhe, &QAction::triggered, pp_gas, &qPrefPartialPressureGas::set_phe);
|
|
|
|
connect(ui.profPn2, &QAction::triggered, pp_gas, &qPrefPartialPressureGas::set_pn2);
|
|
|
|
connect(ui.profPO2, &QAction::triggered, pp_gas, &qPrefPartialPressureGas::set_po2);
|
|
|
|
|
2022-03-02 19:50:50 +00:00
|
|
|
connect(&diveListNotifier, &DiveListNotifier::divesChanged, this, &ProfileWidget::divesChanged);
|
2021-04-12 21:34:28 +00:00
|
|
|
connect(&diveListNotifier, &DiveListNotifier::settingsChanged, view.get(), &ProfileWidget2::settingsChanged);
|
2024-05-25 07:03:39 +00:00
|
|
|
connect(&diveListNotifier, &DiveListNotifier::cylinderAdded, this, &ProfileWidget::cylindersChanged);
|
|
|
|
connect(&diveListNotifier, &DiveListNotifier::cylinderRemoved, this, &ProfileWidget::cylindersChanged);
|
|
|
|
connect(&diveListNotifier, &DiveListNotifier::cylinderEdited, this, &ProfileWidget::cylindersChanged);
|
2022-02-19 10:58:36 +00:00
|
|
|
connect(view.get(), &ProfileWidget2::stopAdded, this, &ProfileWidget::stopAdded);
|
|
|
|
connect(view.get(), &ProfileWidget2::stopRemoved, this, &ProfileWidget::stopRemoved);
|
|
|
|
connect(view.get(), &ProfileWidget2::stopMoved, this, &ProfileWidget::stopMoved);
|
2024-05-25 07:03:39 +00:00
|
|
|
connect(view.get(), &ProfileWidget2::stopEdited, this, &ProfileWidget::stopEdited);
|
2021-04-12 21:34:28 +00:00
|
|
|
|
|
|
|
ui.profCalcAllTissues->setChecked(qPrefTechnicalDetails::calcalltissues());
|
|
|
|
ui.profCalcCeiling->setChecked(qPrefTechnicalDetails::calcceiling());
|
|
|
|
ui.profDcCeiling->setChecked(qPrefTechnicalDetails::dcceiling());
|
|
|
|
ui.profEad->setChecked(qPrefTechnicalDetails::ead());
|
|
|
|
ui.profIncrement3m->setChecked(qPrefTechnicalDetails::calcceiling3m());
|
|
|
|
ui.profMod->setChecked(qPrefTechnicalDetails::mod());
|
|
|
|
ui.profNdl_tts->setChecked(qPrefTechnicalDetails::calcndltts());
|
|
|
|
ui.profDeco->setChecked(qPrefTechnicalDetails::decoinfo());
|
|
|
|
ui.profPhe->setChecked(pp_gas->phe());
|
|
|
|
ui.profPn2->setChecked(pp_gas->pn2());
|
|
|
|
ui.profPO2->setChecked(pp_gas->po2());
|
|
|
|
ui.profHR->setChecked(qPrefTechnicalDetails::hrgraph());
|
|
|
|
ui.profRuler->setChecked(qPrefTechnicalDetails::rulergraph());
|
|
|
|
ui.profSAC->setChecked(qPrefTechnicalDetails::show_sac());
|
|
|
|
ui.profTogglePicture->setChecked(qPrefTechnicalDetails::show_pictures_in_profile());
|
|
|
|
ui.profTankbar->setChecked(qPrefTechnicalDetails::tankbar());
|
|
|
|
ui.profTissues->setChecked(qPrefTechnicalDetails::percentagegraph());
|
|
|
|
ui.profScaled->setChecked(qPrefTechnicalDetails::zoomed_plot());
|
2023-06-18 03:28:51 +00:00
|
|
|
ui.profInfobox->setChecked(qPrefTechnicalDetails::infobox());
|
2021-04-12 21:34:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ProfileWidget::~ProfileWidget()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileWidget::setEnabledToolbar(bool enabled)
|
|
|
|
{
|
|
|
|
for (QAction *b: toolbarActions)
|
|
|
|
b->setEnabled(enabled);
|
|
|
|
}
|
|
|
|
|
2024-04-25 20:16:08 +00:00
|
|
|
void ProfileWidget::setDive(const struct dive *d, int dcNr)
|
2021-04-12 21:34:28 +00:00
|
|
|
{
|
|
|
|
stack->setCurrentIndex(1); // show profile
|
|
|
|
|
2024-06-30 18:38:12 +00:00
|
|
|
bool freeDiveMode = d->get_dc(dcNr)->divemode == FREEDIVE;
|
2021-04-12 21:34:28 +00:00
|
|
|
ui.profCalcCeiling->setDisabled(freeDiveMode);
|
|
|
|
ui.profCalcCeiling->setDisabled(freeDiveMode);
|
|
|
|
ui.profCalcAllTissues ->setDisabled(freeDiveMode);
|
|
|
|
ui.profIncrement3m->setDisabled(freeDiveMode);
|
|
|
|
ui.profDcCeiling->setDisabled(freeDiveMode);
|
|
|
|
ui.profPhe->setDisabled(freeDiveMode);
|
|
|
|
ui.profPn2->setDisabled(freeDiveMode); //TODO is the same as scuba?
|
|
|
|
ui.profPO2->setDisabled(freeDiveMode); //TODO is the same as scuba?
|
|
|
|
ui.profTankbar->setDisabled(freeDiveMode);
|
|
|
|
ui.profMod->setDisabled(freeDiveMode);
|
|
|
|
ui.profNdl_tts->setDisabled(freeDiveMode);
|
|
|
|
ui.profDeco->setDisabled(freeDiveMode);
|
|
|
|
ui.profEad->setDisabled(freeDiveMode);
|
|
|
|
ui.profSAC->setDisabled(freeDiveMode);
|
|
|
|
ui.profTissues->setDisabled(freeDiveMode);
|
|
|
|
|
|
|
|
ui.profRuler->setDisabled(false);
|
|
|
|
ui.profScaled->setDisabled(false); // measuring and scaling
|
|
|
|
ui.profTogglePicture->setDisabled(false);
|
|
|
|
ui.profHR->setDisabled(false);
|
2023-06-18 03:28:51 +00:00
|
|
|
ui.profInfobox->setDisabled(false);
|
2021-04-12 21:34:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileWidget::plotCurrentDive()
|
|
|
|
{
|
2022-09-17 17:07:35 +00:00
|
|
|
plotDive(d, dc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileWidget::plotDive(dive *dIn, int dcIn)
|
|
|
|
{
|
2024-05-25 07:03:39 +00:00
|
|
|
bool endEditMode = false;
|
|
|
|
if (editedDive && (dIn != d || dcIn != dc))
|
|
|
|
endEditMode = true;
|
|
|
|
|
2022-09-17 17:07:35 +00:00
|
|
|
d = dIn;
|
|
|
|
|
|
|
|
if (dcIn >= 0)
|
|
|
|
dc = dcIn;
|
|
|
|
|
|
|
|
// The following is valid because number_of_computers is always at least 1.
|
|
|
|
if (d)
|
2024-06-30 15:16:14 +00:00
|
|
|
dc = std::min(dc, d->number_of_computers() - 1);
|
2022-09-17 17:07:35 +00:00
|
|
|
|
2022-02-19 10:58:36 +00:00
|
|
|
// Exit edit mode if the dive changed
|
2024-05-25 07:03:39 +00:00
|
|
|
if (endEditMode)
|
2022-02-19 10:58:36 +00:00
|
|
|
exitEditMode();
|
|
|
|
|
2022-03-11 20:45:46 +00:00
|
|
|
// If this is a manually added dive and we are not in the planner
|
|
|
|
// or already editing the dive, switch to edit mode.
|
2022-09-17 17:07:35 +00:00
|
|
|
if (d && !editedDive &&
|
2022-03-11 20:45:46 +00:00
|
|
|
DivePlannerPointsModel::instance()->currentMode() == DivePlannerPointsModel::NOTHING) {
|
2024-06-30 18:38:12 +00:00
|
|
|
struct divecomputer *comp = d->get_dc(dc);
|
2024-05-19 10:38:38 +00:00
|
|
|
if (comp && is_dc_manually_added_dive(comp) && !comp->samples.empty() && comp->samples.size() <= 50)
|
2022-03-11 20:45:46 +00:00
|
|
|
editDive();
|
|
|
|
}
|
|
|
|
|
2022-09-17 17:07:35 +00:00
|
|
|
setEnabledToolbar(d != nullptr);
|
2022-02-19 10:58:36 +00:00
|
|
|
if (editedDive) {
|
2024-05-25 07:03:39 +00:00
|
|
|
view->plotDive(editedDive.get(), dc);
|
2024-04-25 20:16:08 +00:00
|
|
|
setDive(editedDive.get(), dc);
|
2022-09-17 17:07:35 +00:00
|
|
|
} else if (d) {
|
|
|
|
view->setProfileState(d, dc);
|
2021-10-04 19:45:15 +00:00
|
|
|
view->resetZoom(); // when switching dive, reset the zoomLevel
|
2022-09-17 17:07:35 +00:00
|
|
|
view->plotDive(d, dc);
|
2024-04-25 20:16:08 +00:00
|
|
|
setDive(d, dc);
|
2021-06-30 05:17:40 +00:00
|
|
|
} else {
|
2021-08-08 13:22:15 +00:00
|
|
|
view->clear();
|
2021-06-30 05:17:40 +00:00
|
|
|
stack->setCurrentIndex(0);
|
|
|
|
}
|
2021-04-12 21:34:28 +00:00
|
|
|
}
|
|
|
|
|
2022-09-17 17:07:35 +00:00
|
|
|
void ProfileWidget::nextDC()
|
|
|
|
{
|
|
|
|
rotateDC(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileWidget::prevDC()
|
|
|
|
{
|
|
|
|
rotateDC(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileWidget::rotateDC(int dir)
|
|
|
|
{
|
|
|
|
if (!d)
|
|
|
|
return;
|
2024-06-30 15:16:14 +00:00
|
|
|
int numDC = d->number_of_computers();
|
2022-09-17 17:07:35 +00:00
|
|
|
int newDC = (dc + dir) % numDC;
|
|
|
|
if (newDC < 0)
|
|
|
|
newDC += numDC;
|
|
|
|
if (newDC == dc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
plotDive(d, newDC);
|
|
|
|
}
|
|
|
|
|
2022-03-02 19:50:50 +00:00
|
|
|
void ProfileWidget::divesChanged(const QVector<dive *> &dives, DiveField field)
|
|
|
|
{
|
|
|
|
// If the current dive is not in list of changed dives, do nothing.
|
|
|
|
// Also, if we are currently placing a command, don't do anything.
|
|
|
|
// Note that we cannot use Command::placingCommand(), because placing
|
|
|
|
// a depth or time change on the maintab requires an update.
|
2022-09-17 17:07:35 +00:00
|
|
|
if (!d || !dives.contains(d) || !(field.duration || field.depth) || placingCommand)
|
2022-03-02 19:50:50 +00:00
|
|
|
return;
|
|
|
|
|
2024-05-25 07:03:39 +00:00
|
|
|
// If we're editing the current dive and not currently
|
2022-03-02 19:50:50 +00:00
|
|
|
// placing command, we have to update the edited dive.
|
|
|
|
if (editedDive) {
|
2022-09-17 17:07:35 +00:00
|
|
|
copy_dive(d, editedDive.get());
|
2022-03-02 19:50:50 +00:00
|
|
|
// TODO: Holy moly that function sends too many signals. Fix it!
|
2024-05-25 07:03:39 +00:00
|
|
|
DivePlannerPointsModel::instance()->loadFromDive(editedDive.get(), dc);
|
2022-03-02 19:50:50 +00:00
|
|
|
}
|
|
|
|
|
2024-05-25 07:03:39 +00:00
|
|
|
// Only if duration or depth changed, the profile needs to be replotted.
|
|
|
|
if (field.duration || field.depth)
|
|
|
|
plotCurrentDive();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileWidget::cylindersChanged(struct dive *changed, int pos)
|
|
|
|
{
|
|
|
|
// If the current dive is not in list of changed dives, do nothing.
|
|
|
|
// Only if duration or depth changed, the profile needs to be replotted.
|
|
|
|
// Also, if we are currently placing a command, don't do anything.
|
|
|
|
// Note that we cannot use Command::placingCommand(), because placing
|
|
|
|
// a depth or time change on the maintab requires an update.
|
|
|
|
if (!d || changed != d || !editedDive)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If we're editing the current dive we have to update the
|
|
|
|
// cylinders of the edited dive.
|
|
|
|
if (editedDive) {
|
2024-05-28 19:31:11 +00:00
|
|
|
editedDive.get()->cylinders = d->cylinders;
|
2024-05-25 07:03:39 +00:00
|
|
|
// TODO: Holy moly that function sends too many signals. Fix it!
|
|
|
|
DivePlannerPointsModel::instance()->loadFromDive(editedDive.get(), dc);
|
|
|
|
}
|
2022-03-02 19:50:50 +00:00
|
|
|
}
|
|
|
|
|
2024-04-25 20:16:08 +00:00
|
|
|
void ProfileWidget::setPlanState(const struct dive *d, int dcNr)
|
2021-04-12 21:34:28 +00:00
|
|
|
{
|
2024-04-25 20:16:08 +00:00
|
|
|
dc = dcNr;
|
|
|
|
view->setPlanState(d, dcNr);
|
|
|
|
setDive(d, dcNr);
|
2021-04-12 21:34:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileWidget::unsetProfHR()
|
|
|
|
{
|
|
|
|
ui.profHR->setChecked(false);
|
|
|
|
qPrefTechnicalDetails::set_hrgraph(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileWidget::unsetProfTissues()
|
|
|
|
{
|
|
|
|
ui.profTissues->setChecked(false);
|
|
|
|
qPrefTechnicalDetails::set_percentagegraph(false);
|
|
|
|
}
|
2022-02-19 10:58:36 +00:00
|
|
|
|
|
|
|
void ProfileWidget::editDive()
|
|
|
|
{
|
2024-05-16 18:11:21 +00:00
|
|
|
editedDive = std::make_unique<dive>();
|
2022-09-17 17:07:35 +00:00
|
|
|
copy_dive(d, editedDive.get()); // Work on a copy of the dive
|
2024-05-25 07:03:39 +00:00
|
|
|
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::EDIT);
|
|
|
|
DivePlannerPointsModel::instance()->loadFromDive(editedDive.get(), dc);
|
|
|
|
view->setEditState(editedDive.get(), dc);
|
2022-02-19 10:58:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileWidget::exitEditMode()
|
|
|
|
{
|
|
|
|
if (!editedDive)
|
|
|
|
return;
|
2024-05-25 07:03:39 +00:00
|
|
|
|
2022-02-19 10:58:36 +00:00
|
|
|
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::NOTHING);
|
2022-09-17 17:07:35 +00:00
|
|
|
view->setProfileState(d, dc); // switch back to original dive before erasing the copy.
|
2022-02-19 10:58:36 +00:00
|
|
|
editedDive.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update depths of edited dive
|
|
|
|
static void calcDepth(dive &d, int dcNr)
|
|
|
|
{
|
2024-09-03 15:04:48 +00:00
|
|
|
d.maxdepth = d.get_dc(dcNr)->maxdepth = 0_m;
|
2024-06-23 12:20:59 +00:00
|
|
|
divelog.dives.fixup_dive(d);
|
2022-02-19 10:58:36 +00:00
|
|
|
}
|
|
|
|
|
2022-03-02 19:50:50 +00:00
|
|
|
// Silly RAII-variable setter class: reset variable when going out of scope.
|
|
|
|
template <typename T>
|
|
|
|
struct Setter {
|
|
|
|
T &var, old;
|
|
|
|
Setter(T &var, T value) : var(var), old(var) {
|
|
|
|
var = value;
|
|
|
|
}
|
|
|
|
~Setter() {
|
|
|
|
var = old;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-02-19 10:58:36 +00:00
|
|
|
void ProfileWidget::stopAdded()
|
|
|
|
{
|
|
|
|
if (!editedDive)
|
|
|
|
return;
|
2024-05-25 07:03:39 +00:00
|
|
|
calcDepth(*editedDive, dc);
|
2022-03-02 19:50:50 +00:00
|
|
|
Setter s(placingCommand, true);
|
2024-05-25 07:03:39 +00:00
|
|
|
Command::editProfile(editedDive.get(), dc, Command::EditProfileType::ADD, 0);
|
2022-02-19 10:58:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileWidget::stopRemoved(int count)
|
|
|
|
{
|
|
|
|
if (!editedDive)
|
|
|
|
return;
|
2024-05-25 07:03:39 +00:00
|
|
|
calcDepth(*editedDive, dc);
|
2022-03-02 19:50:50 +00:00
|
|
|
Setter s(placingCommand, true);
|
2024-05-25 07:03:39 +00:00
|
|
|
Command::editProfile(editedDive.get(), dc, Command::EditProfileType::REMOVE, count);
|
2022-02-19 10:58:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileWidget::stopMoved(int count)
|
|
|
|
{
|
|
|
|
if (!editedDive)
|
|
|
|
return;
|
2024-05-25 07:03:39 +00:00
|
|
|
calcDepth(*editedDive, dc);
|
|
|
|
Setter s(placingCommand, true);
|
|
|
|
Command::editProfile(editedDive.get(), dc, Command::EditProfileType::MOVE, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileWidget::stopEdited()
|
|
|
|
{
|
|
|
|
if (!editedDive)
|
|
|
|
return;
|
|
|
|
|
2022-03-02 19:50:50 +00:00
|
|
|
Setter s(placingCommand, true);
|
2024-05-25 07:03:39 +00:00
|
|
|
Command::editProfile(editedDive.get(), dc, Command::EditProfileType::EDIT, 0);
|
2022-02-19 10:58:36 +00:00
|
|
|
}
|