summaryrefslogtreecommitdiffstats
path: root/qt-models
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2017-01-11 09:22:41 -0800
committerGravatar Subsurface <dirk@subsurface-divelog.org>2017-01-12 14:17:09 -0800
commit638e7fb28fa48adfb4d9ecba132bbc26990b4056 (patch)
tree9370057b47fa67b8d8fa1625e1289546f0b07f1f /qt-models
parent6637aee114f765d6e92d2258badbfa1cf93d6885 (diff)
downloadsubsurface-638e7fb28fa48adfb4d9ecba132bbc26990b4056.tar.gz
Add cylinder equipment tooltips with gas volume
This adds tooltips for the equipment tab for each cylinder, showing the amount of gas used. When you mouse over the size and working pressure fields, the tooltip will show the amount of gas used (along with start and end gas volumes). And when you mouse over the start and end pressures, it will show the start and end gas volumes, and the Z factor used. I started doing this because of the gas volume questions in the last day or two (and a few from a few weeks ago). When even Robert Helling starts wondering about the effects of compressibility on the SAC calculation, our numbers are clearly too opaque. With these tooltips, at least you can see what went into the used gas calculations, instead of having to add debugging options to print out Z factors. [ This patch also adds a "rint()" to get the rounding right in the gas_volume() function. Although rounding to the nearst milliliter really doesn't matter, it's the right thing to do after doing FP calculations ;^] Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'qt-models')
-rw-r--r--qt-models/cylindermodel.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/qt-models/cylindermodel.cpp b/qt-models/cylindermodel.cpp
index 4a9b03864..c2c94f765 100644
--- a/qt-models/cylindermodel.cpp
+++ b/qt-models/cylindermodel.cpp
@@ -51,6 +51,58 @@ static QString get_cylinder_string(cylinder_t *cyl)
return QString("%1").arg(value, 0, 'f', decimals) + unit;
}
+static QString gas_volume_string(int ml, const char *tail)
+{
+ double vol;
+ const char *unit;
+ int decimals;
+
+ vol = get_volume_units(ml, NULL, &unit);
+ decimals = (vol > 20.0) ? 0 : (vol > 2.0) ? 1 : 2;
+
+ return QString("%1 %2 %3").arg(vol, 0, 'f', decimals).arg(unit).arg(tail);
+}
+
+static QVariant gas_usage_tooltip(cylinder_t *cyl)
+{
+ pressure_t startp = cyl->start.mbar ? cyl->start : cyl->sample_start;
+ pressure_t endp = cyl->end.mbar ? cyl->end : cyl->sample_end;
+
+ int start, end, used;
+
+ start = gas_volume(cyl, startp);
+ end = gas_volume(cyl, endp);
+ used = (end && start > end) ? start - end : 0;
+
+ if (!used)
+ return QVariant();
+
+ return gas_volume_string(used, "(") +
+ gas_volume_string(start, " -> ") +
+ gas_volume_string(end, ")");
+}
+
+static QVariant gas_volume_tooltip(cylinder_t *cyl, pressure_t p)
+{
+ int vol = gas_volume(cyl, p);
+ double Z;
+
+ if (!vol)
+ return QVariant();
+
+ Z = gas_compressibility_factor(&cyl->gasmix, p.mbar / 1000.0);
+ return gas_volume_string(vol, "(Z=") + QString("%1)").arg(Z, 0, 'f', 3);
+}
+
+static QVariant gas_start_tooltip(cylinder_t *cyl)
+{
+ return gas_volume_tooltip(cyl, cyl->start.mbar ? cyl->start : cyl->sample_start);
+}
+
+static QVariant gas_end_tooltip(cylinder_t *cyl)
+{
+ return gas_volume_tooltip(cyl, cyl->end.mbar ? cyl->end : cyl->sample_end);
+}
static QVariant percent_string(fraction_t fraction)
{
@@ -176,6 +228,13 @@ QVariant CylindersModel::data(const QModelIndex &index, int role) const
case REMOVE:
ret = tr("Clicking here will remove this cylinder.");
break;
+ case SIZE:
+ case WORKINGPRESS:
+ return gas_usage_tooltip(cyl);
+ case START:
+ return gas_start_tooltip(cyl);
+ case END:
+ return gas_end_tooltip(cyl);
case DEPTH:
ret = tr("Switch depth for deco gas. Calculated using Deco pO₂ preference, unless set manually.");
break;