summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2013-06-19 16:33:49 -1000
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-06-19 21:40:38 -0700
commit45d9ca09de0bae43f54b7ab0fb08d8c6406be7a2 (patch)
tree250ec5cc3892208a8b41e78a49c89acd577811af
parent02f2768148ecc6d4b547506fe841a5dc8f3bedd2 (diff)
downloadsubsurface-45d9ca09de0bae43f54b7ab0fb08d8c6406be7a2.tar.gz
Fix the imperial cylinder size calculations in equipment handling
This makes us use the same linear calculations as we did in the Gtk branch. We don't take compressibility into account, since tank manufacturers don't seem to either. A Luxfer AL80 is 11.1 liters, and with the standard (non-compressibility) calculations, 80 cuft of air at 3000 psi is 11.094 liter, so that is the right model to use. Also, stop with the horrible "units in edited numbers" stuff. It uses up precious space, and doesn't look any better. If the user asked for cuft, give him cuft without making a big deal about it. Oh, and if the working pressure doesn't exist, sizes are always in liters. That's what we did in the Gtk branch, that's what we do here. Again, no reason to even bother stating units, it's not helping. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--qt-ui/models.cpp47
1 files changed, 22 insertions, 25 deletions
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp
index 489f91bb6..4ef8bc6ca 100644
--- a/qt-ui/models.cpp
+++ b/qt-ui/models.cpp
@@ -84,12 +84,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) {
- double cuft = ml_to_cuft(gas_volume(cyl, cyl->type.workingpressure));
- ret = QString("%1cuft").arg(cuft, 0, 'f', 1);
+ 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:
@@ -164,28 +168,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);
}
}
}