diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-10-06 10:58:12 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-10-07 17:50:51 +0300 |
commit | 97991e2b9fff4254c2b40417bf6d7496ba0d849f (patch) | |
tree | a2b9af681e9ac5e72e4846736df001f75f7cc788 /qt-models/yearlystatisticsmodel.cpp | |
parent | 68fdc0b6f49c81cb61387b7d006807509280c9df (diff) | |
download | subsurface-97991e2b9fff4254c2b40417bf6d7496ba0d849f.tar.gz |
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 <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models/yearlystatisticsmodel.cpp')
-rw-r--r-- | qt-models/yearlystatisticsmodel.cpp | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/qt-models/yearlystatisticsmodel.cpp b/qt-models/yearlystatisticsmodel.cpp index 89a6ad0e2..d713be8f1 100644 --- a/qt-models/yearlystatisticsmodel.cpp +++ b/qt-models/yearlystatisticsmodel.cpp @@ -176,13 +176,15 @@ void YearlyStatisticsModel::update_yearly_stats() { int i, month = 0; unsigned int j, combined_months; + stats_summary_auto_free stats; + calculate_stats_summary(&stats); - for (i = 0; stats_yearly != NULL && stats_yearly[i].period; ++i) { - YearStatisticsItem *item = new YearStatisticsItem(stats_yearly[i]); + for (i = 0; stats.stats_yearly != NULL && stats.stats_yearly[i].period; ++i) { + YearStatisticsItem *item = new YearStatisticsItem(stats.stats_yearly[i]); combined_months = 0; - for (j = 0; combined_months < stats_yearly[i].selection_size; ++j) { - combined_months += stats_monthly[month].selection_size; - YearStatisticsItem *iChild = new YearStatisticsItem(stats_monthly[month]); + for (j = 0; combined_months < stats.stats_yearly[i].selection_size; ++j) { + combined_months += stats.stats_monthly[month].selection_size; + YearStatisticsItem *iChild = new YearStatisticsItem(stats.stats_monthly[month]); item->children.append(iChild); iChild->parent = item; month++; @@ -191,11 +193,10 @@ void YearlyStatisticsModel::update_yearly_stats() item->parent = rootItem.get(); } - - if (stats_by_trip != NULL && stats_by_trip[0].is_trip == true) { - YearStatisticsItem *item = new YearStatisticsItem(stats_by_trip[0]); - for (i = 1; stats_by_trip != NULL && stats_by_trip[i].is_trip; ++i) { - YearStatisticsItem *iChild = new YearStatisticsItem(stats_by_trip[i]); + if (stats.stats_by_trip != NULL && stats.stats_by_trip[0].is_trip == true) { + YearStatisticsItem *item = new YearStatisticsItem(stats.stats_by_trip[0]); + for (i = 1; stats.stats_by_trip != NULL && stats.stats_by_trip[i].is_trip; ++i) { + YearStatisticsItem *iChild = new YearStatisticsItem(stats.stats_by_trip[i]); item->children.append(iChild); iChild->parent = item; } @@ -204,12 +205,12 @@ void YearlyStatisticsModel::update_yearly_stats() } /* Show the statistic sorted by dive type */ - if (stats_by_type != NULL && stats_by_type[0].selection_size) { - YearStatisticsItem *item = new YearStatisticsItem(stats_by_type[0]); + if (stats.stats_by_type != NULL && stats.stats_by_type[0].selection_size) { + YearStatisticsItem *item = new YearStatisticsItem(stats.stats_by_type[0]); for (i = 1; i <= NUM_DIVEMODE; ++i) { - if (stats_by_type[i].selection_size == 0) + if (stats.stats_by_type[i].selection_size == 0) continue; - YearStatisticsItem *iChild = new YearStatisticsItem(stats_by_type[i]); + YearStatisticsItem *iChild = new YearStatisticsItem(stats.stats_by_type[i]); item->children.append(iChild); iChild->parent = item; } |