summaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
Diffstat (limited to 'qt-ui')
-rw-r--r--qt-ui/maintab.ui26
-rw-r--r--qt-ui/models.cpp114
2 files changed, 79 insertions, 61 deletions
diff --git a/qt-ui/maintab.ui b/qt-ui/maintab.ui
index c42dc4638..a89adfd2b 100644
--- a/qt-ui/maintab.ui
+++ b/qt-ui/maintab.ui
@@ -14,7 +14,7 @@
<string>TabWidget</string>
</property>
<property name="currentIndex">
- <number>1</number>
+ <number>0</number>
</property>
<widget class="QWidget" name="notesTab">
<attribute name="title">
@@ -259,7 +259,7 @@
<string>Dive Info</string>
</attribute>
<layout class="QGridLayout" name="gridLayout">
- <item row="0" column="0">
+ <item row="1" column="2">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>SAC</string>
@@ -278,7 +278,7 @@
</layout>
</widget>
</item>
- <item row="0" column="1">
+ <item row="1" column="0">
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Gases Used</string>
@@ -297,7 +297,7 @@
</layout>
</widget>
</item>
- <item row="1" column="0">
+ <item row="2" column="2">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>OTU</string>
@@ -316,7 +316,7 @@
</layout>
</widget>
</item>
- <item row="4" column="0">
+ <item row="0" column="0">
<widget class="QGroupBox" name="groupBox_5">
<property name="title">
<string>Date</string>
@@ -335,7 +335,7 @@
</layout>
</widget>
</item>
- <item row="5" column="0">
+ <item row="3" column="0">
<widget class="QGroupBox" name="groupBox_10">
<property name="title">
<string>Air Pressure</string>
@@ -354,7 +354,7 @@
</layout>
</widget>
</item>
- <item row="4" column="1">
+ <item row="3" column="1">
<widget class="QGroupBox" name="groupBox_9">
<property name="title">
<string>Air Temperature</string>
@@ -373,7 +373,7 @@
</layout>
</widget>
</item>
- <item row="0" column="2">
+ <item row="1" column="1">
<widget class="QGroupBox" name="groupBox_4">
<property name="title">
<string>Gas Consumed</string>
@@ -392,7 +392,7 @@
</layout>
</widget>
</item>
- <item row="1" column="1">
+ <item row="2" column="0">
<widget class="QGroupBox" name="groupBox_6">
<property name="title">
<string>Max. Depth</string>
@@ -411,7 +411,7 @@
</layout>
</widget>
</item>
- <item row="1" column="2">
+ <item row="2" column="1">
<widget class="QGroupBox" name="groupBox_7">
<property name="title">
<string>Ave. Depth</string>
@@ -430,7 +430,7 @@
</layout>
</widget>
</item>
- <item row="4" column="2">
+ <item row="3" column="2">
<widget class="QGroupBox" name="groupBox_8">
<property name="title">
<string>Water Temperature</string>
@@ -449,7 +449,7 @@
</layout>
</widget>
</item>
- <item row="5" column="1">
+ <item row="0" column="2">
<widget class="QGroupBox" name="groupBox_12">
<property name="title">
<string>Interval</string>
@@ -468,7 +468,7 @@
</layout>
</widget>
</item>
- <item row="5" column="2">
+ <item row="0" column="1">
<widget class="QGroupBox" name="groupBox_11">
<property name="title">
<string>Dive Time</string>
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp
index 3b2940a6c..0288e7107 100644
--- a/qt-ui/models.cpp
+++ b/qt-ui/models.cpp
@@ -59,6 +59,16 @@ int CylindersModel::columnCount(const QModelIndex& parent) const
return COLUMNS;
}
+static QVariant percent_string(fraction_t fraction)
+{
+ int permille = fraction.permille;
+
+ if (!permille)
+ return QVariant();
+
+ return QString("%1%").arg(permille / 10.0, 0, 'f', 1);
+}
+
QVariant CylindersModel::data(const QModelIndex& index, int role) const
{
QVariant ret;
@@ -68,9 +78,21 @@ QVariant CylindersModel::data(const QModelIndex& index, int role) const
cylinder_t *cyl = &current->cylinder[index.row()];
switch (role) {
- case Qt::FontRole:
- ret = defaultModelFont();
+ case Qt::FontRole: {
+ QFont font = defaultModelFont();
+ switch (index.column()) {
+ case START:
+ if (!cyl->start.mbar)
+ font.setItalic(true);
+ break;
+ case END:
+ if (!cyl->end.mbar)
+ font.setItalic(true);
+ break;
+ }
+ ret = font;
break;
+ }
case Qt::TextAlignmentRole:
ret = Qt::AlignHCenter;
break;
@@ -84,12 +106,16 @@ QVariant CylindersModel::data(const QModelIndex& index, int role) const
// we can't use get_volume_string because the idiotic imperial tank
// sizes take working pressure into account...
if (cyl->type.size.mliter) {
- if (prefs.units.volume == prefs.units.CUFT) {
- int cuft = 0.5 + ml_to_cuft(gas_volume(cyl, cyl->type.workingpressure));
- ret = QString("%1cuft").arg(cuft);
+ double volume;
+ int mbar = cyl->type.workingpressure.mbar;
+
+ if (mbar && prefs.units.volume == prefs.units.CUFT) {
+ volume = ml_to_cuft(cyl->type.size.mliter);
+ volume *= bar_to_atm(mbar / 1000.0);
} else {
- ret = QString("%1l").arg(cyl->type.size.mliter / 1000.0, 0, 'f', 1);
+ volume = cyl->type.size.mliter / 1000.0;
}
+ ret = QString("%1").arg(volume, 0, 'f', 1);
}
break;
case WORKINGPRESS:
@@ -98,17 +124,21 @@ QVariant CylindersModel::data(const QModelIndex& index, int role) const
break;
case START:
if (cyl->start.mbar)
- ret = get_pressure_string(cyl->start, TRUE);
+ ret = get_pressure_string(cyl->start, FALSE);
+ else if (cyl->sample_start.mbar)
+ ret = get_pressure_string(cyl->sample_start, FALSE);
break;
case END:
if (cyl->end.mbar)
- ret = get_pressure_string(cyl->end, TRUE );
+ ret = get_pressure_string(cyl->end, FALSE);
+ else if (cyl->sample_end.mbar)
+ ret = get_pressure_string(cyl->sample_end, FALSE);
break;
case O2:
- ret = QString("%1%").arg((cyl->gasmix.o2.permille + 5) / 10);
+ ret = percent_string(cyl->gasmix.o2);
break;
case HE:
- ret = QString("%1%").arg((cyl->gasmix.he.permille + 5) / 10);
+ ret = percent_string(cyl->gasmix.he);
break;
}
break;
@@ -164,28 +194,21 @@ bool CylindersModel::setData(const QModelIndex& index, const QVariant& value, in
if (value.toDouble() != 0.0) {
TankInfoModel *tanks = TankInfoModel::instance();
QModelIndexList matches = tanks->match(tanks->index(0,0), Qt::DisplayRole, cyl->type.description);
- if (prefs.units.volume == prefs.units.CUFT) {
- if (cyl->type.workingpressure.mbar == 0) {
- // this is a hack as we can't store a wet size
- // without working pressure in cuft mode
- // so we assume it's an aluminum tank at 3000psi
- cyl->type.workingpressure.mbar = psi_to_mbar(3000);
- if (!matches.isEmpty())
- tanks->setData(tanks->index(matches.first().row(), TankInfoModel::BAR), cyl->type.workingpressure.mbar / 1000.0);
- }
- if (cyl->type.size.mliter != wet_volume(value.toDouble(), cyl->type.workingpressure)) {
- mark_divelist_changed(TRUE);
- cyl->type.size.mliter = wet_volume(value.toDouble(), cyl->type.workingpressure);
- if (!matches.isEmpty())
- tanks->setData(tanks->index(matches.first().row(), TankInfoModel::ML), cyl->type.size.mliter);
- }
+ int mbar = cyl->type.workingpressure.mbar;
+ int mliter;
+
+ if (mbar && prefs.units.volume == prefs.units.CUFT) {
+ double liters = cuft_to_l(value.toDouble());
+ liters /= bar_to_atm(mbar / 1000.0);
+ mliter = rint(liters * 1000);
} else {
- if (cyl->type.size.mliter != value.toDouble() * 1000.0) {
- mark_divelist_changed(TRUE);
- cyl->type.size.mliter = value.toDouble() * 1000.0;
- if (!matches.isEmpty())
- tanks->setData(tanks->index(matches.first().row(), TankInfoModel::ML), cyl->type.size.mliter);
- }
+ mliter = rint(value.toDouble() * 1000);
+ }
+ if (cyl->type.size.mliter != mliter) {
+ mark_divelist_changed(TRUE);
+ cyl->type.size.mliter = mliter;
+ if (!matches.isEmpty())
+ tanks->setData(tanks->index(matches.first().row(), TankInfoModel::ML), cyl->type.size.mliter);
}
}
}
@@ -227,14 +250,14 @@ bool CylindersModel::setData(const QModelIndex& index, const QVariant& value, in
}
break;
case O2:
- if (CHANGED(toInt, "%", "%")) {
- cyl->gasmix.o2.permille = value.toInt() * 10;
+ if (CHANGED(toDouble, "%", "%")) {
+ cyl->gasmix.o2.permille = value.toDouble() * 10 + 0.5;
mark_divelist_changed(TRUE);
}
break;
case HE:
- if (CHANGED(toInt, "%", "%")) {
- cyl->gasmix.he.permille = value.toInt() * 10;
+ if (CHANGED(toDouble, "%", "%")) {
+ cyl->gasmix.he.permille = value.toDouble() * 10 + 0.5;
mark_divelist_changed(TRUE);
}
break;
@@ -408,7 +431,7 @@ bool WeightModel::setData(const QModelIndex& index, const QVariant& value, int r
if (prefs.units.weight == prefs.units.LBS)
ws->weight.grams = lbs_to_grams(value.toDouble());
else
- ws->weight.grams = value.toDouble() * 1000.0;
+ ws->weight.grams = value.toDouble() * 1000.0 + 0.5;
// now update the ws_info
WSInfoModel *wsim = WSInfoModel::instance();
QModelIndexList matches = wsim->match(wsim->index(0,0), Qt::DisplayRole, ws->description);
@@ -678,22 +701,17 @@ QVariant TankInfoModel::data(const QModelIndex& index, int role) const
if (role == Qt::FontRole){
return defaultModelFont();
}
+ if (role == Qt::DisplayRole || role == Qt::EditRole) {
+ struct tank_info *info = &tank_info[index.row()];
+ int ml = info->ml;
+ double bar = (info->psi) ? psi_to_bar(info->psi) : info->bar;
- struct tank_info *info = &tank_info[index.row()];
-
- int ml = info->ml;
-
- int bar = ((info->psi) ? psi_to_bar(info->psi) : info->bar) * 1000 + 0.5;
+ if (info->cuft && info->psi)
+ ml = cuft_to_l(info->cuft) * 1000 / bar_to_atm(bar);
- if (info->cuft && info->psi) {
- pressure_t p;
- p.mbar = psi_to_mbar(info->psi);
- ml = wet_volume(info->cuft, p);
- }
- if (role == Qt::DisplayRole || role == Qt::EditRole) {
switch(index.column()) {
case BAR:
- ret = bar;
+ ret = bar * 1000;
break;
case ML:
ret = ml;