diff options
Diffstat (limited to 'qt-ui/models.cpp')
-rw-r--r-- | qt-ui/models.cpp | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index fec7d02ed..69a276bfb 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -14,6 +14,7 @@ #include "qthelper.h" #include "gettextfromc.h" #include "display.h" +#include "color.h" #include <QCoreApplication> #include <QDebug> @@ -387,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; } @@ -394,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; @@ -404,7 +407,7 @@ void CylindersModel::remove(const QModelIndex &index) ((DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING && DivePlannerPointsModel::instance()->tankInUse(cyl->gasmix)) || (DivePlannerPointsModel::instance()->currentMode() == DivePlannerPointsModel::NOTHING && - (cyl->manually_added || is_cylinder_used(&displayed_dive, index.row()))))) { + is_cylinder_used(&displayed_dive, index.row())))) { QMessageBox::warning(MainWindow::instance(), TITLE_OR_TEXT( tr("Cylinder cannot be removed"), tr("This gas is in use. Only cylinders that are not used in the dive can be removed.")), @@ -418,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), @@ -1191,7 +1207,7 @@ QVariant DiveItem::data(int column, int role) const retVal = dive->maxcns; break; case LOCATION: - retVal = QString(dive->location); + retVal = QString(get_dive_location(dive)); break; } break; @@ -1232,7 +1248,7 @@ QVariant DiveItem::data(int column, int role) const retVal = dive->maxcns; break; case LOCATION: - retVal = QString(dive->location); + retVal = QString(get_dive_location(dive)); break; case GAS: const char *gas_string = get_dive_gas_string(dive); @@ -1356,15 +1372,19 @@ QString DiveItem::displayDepthWithUnit() const QString DiveItem::displayDuration() const { - int hrs, mins; + int hrs, mins, fullmins, secs; struct dive *dive = get_dive_by_uniq_id(diveId); mins = (dive->duration.seconds + 59) / 60; + fullmins = dive->duration.seconds / 60; + secs = dive->duration.seconds - 60 * fullmins; hrs = mins / 60; mins -= hrs * 60; QString displayTime; if (hrs) displayTime = QString("%1:%2").arg(hrs).arg(mins, 2, 10, QChar('0')); + else if (mins < 15 || dive->dc.divemode == FREEDIVE) + displayTime = QString("%1m%2s").arg(fullmins).arg(secs, 2, 10, QChar('0')); else displayTime = QString("%1").arg(mins); return displayTime; @@ -2110,7 +2130,7 @@ QVariant ProfilePrintModel::data(const QModelIndex &index, int role) const } if (row == 1) { if (col == 0) - return QString(dive->location); + return QString(get_dive_location(dive)); if (col == 3) return QString(tr("Duration: %1 min")).arg(di.displayDuration()); } |