diff options
Diffstat (limited to 'qt-ui')
-rw-r--r-- | qt-ui/maintab.cpp | 10 | ||||
-rw-r--r-- | qt-ui/models.cpp | 15 |
2 files changed, 25 insertions, 0 deletions
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index a75b80722..314626c5d 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -813,6 +813,16 @@ void MainTab::acceptChanges() cd->cylinder[i] = displayed_dive.cylinder[i]; cd->cylinder[i].type.description = copy_string(displayed_dive.cylinder[i].type.description); } + /* if cylinders changed we may have changed gas change events + * - so far this is ONLY supported for a single selected dive */ + struct divecomputer *tdc = ¤t_dive->dc; + struct divecomputer *sdc = &displayed_dive.dc; + while(tdc && sdc) { + free_events(tdc->events); + copy_events(sdc, tdc); + tdc = tdc->next; + sdc = sdc->next; + } do_replot = true; } diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index 6376bb82a..d6b425b52 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -388,6 +388,7 @@ Qt::ItemFlags CylindersModel::flags(const QModelIndex &index) const void CylindersModel::remove(const QModelIndex &index) { + int mapping[MAX_CYLINDERS]; if (index.column() != REMOVE) { return; } @@ -395,6 +396,7 @@ void CylindersModel::remove(const QModelIndex &index) cylinder_t *cyl = &displayed_dive.cylinder[index.row()]; struct gasmix *mygas = &cyl->gasmix; for (int i = 0; i < MAX_CYLINDERS; i++) { + mapping[i] = i; if (i == index.row() || cylinder_none(&displayed_dive.cylinder[i])) continue; struct gasmix *gas2 = &displayed_dive.cylinder[i].gasmix; @@ -419,11 +421,24 @@ void CylindersModel::remove(const QModelIndex &index) // as first gas memmove(cyl, &displayed_dive.cylinder[same_gas], sizeof(*cyl)); remove_cylinder(&displayed_dive, same_gas); + mapping[same_gas] = 0; + for (int i = same_gas + 1; i < MAX_CYLINDERS; i++) + mapping[i] = i - 1; } else { remove_cylinder(&displayed_dive, index.row()); + if (same_gas > index.row()) + same_gas--; + mapping[index.row()] = same_gas; + for (int i = index.row() + 1; i < MAX_CYLINDERS; i++) + mapping[i] = i - 1; } changed = true; endRemoveRows(); + struct divecomputer *dc = &displayed_dive.dc; + while (dc) { + dc_cylinder_renumber(&displayed_dive, dc, mapping); + dc = dc->next; + } } WeightModel::WeightModel(QObject *parent) : CleanerTableModel(parent), |