diff --git a/CHANGELOG.md b/CHANGELOG.md index 9201a4b4a..3f0a31994 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ import: allow import of divesites without UUID divelist: do not include planned versions of a dive if there is real data desktop: fix key composition in tag widgets and dive site widget +desktop: use combobox for moving sensor between cylinders mobile: send log files as attachments for support emails on iOS mobile: allow cloud account deletion (Apple app store requirement) mobile: fix listing of local cloud cache directories diff --git a/commands/command_edit.cpp b/commands/command_edit.cpp index 250acd8de..3a9b23556 100644 --- a/commands/command_edit.cpp +++ b/commands/command_edit.cpp @@ -1361,6 +1361,9 @@ void EditSensors::mapSensors(int toCyl, int fromCyl) for (int s = 0; s < MAX_SENSORS; ++s) { if (dc->sample[i].pressure[s].mbar && dc->sample[i].sensor[s] == fromCyl) dc->sample[i].sensor[s] = toCyl; + // In case the cylinder we are moving to has a sensor attached, move it to the other cylinder + else if (dc->sample[i].pressure[s].mbar && dc->sample[i].sensor[s] == toCyl) + dc->sample[i].sensor[s] = fromCyl; } } emit diveListNotifier.diveComputerEdited(dc); diff --git a/desktop-widgets/modeldelegates.cpp b/desktop-widgets/modeldelegates.cpp index 1f8dac9f4..570bed872 100644 --- a/desktop-widgets/modeldelegates.cpp +++ b/desktop-widgets/modeldelegates.cpp @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include "desktop-widgets/modeldelegates.h" +#include "core/sample.h" #include "core/subsurface-string.h" #include "core/gettextfromc.h" #include "desktop-widgets/mainwindow.h" @@ -281,6 +282,42 @@ void TankUseDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, c model->setData(index, comboBox->currentIndex()); } + +SensorDelegate::SensorDelegate(QObject *parent) : QStyledItemDelegate(parent) +{ +} + +QWidget *SensorDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index) const +{ + QComboBox *comboBox = new QComboBox(parent); + std::vector sensors; + const struct divecomputer *currentdc = get_dive_dc(current_dive, dc_number); + for (int i = 0; i < currentdc->samples; ++i) { + auto &sample = currentdc->sample[i]; + for (int s = 0; s < MAX_SENSORS; ++s) { + if (sample.pressure[s].mbar) { + if (std::find(sensors.begin(), sensors.end(), sample.sensor[s]) == sensors.end()) + sensors.push_back(sample.sensor[s]); + } + } + } + std::sort(sensors.begin(), sensors.end()); + for (auto s : sensors) + comboBox->addItem(QString::number(s)); + + comboBox->setCurrentIndex(-1); + QString indexString = index.data().toString(); + if (!indexString.isEmpty()) + comboBox->setCurrentText(indexString); + return comboBox; +} + +void SensorDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const +{ + QComboBox *comboBox = qobject_cast(editor); + model->setData(index, comboBox->currentText()); +} + void WSInfoDelegate::editorClosed(QWidget *, QAbstractItemDelegate::EndEditHint hint) { WeightModel *mymodel = qobject_cast(currCombo.model); diff --git a/desktop-widgets/modeldelegates.h b/desktop-widgets/modeldelegates.h index f3858ce1e..7d76b6b9b 100644 --- a/desktop-widgets/modeldelegates.h +++ b/desktop-widgets/modeldelegates.h @@ -79,6 +79,15 @@ private: void setEditorData(QWidget *editor, const QModelIndex &index) const override; }; +class SensorDelegate : public QStyledItemDelegate { + Q_OBJECT +public: + explicit SensorDelegate(QObject *parent = 0); +private: + void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override; + QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override; +}; + class WSInfoDelegate : public ComboBoxDelegate { Q_OBJECT public: diff --git a/desktop-widgets/tab-widgets/TabDiveEquipment.cpp b/desktop-widgets/tab-widgets/TabDiveEquipment.cpp index 84b159c8f..2524fb371 100644 --- a/desktop-widgets/tab-widgets/TabDiveEquipment.cpp +++ b/desktop-widgets/tab-widgets/TabDiveEquipment.cpp @@ -61,6 +61,7 @@ TabDiveEquipment::TabDiveEquipment(QWidget *parent) : TabBase(parent), ui.cylinders->view()->setItemDelegateForColumn(CylindersModel::TYPE, new TankInfoDelegate(this)); ui.cylinders->view()->setItemDelegateForColumn(CylindersModel::USE, new TankUseDelegate(this)); + ui.cylinders->view()->setItemDelegateForColumn(CylindersModel::SENSORS, new SensorDelegate(this)); ui.weights->view()->setItemDelegateForColumn(WeightModel::TYPE, new WSInfoDelegate(this)); ui.cylinders->view()->setColumnHidden(CylindersModel::DEPTH, true); ui.cylinders->view()->setColumnHidden(CylindersModel::WORKINGPRESS_INT, true); diff --git a/qt-models/cylindermodel.cpp b/qt-models/cylindermodel.cpp index bc8d3e7a3..6b95b032b 100644 --- a/qt-models/cylindermodel.cpp +++ b/qt-models/cylindermodel.cpp @@ -240,23 +240,17 @@ QVariant CylindersModel::data(const QModelIndex &index, int role) const case SIZE_INT: return static_cast(cyl->type.size.mliter); case SENSORS: { - std::vector sensors; const struct divecomputer *currentdc = get_dive_dc(current_dive, dc_number); for (int i = 0; i < currentdc->samples; ++i) { auto &sample = currentdc->sample[i]; - for (auto s = 0; s < MAX_SENSORS; ++s) { + for (int s = 0; s < MAX_SENSORS; ++s) { if (sample.pressure[s].mbar) { if (sample.sensor[s] == index.row()) - return tr("Sensor attached, can't move another sensor here."); - else if (std::find(sensors.begin(), sensors.end(), sample.sensor[s]) == sensors.end()) - sensors.push_back(sample.sensor[s]); + return QString::number(sample.sensor[s]); } } } - QStringList sensorStrings; - for (auto s : sensors) - sensorStrings << QString::number(s); - return tr("Select one of these cylinders: ") + sensorStrings.join(","); + return QString(); } } break; @@ -477,14 +471,6 @@ bool CylindersModel::setData(const QModelIndex &index, const QVariant &value, in type = Command::EditCylinderType::TYPE; break; case SENSORS: { - std::vector sensors; - for (auto &sensor : vString.split(",")) { - bool ok = false; - int s = sensor.toInt(&ok); - if (ok && s < MAX_SENSORS) - sensors.push_back(s); - } - bool ok = false; int s = vString.toInt(&ok); if (ok) { @@ -553,19 +539,6 @@ Qt::ItemFlags CylindersModel::flags(const QModelIndex &index) const { if (index.column() == REMOVE || index.column() == USE) return Qt::ItemIsEnabled; - if (index.column() == SENSORS) { - const struct divecomputer *currentdc = get_dive_dc(current_dive, dc_number); - for (int i = 0; i < currentdc->samples; ++i) { - auto &sample = currentdc->sample[i]; - for (auto s = 0; s < MAX_SENSORS; ++s) { - if (sample.pressure[s].mbar) { - if (sample.sensor[s] == index.row()) - // Sensor attached, not editable. - return QAbstractItemModel::flags(index); - } - } - } - } return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; }