desktop: warn when deleting a cylinder with sensor readings

This makes the sensors pointless and in the future, they
will be removed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2021-09-02 19:11:35 +02:00 committed by Dirk Hohndel
parent 28fe6a7b38
commit 9376721873

View file

@ -3,11 +3,14 @@
#include "maintab.h"
#include "desktop-widgets/simplewidgets.h" // For isGnome3Session()
#include "desktop-widgets/modeldelegates.h"
#include "core/dive.h"
#include "core/selection.h"
#include "commands/command.h"
#include "qt-models/cylindermodel.h"
#include "qt-models/weightmodel.h"
#include <QMessageBox>
#include <QSettings>
#include <QCompleter>
@ -162,10 +165,21 @@ void TabDiveEquipment::editCylinderWidget(const QModelIndex &index)
if (!index.isValid())
return;
if (index.column() == CylindersModel::REMOVE)
if (index.column() == CylindersModel::REMOVE) {
int cylinder_id = cylindersModel->mapToSource(index).row();
for (dive *d: getDiveSelection()) {
if (cylinder_with_sensor_sample(d, cylinder_id)) {
if (QMessageBox::warning(this, tr("Remove cylinder?"),
tr("The deleted cylinder has sensor readings, which will be lost.\n"
"Do you want to continue?"),
QMessageBox::Yes|QMessageBox::No) != QMessageBox::Yes)
return;
}
}
divesEdited(Command::removeCylinder(cylindersModel->mapToSource(index).row(), false));
else
} else {
ui.cylinders->edit(index);
}
}
void TabDiveEquipment::editWeightWidget(const QModelIndex &index)