mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: refactor per_cylinder_mean_depth()
This function had a horrendous interface: The caller would have to allocate two arrays of the correct size to be filled with data. The callee couldn't even check the size, because the data was passed as raw pointers. Instead, use std::vector<>, construct everything in the called function and do size-sanity check in the calling function. Use depth_t and duration_t instead of plain integers to represent mean depth and time. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
dbc06d78b6
commit
9cf753fa56
3 changed files with 54 additions and 49 deletions
|
@ -126,15 +126,12 @@ void TabDiveInformation::updateProfile()
|
|||
|
||||
std::vector<volume_t> gases = get_gas_used(currentDive);
|
||||
QString volumes;
|
||||
std::vector<int> mean(currentDive->cylinders.size()), duration(currentDive->cylinders.size());
|
||||
struct divecomputer *currentdc = parent.getCurrentDC();
|
||||
if (currentdc && !currentDive->cylinders.empty())
|
||||
per_cylinder_mean_depth(currentDive, currentdc, mean.data(), duration.data());
|
||||
auto mean = currentDive->per_cylinder_mean_depth_and_duration(parent.currentDC);
|
||||
volume_t sac;
|
||||
QString gaslist, SACs, separator;
|
||||
|
||||
for (size_t i = 0; i < currentDive->cylinders.size(); i++) {
|
||||
if (!currentDive->is_cylinder_used(i))
|
||||
if (!currentDive->is_cylinder_used(i) || i >= mean.size())
|
||||
continue;
|
||||
gaslist.append(separator); volumes.append(separator); SACs.append(separator);
|
||||
separator = "\n";
|
||||
|
@ -143,9 +140,8 @@ void TabDiveInformation::updateProfile()
|
|||
if (!gases[i].mliter)
|
||||
continue;
|
||||
volumes.append(get_volume_string(gases[i], true));
|
||||
if (duration[i]) {
|
||||
depth_t mean_depth = { .mm = mean[i] }; // Will be removed in upcoming commit
|
||||
sac.mliter = lrint(gases[i].mliter / (currentDive->depth_to_atm(mean_depth) * duration[i] / 60));
|
||||
if (mean[i].duration.seconds > 0) {
|
||||
sac.mliter = lrint(gases[i].mliter / (currentDive->depth_to_atm(mean[i].depth) * mean[i].duration.seconds / 60));
|
||||
SACs.append(get_volume_string(sac, true).append(tr("/min")));
|
||||
}
|
||||
}
|
||||
|
@ -155,7 +151,7 @@ void TabDiveInformation::updateProfile()
|
|||
ui->diveTimeText->setText(get_dive_duration_string(currentDive->duration.seconds, tr("h"), tr("min"), tr("sec"),
|
||||
" ", currentDive->dcs[0].divemode == FREEDIVE));
|
||||
|
||||
ui->sacText->setText(!currentDive->cylinders.empty() && mean[0] && currentDive->dcs[0].divemode != CCR ? std::move(SACs) : QString());
|
||||
ui->sacText->setText(!currentDive->cylinders.empty() && mean[0].depth.mm > 0 && currentDive->dcs[0].divemode != CCR ? std::move(SACs) : QString());
|
||||
|
||||
if (currentDive->surface_pressure.mbar == 0) {
|
||||
ui->atmPressVal->clear(); // If no atm pressure for dive then clear text box
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue