Statistics: un-globalize stats_selection

The statistics of the selected dives were calculated
a) into a global objects and
b) at a completely different place than where they're used.

There's no plausible reason for either. There fore render
into a caller-provided structure at the place of use.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2018-10-06 16:30:57 +02:00 committed by Dirk Hohndel
parent 97991e2b9f
commit b61f6f66d8
4 changed files with 9 additions and 11 deletions

View file

@ -4,6 +4,7 @@
* core logic for the Info & Stats page - * core logic for the Info & Stats page -
* char *get_minutes(int seconds); * char *get_minutes(int seconds);
* void calculate_stats_summary(struct stats_summary *out); * void calculate_stats_summary(struct stats_summary *out);
* void calculate_stats_selected(stats_t *stats_selection);
*/ */
#include "gettext.h" #include "gettext.h"
#include <string.h> #include <string.h>
@ -14,8 +15,6 @@
#include "divelist.h" #include "divelist.h"
#include "statistics.h" #include "statistics.h"
stats_t stats_selection;
static void process_temperatures(struct dive *dp, stats_t *stats) static void process_temperatures(struct dive *dp, stats_t *stats)
{ {
temperature_t min_temp, mean_temp, max_temp = {.mkelvin = 0}; temperature_t min_temp, mean_temp, max_temp = {.mkelvin = 0};
@ -224,21 +223,21 @@ void init_stats_summary(struct stats_summary *stats)
} }
/* make sure we skip the selected summary entries */ /* make sure we skip the selected summary entries */
void process_selected_dives(void) void calculate_stats_selected(stats_t *stats_selection)
{ {
struct dive *dive; struct dive *dive;
unsigned int i, nr; unsigned int i, nr;
memset(&stats_selection, 0, sizeof(stats_selection)); memset(stats_selection, 0, sizeof(*stats_selection));
nr = 0; nr = 0;
for_each_dive(i, dive) { for_each_dive(i, dive) {
if (dive->selected) { if (dive->selected) {
process_dive(dive, &stats_selection); process_dive(dive, stats_selection);
nr++; nr++;
} }
} }
stats_selection.selection_size = nr; stats_selection->selection_size = nr;
} }
#define SOME_GAS 5000 // 5bar drop in cylinder pressure makes cylinder used #define SOME_GAS 5000 // 5bar drop in cylinder pressure makes cylinder used

View file

@ -37,7 +37,6 @@ typedef struct
bool is_trip; bool is_trip;
char *location; char *location;
} stats_t; } stats_t;
extern stats_t stats_selection;
struct stats_summary { struct stats_summary {
stats_t *stats_yearly; stats_t *stats_yearly;
@ -54,9 +53,9 @@ extern char *get_minutes(int seconds);
extern void init_stats_summary(struct stats_summary *stats); extern void init_stats_summary(struct stats_summary *stats);
extern void free_stats_summary(struct stats_summary *stats); extern void free_stats_summary(struct stats_summary *stats);
extern void calculate_stats_summary(struct stats_summary *stats); extern void calculate_stats_summary(struct stats_summary *stats);
extern void calculate_stats_selected(stats_t *stats_selection);
extern void get_gas_used(struct dive *dive, volume_t gases[MAX_CYLINDERS]); extern void get_gas_used(struct dive *dive, volume_t gases[MAX_CYLINDERS]);
extern void process_selected_dives(void); extern void selected_dives_gas_parts(volume_t *o2_tot, volume_t *he_tot);
void selected_dives_gas_parts(volume_t *o2_tot, volume_t *he_tot);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -44,6 +44,8 @@ void TabDiveStatistics::clear()
void TabDiveStatistics::updateData() void TabDiveStatistics::updateData()
{ {
stats_t stats_selection;
calculate_stats_selected(&stats_selection);
clear(); clear();
ui->depthLimits->setMaximum(get_depth_string(stats_selection.max_depth, true)); ui->depthLimits->setMaximum(get_depth_string(stats_selection.max_depth, true));
if (amount_selected > 1) if (amount_selected > 1)

View file

@ -424,8 +424,6 @@ void MainTab::updateDiveInfo(bool clear)
setEnabled(false); setEnabled(false);
editMode = IGNORE; // don't trigger on changes to the widgets editMode = IGNORE; // don't trigger on changes to the widgets
process_selected_dives();
for (auto widget : extraWidgets) { for (auto widget : extraWidgets) {
widget->updateData(); widget->updateData();
} }