summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--helpers.h1
-rw-r--r--qt-ui/maintab.cpp17
-rw-r--r--qt-ui/maintab.ui46
-rw-r--r--qthelper.cpp31
4 files changed, 81 insertions, 14 deletions
diff --git a/helpers.h b/helpers.h
index 445e9135c..392dcb5ac 100644
--- a/helpers.h
+++ b/helpers.h
@@ -33,6 +33,7 @@ QString get_dive_date_string(timestamp_t when);
QString get_short_dive_date_string(timestamp_t when);
QString get_trip_date_string(timestamp_t when, int nr);
QString uiLanguage(QLocale *callerLoc);
+void selectedDivesGasUsed(QVector<QPair<QString, int> > &gasUsed);
#define M_OR_FT(_m, _f) ((prefs.units.length == units::METERS) ? ((_m) * 1000) : (feet_to_mm(_f)))
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index 19b47c872..5b8985b3e 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -530,6 +530,23 @@ void MainTab::updateDiveInfo(int dive)
ui.timeLimits->setAverage(get_time_string(seconds, 0));
ui.timeLimits->setMaximum(get_time_string(stats_selection.longest_time.seconds, 0));
ui.timeLimits->setMinimum(get_time_string(stats_selection.shortest_time.seconds, 0));
+ // now let's get some gas use statistics
+ QVector<QPair<QString, int> > gasUsed;
+ QString gasUsedString;
+ QPair<QString, int> topGases[8] = { };
+ volume_t vol;
+ selectedDivesGasUsed(gasUsed);
+ for (int j = 0; j < 8; j++) {
+ if (gasUsed.isEmpty())
+ break;
+ QPair<QString, int> gasPair = gasUsed.last();
+ gasUsed.pop_back();
+ vol.mliter = gasPair.second;
+ gasUsedString.append(gasPair.first).append(": ").append(get_volume_string(vol, true)).append("\n");
+ }
+ if (!gasUsed.isEmpty())
+ gasUsedString.append("...");
+ ui.gasConsumption->setText(gasUsedString);
} else {
/* clear the fields */
clearInfo();
diff --git a/qt-ui/maintab.ui b/qt-ui/maintab.ui
index 904a49304..2a0d3353e 100644
--- a/qt-ui/maintab.ui
+++ b/qt-ui/maintab.ui
@@ -37,8 +37,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>662</width>
- <height>649</height>
+ <width>668</width>
+ <height>658</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_2">
@@ -289,8 +289,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>662</width>
- <height>649</height>
+ <width>100</width>
+ <height>30</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_5">
@@ -369,8 +369,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>662</width>
- <height>649</height>
+ <width>387</width>
+ <height>285</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_6">
@@ -679,8 +679,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>662</width>
- <height>649</height>
+ <width>337</width>
+ <height>157</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_7">
@@ -766,7 +766,7 @@
</layout>
</widget>
</item>
- <item row="1" column="2">
+ <item row="2" column="1">
<widget class="QGroupBox" name="groupBox_7b">
<property name="title">
<string>Dives</string>
@@ -785,8 +785,27 @@
</layout>
</widget>
</item>
- <item row="2" column="0">
- <spacer>
+ <item row="1" column="2">
+ <widget class="QGroupBox" name="groupBox_13">
+ <property name="title">
+ <string>Gas Consumption</string>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout_15b">
+ <item>
+ <widget class="QLabel" name="gasConsumption">
+ <property name="text">
+ <string/>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item row="3" column="0">
+ <spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
@@ -795,8 +814,8 @@
</property>
<property name="sizeHint" stdset="0">
<size>
- <width>20</width>
- <height>20</height>
+ <width>0</width>
+ <height>0</height>
</size>
</property>
</spacer>
@@ -808,6 +827,7 @@
<zorder>groupBox_14</zorder>
<zorder>groupBoxb</zorder>
<zorder>groupBox_7b</zorder>
+ <zorder>groupBox_13</zorder>
</widget>
</widget>
</item>
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);
+}