mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
0102604645
commit
8a0d852a7c
4 changed files with 81 additions and 14 deletions
31
qthelper.cpp
31
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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue