core: C++-ify statistics.c

The old code was wild: For the yearly statistics it would allocate
one entry per dive in the log. Of course, it would also leak
C-style strings.

Convert the whole thing to somewhat idiomatic C++.

Somewhat wasted work, because I'd like to convert the whole thing
to the new statistics code. But let's finish the conversion to C++
first.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-05-01 23:16:00 +02:00
parent 6d9dd5d0a1
commit a1ac99d5ed
12 changed files with 496 additions and 582 deletions

View file

@ -124,7 +124,7 @@ void TabDiveInformation::updateProfile()
ui->maximumDepthText->setText(get_depth_string(currentDive->maxdepth, true));
ui->averageDepthText->setText(get_depth_string(currentDive->meandepth, true));
volume_t *gases = get_gas_used(currentDive);
std::vector<volume_t> gases = get_gas_used(currentDive);
QString volumes;
std::vector<int> mean(currentDive->cylinders.nr), duration(currentDive->cylinders.nr);
struct divecomputer *currentdc = parent.getCurrentDC();
@ -148,7 +148,6 @@ void TabDiveInformation::updateProfile()
SACs.append(get_volume_string(sac, true).append(tr("/min")));
}
}
free(gases);
ui->gasUsedText->setText(volumes);
ui->oxygenHeliumText->setText(gaslist);

View file

@ -72,8 +72,7 @@ void TabDiveStatistics::cylinderChanged(dive *d)
void TabDiveStatistics::updateData(const std::vector<dive *> &, dive *currentDive, int)
{
stats_t stats_selection;
calculate_stats_selected(&stats_selection);
stats_t stats_selection = calculate_stats_selected();
clear();
if (amount_selected > 1 && stats_selection.selection_size >= 1) {
ui->depthLimits->setMaximum(get_depth_string(stats_selection.max_depth, true));
@ -135,13 +134,12 @@ void TabDiveStatistics::updateData(const std::vector<dive *> &, dive *currentDiv
vol.mliter = gasPair.second;
gasUsedString.append(gasPair.first).append(": ").append(get_volume_string(vol, true)).append("\n");
}
volume_t o2_tot = {}, he_tot = {};
selected_dives_gas_parts(&o2_tot, &he_tot);
auto [o2_tot, he_tot] = selected_dives_gas_parts();
/* No need to show the gas mixing information if diving
* with pure air, and only display the he / O2 part when
* it is used.
*/
* with pure air, and only display the he / O2 part when
* it is used.
*/
if (he_tot.mliter || o2_tot.mliter) {
gasUsedString.append(tr("These gases could be\nmixed from Air and using:\n"));
if (he_tot.mliter) {