Statistics: only consider selected dives in HTML export statistics

If only selected dives were exported into HTML, the statistics would
nevertheless cover all dives. A counter-intuitive behavior. Fix by
adding a selected_only flag to calculate_stats_summary().

Reported-by: Jan Mulder <jlmulder@xs4all.nl>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2018-10-06 16:50:46 +02:00 committed by Dirk Hohndel
parent b61f6f66d8
commit df16866292
5 changed files with 8 additions and 6 deletions

View file

@ -79,7 +79,7 @@ static void exportHTMLstatistics(const QString filename, struct htmlExportSettin
stats_t total_stats;
calculate_stats_summary(&stats);
calculate_stats_summary(&stats, hes.selectedOnly);
total_stats.selection_size = 0;
total_stats.total_time.seconds = 0;

View file

@ -3,7 +3,7 @@
*
* core logic for the Info & Stats page -
* char *get_minutes(int seconds);
* void calculate_stats_summary(struct stats_summary *out);
* void calculate_stats_summary(struct stats_summary *out, bool selected_only);
* void calculate_stats_selected(stats_t *stats_selection);
*/
#include "gettext.h"
@ -91,7 +91,7 @@ char *get_minutes(int seconds)
* Before first use, it should be initialized with init_stats_summary().
* After use, memory must be released with free_stats_summary().
*/
void calculate_stats_summary(struct stats_summary *out)
void calculate_stats_summary(struct stats_summary *out, bool selected_only)
{
int idx;
struct dive *dp;
@ -147,6 +147,8 @@ void calculate_stats_summary(struct stats_summary *out)
/* this relies on the fact that the dives in the dive_table
* are in chronological order */
for_each_dive (idx, dp) {
if (selected_only && !dp->selected)
continue;
process_dive(dp, &stats);
/* yearly statistics */

View file

@ -52,7 +52,7 @@ extern "C" {
extern char *get_minutes(int seconds);
extern void init_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, bool selected_only);
extern void calculate_stats_selected(stats_t *stats_selection);
extern void get_gas_used(struct dive *dive, volume_t gases[MAX_CYLINDERS]);
extern void selected_dives_gas_parts(volume_t *o2_tot, volume_t *he_tot);

View file

@ -208,7 +208,7 @@ QString TemplateLayout::generateStatistics()
int i = 0;
stats_summary_auto_free stats;
calculate_stats_summary(&stats);
calculate_stats_summary(&stats, false);
while (stats.stats_yearly != NULL && stats.stats_yearly[i].period) {
YearInfo year(stats.stats_yearly[i]);
years.append(QVariant::fromValue(year));

View file

@ -177,7 +177,7 @@ void YearlyStatisticsModel::update_yearly_stats()
int i, month = 0;
unsigned int j, combined_months;
stats_summary_auto_free stats;
calculate_stats_summary(&stats);
calculate_stats_summary(&stats, false);
for (i = 0; stats.stats_yearly != NULL && stats.stats_yearly[i].period; ++i) {
YearStatisticsItem *item = new YearStatisticsItem(stats.stats_yearly[i]);