summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-10-06 16:50:46 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-10-07 17:50:51 +0300
commitdf16866292ac16430e840ccc0013a5914303cd0f (patch)
tree5fb145cbf2b8da6d37bb5b9e7b4d669c7fd90df2
parentb61f6f66d8859e62023e3818879b90de529e9a72 (diff)
downloadsubsurface-df16866292ac16430e840ccc0013a5914303cd0f.tar.gz
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>
-rw-r--r--core/divelogexportlogic.cpp2
-rw-r--r--core/statistics.c6
-rw-r--r--core/statistics.h2
-rw-r--r--desktop-widgets/templatelayout.cpp2
-rw-r--r--qt-models/yearlystatisticsmodel.cpp2
5 files changed, 8 insertions, 6 deletions
diff --git a/core/divelogexportlogic.cpp b/core/divelogexportlogic.cpp
index 27a42fbf7..1a0779422 100644
--- a/core/divelogexportlogic.cpp
+++ b/core/divelogexportlogic.cpp
@@ -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;
diff --git a/core/statistics.c b/core/statistics.c
index 5d9c8049a..6f5efe64f 100644
--- a/core/statistics.c
+++ b/core/statistics.c
@@ -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 */
diff --git a/core/statistics.h b/core/statistics.h
index d0cf5ab67..d3707b9cb 100644
--- a/core/statistics.h
+++ b/core/statistics.h
@@ -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);
diff --git a/desktop-widgets/templatelayout.cpp b/desktop-widgets/templatelayout.cpp
index 5bef7b172..e91441d18 100644
--- a/desktop-widgets/templatelayout.cpp
+++ b/desktop-widgets/templatelayout.cpp
@@ -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));
diff --git a/qt-models/yearlystatisticsmodel.cpp b/qt-models/yearlystatisticsmodel.cpp
index d713be8f1..c8aa2639b 100644
--- a/qt-models/yearlystatisticsmodel.cpp
+++ b/qt-models/yearlystatisticsmodel.cpp
@@ -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]);