diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2014-06-09 22:45:44 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-06-09 22:48:21 -0700 |
commit | 8a0d852a7c17643bd6d45751c8b7489c23699829 (patch) | |
tree | 2168e215a9caac3aede8022aeafad8f544fc29d9 /qthelper.cpp | |
parent | 01026046451ef706bb184fad01032bb4c11add35 (diff) | |
download | subsurface-8a0d852a7c17643bd6d45751c8b7489c23699829.tar.gz |
Add gas consumption statistic for selected dives
We already did a list of gases and volume consumed for the selected dive
on the Dive Info tab, but did not provide that same data on the Stats tab
for all the selected dives.
I arbitrary limited this to eight gases (as the list can get quite long
when you select a lot of dives). The gases are sorted by volume consumed.
Fixes #535
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qthelper.cpp')
-rw-r--r-- | qthelper.cpp | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/qthelper.cpp b/qthelper.cpp index 7eba936a6..8b7b3960f 100644 --- a/qthelper.cpp +++ b/qthelper.cpp @@ -1,11 +1,12 @@ #include "qthelper.h" #include "qt-gui.h" #include "dive.h" +#include "statistics.h" #include <exif.h> #include "file.h" #include <QRegExp> #include <QDir> - +#include <QMap> #include <QDebug> #include <QSettings> #include <libxslt/documents.h> @@ -280,3 +281,31 @@ extern "C" void picture_load_exif_data(struct picture *p, timestamp_t *timestamp free(mem.buffer); return; } + +static bool lessThan(const QPair<QString, int> &a, const QPair<QString, int> &b) +{ + return a.second < b.second; +} + +void selectedDivesGasUsed(QVector<QPair<QString, int> > &gasUsedOrdered) +{ + int i, j; + struct dive *d; + QString gas; + QMap<QString, int> gasUsed; + for_each_dive (i, d) { + if (!d->selected) + continue; + volume_t diveGases[MAX_CYLINDERS] = {}; + get_gas_used(d, diveGases); + for (j = 0; j < MAX_CYLINDERS; j++) + if (diveGases[j].mliter) { + QString gasName = gasname(&d->cylinder[j].gasmix); + gasUsed[gasName] += diveGases[j].mliter; + } + } + Q_FOREACH(gas, gasUsed.keys()) { + gasUsedOrdered.append(QPair<QString, int>(gas, gasUsed[gas])); + } + qSort(gasUsedOrdered.begin(), gasUsedOrdered.end(), lessThan); +} |