From 97991e2b9fff4254c2b40417bf6d7496ba0d849f Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 6 Oct 2018 10:58:12 +0200 Subject: Statistics: remove global state / calculate only when needed Statistics were calculated into global variables every time the current dive was changed. Calculate statistics only when needed and into a structure provided by the caller. Signed-off-by: Berthold Stoeger --- desktop-widgets/templatelayout.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'desktop-widgets/templatelayout.cpp') diff --git a/desktop-widgets/templatelayout.cpp b/desktop-widgets/templatelayout.cpp index 0d6586390..5bef7b172 100644 --- a/desktop-widgets/templatelayout.cpp +++ b/desktop-widgets/templatelayout.cpp @@ -207,8 +207,10 @@ QString TemplateLayout::generateStatistics() QVariantList years; int i = 0; - while (stats_yearly != NULL && stats_yearly[i].period) { - YearInfo year(stats_yearly[i]); + stats_summary_auto_free stats; + calculate_stats_summary(&stats); + while (stats.stats_yearly != NULL && stats.stats_yearly[i].period) { + YearInfo year(stats.stats_yearly[i]); years.append(QVariant::fromValue(year)); i++; } -- cgit v1.2.3-70-g09d2