diff options
Diffstat (limited to 'desktop-widgets/tab-widgets')
-rw-r--r-- | desktop-widgets/tab-widgets/TabDiveEquipment.cpp | 33 | ||||
-rw-r--r-- | desktop-widgets/tab-widgets/TabDiveInformation.cpp | 8 | ||||
-rw-r--r-- | desktop-widgets/tab-widgets/TabDiveStatistics.cpp | 6 | ||||
-rw-r--r-- | desktop-widgets/tab-widgets/maintab.cpp | 13 |
4 files changed, 25 insertions, 35 deletions
diff --git a/desktop-widgets/tab-widgets/TabDiveEquipment.cpp b/desktop-widgets/tab-widgets/TabDiveEquipment.cpp index af4dcbd44..6f43fc5a2 100644 --- a/desktop-widgets/tab-widgets/TabDiveEquipment.cpp +++ b/desktop-widgets/tab-widgets/TabDiveEquipment.cpp @@ -207,9 +207,10 @@ static QVector<dive *> getSelectedDivesCurrentLast() return res; } -// TODO: This is only a temporary function until undo of weightsystems is implemented. +// TODO: This are only temporary functions until undo of weightsystems and cylinders is implemented. // Therefore it is not worth putting it in a header. extern bool weightsystems_equal(const dive *d1, const dive *d2); +extern bool cylinders_equal(const dive *d1, const dive *d2); void TabDiveEquipment::acceptChanges() { @@ -227,31 +228,13 @@ void TabDiveEquipment::acceptChanges() if (cylindersModel->changed) { mark_divelist_changed(true); MODIFY_DIVES(selectedDives, - for (int i = 0; i < MAX_CYLINDERS; i++) { - if (mydive != cd) { - if (same_string(mydive->cylinder[i].type.description, cd->cylinder[i].type.description)) { - // if we started out with the same cylinder description (for multi-edit) or if we do copt & paste - // make sure that we have the same cylinder type and copy the gasmix, but DON'T copy the start - // and end pressures (those are per dive after all) - if (!same_string(mydive->cylinder[i].type.description, displayed_dive.cylinder[i].type.description)) { - free((void*)mydive->cylinder[i].type.description); - mydive->cylinder[i].type.description = copy_string(displayed_dive.cylinder[i].type.description); - } - mydive->cylinder[i].type.size = displayed_dive.cylinder[i].type.size; - mydive->cylinder[i].type.workingpressure = displayed_dive.cylinder[i].type.workingpressure; - mydive->cylinder[i].gasmix = displayed_dive.cylinder[i].gasmix; - mydive->cylinder[i].cylinder_use = displayed_dive.cylinder[i].cylinder_use; - mydive->cylinder[i].depth = displayed_dive.cylinder[i].depth; - } - } - } + // if we started out with the same cylinder description (for multi-edit) or if we do copt & paste + // make sure that we have the same cylinder type and copy the gasmix, but DON'T copy the start + // and end pressures (those are per dive after all) + if (cylinders_equal(mydive, cd) && mydive != cd) + copy_cylinder_types(&displayed_dive, cd); + copy_cylinders(&displayed_dive.cylinders, &cd->cylinders); ); - for (int i = 0; i < MAX_CYLINDERS; i++) { - // copy the cylinder but make sure we have our own copy of the strings - free((void*)cd->cylinder[i].type.description); - 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 * and sensor idx in samples as well * - so far this is ONLY supported for a single selected dive */ diff --git a/desktop-widgets/tab-widgets/TabDiveInformation.cpp b/desktop-widgets/tab-widgets/TabDiveInformation.cpp index d5ce7d035..afa427bdc 100644 --- a/desktop-widgets/tab-widgets/TabDiveInformation.cpp +++ b/desktop-widgets/tab-widgets/TabDiveInformation.cpp @@ -53,20 +53,20 @@ void TabDiveInformation::updateProfile() ui->maximumDepthText->setText(get_depth_string(current_dive->maxdepth, true)); ui->averageDepthText->setText(get_depth_string(current_dive->meandepth, true)); - volume_t *gases = get_gas_used(current_dive); + volume_t *gases = get_gas_used(current_dive); QString volumes; - std::vector<int> mean(MAX_CYLINDERS), duration(MAX_CYLINDERS); + std::vector<int> mean(current_dive->cylinders.nr), duration(current_dive->cylinders.nr); per_cylinder_mean_depth(current_dive, select_dc(current_dive), &mean[0], &duration[0]); volume_t sac; QString gaslist, SACs, separator; - for (int i = 0; i < MAX_CYLINDERS; i++) { + for (int i = 0; i < current_dive->cylinders.nr; i++) { if (!is_cylinder_used(current_dive, i)) continue; gaslist.append(separator); volumes.append(separator); SACs.append(separator); separator = "\n"; - gaslist.append(gasname(current_dive->cylinder[i].gasmix)); + gaslist.append(gasname(current_dive->cylinders.cylinders[i].gasmix)); if (!gases[i].mliter) continue; volumes.append(get_volume_string(gases[i], true)); diff --git a/desktop-widgets/tab-widgets/TabDiveStatistics.cpp b/desktop-widgets/tab-widgets/TabDiveStatistics.cpp index ee090c6bc..f3c5f5807 100644 --- a/desktop-widgets/tab-widgets/TabDiveStatistics.cpp +++ b/desktop-widgets/tab-widgets/TabDiveStatistics.cpp @@ -118,16 +118,12 @@ void TabDiveStatistics::updateData() QVector<QPair<QString, int> > gasUsed = selectedDivesGasUsed(); QString gasUsedString; volume_t vol; - for (int j = 0; j < MAX_CYLINDERS; j++) { - if (gasUsed.isEmpty()) - break; + while (!gasUsed.isEmpty()) { QPair<QString, int> gasPair = gasUsed.last(); gasUsed.pop_back(); vol.mliter = gasPair.second; gasUsedString.append(gasPair.first).append(": ").append(get_volume_string(vol, true)).append("\n"); } - if (!gasUsed.isEmpty()) - gasUsedString.append("..."); volume_t o2_tot = {}, he_tot = {}; selected_dives_gas_parts(&o2_tot, &he_tot); diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp index 3aea3fe39..4d3d7397d 100644 --- a/desktop-widgets/tab-widgets/maintab.cpp +++ b/desktop-widgets/tab-widgets/maintab.cpp @@ -651,13 +651,24 @@ bool weightsystems_equal(const dive *d1, const dive *d2) return true; } +bool cylinders_equal(const dive *d1, const dive *d2) +{ + if (d1->cylinders.nr != d2->cylinders.nr) + return false; + for (int i = 0; i < d1->cylinders.nr; ++i) { + if (!same_cylinder(d1->cylinders.cylinders[i], d2->cylinders.cylinders[i])) + return false; + } + return true; +} + void MainTab::rejectChanges() { EditMode lastMode = editMode; if (lastMode != NONE && current_dive && (modified || - memcmp(¤t_dive->cylinder[0], &displayed_dive.cylinder[0], sizeof(cylinder_t) * MAX_CYLINDERS) || + !cylinders_equal(current_dive, &displayed_dive) || !weightsystems_equal(current_dive, &displayed_dive))) { if (QMessageBox::warning(MainWindow::instance(), TITLE_OR_TEXT(tr("Discard the changes?"), tr("You are about to discard your changes.")), |