2017-04-27 18:25:32 +00:00
|
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2015-05-28 19:23:49 +00:00
|
|
|
|
#include "cylindermodel.h"
|
2015-05-28 19:39:15 +00:00
|
|
|
|
#include "tankinfomodel.h"
|
2015-05-28 19:23:49 +00:00
|
|
|
|
#include "models.h"
|
2016-04-05 05:02:03 +00:00
|
|
|
|
#include "core/helpers.h"
|
|
|
|
|
#include "core/color.h"
|
|
|
|
|
#include "qt-models/diveplannermodel.h"
|
|
|
|
|
#include "core/gettextfromc.h"
|
2015-05-28 19:23:49 +00:00
|
|
|
|
|
2016-03-07 06:43:20 +00:00
|
|
|
|
CylindersModel::CylindersModel(QObject *parent) :
|
|
|
|
|
CleanerTableModel(parent),
|
|
|
|
|
changed(false),
|
2015-05-28 19:23:49 +00:00
|
|
|
|
rows(0)
|
|
|
|
|
{
|
2016-07-06 12:40:32 +00:00
|
|
|
|
// enum {REMOVE, TYPE, SIZE, WORKINGPRESS, START, END, O2, HE, DEPTH, MOD, MND, USE};
|
2015-05-28 19:23:49 +00:00
|
|
|
|
setHeaderDataStrings(QStringList() << "" << tr("Type") << tr("Size") << tr("Work press.") << tr("Start press.") << tr("End press.") << tr("O₂%") << tr("He%")
|
2016-07-19 09:01:06 +00:00
|
|
|
|
<< tr("Deco switch at") <<tr("Bot. MOD") <<tr("MND") << tr("Use"));
|
2015-05-28 19:23:49 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-26 12:34:17 +00:00
|
|
|
|
QVariant CylindersModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
|
|
|
{
|
2017-03-11 06:42:20 +00:00
|
|
|
|
if (role == Qt::DisplayRole && orientation == Qt::Horizontal && in_planner() && section == WORKINGPRESS)
|
2017-02-26 12:34:17 +00:00
|
|
|
|
return tr("Start press.");
|
|
|
|
|
else
|
|
|
|
|
return CleanerTableModel::headerData(section, orientation, role);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-05-28 19:23:49 +00:00
|
|
|
|
CylindersModel *CylindersModel::instance()
|
|
|
|
|
{
|
|
|
|
|
|
2017-12-20 19:00:26 +00:00
|
|
|
|
static CylindersModel self;
|
|
|
|
|
return &self;
|
2015-05-28 19:23:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
Don't use "get_volume_string()" for cylinder size string
We had two totally different usage cases for "get_volume_string()": one
that did the obvious "show this volume as a string", and one that tried
to show a cylinder size.
The function used a magic third argument (the working pressure of the
cylinder) to distinguish between the two cases, but it still got it
wrong.
A metric cylinder doesn't necessarily have a working pressure at all,
and the size is a wet size in liters. We'd pass in zero as the working
pressure, and if the volume units were set to cubic feet, the logic in
"get_volume_string()" would happily convert the metric wet size into the
wet size in cubic feet.
But that's completely wrong. An imperial cylinder size simply isn't a
wet size. If you don't have a working pressure, you cannot convert the
cylinder size to cubic feet. End of story.
So instead of having "get_volume_string()" have magical behavior
depending on working pressure, and getting it wrong anyway, just make
get_volume_string do a pure volume conversion, and create a whole new
function for showing the size of a cylinder.
Now, if the cylinder doesn't have a working pressure, we just show the
metric size, even if the user had asked for cubic feet.
[Dirk Hohndel: added call to translation functions for the units]
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-24 22:42:56 +00:00
|
|
|
|
static QString get_cylinder_string(cylinder_t *cyl)
|
|
|
|
|
{
|
|
|
|
|
QString unit;
|
|
|
|
|
int decimals;
|
|
|
|
|
unsigned int ml = cyl->type.size.mliter;
|
|
|
|
|
pressure_t wp = cyl->type.workingpressure;
|
|
|
|
|
double value;
|
|
|
|
|
|
|
|
|
|
// We cannot use "get_volume_units()", because even when
|
|
|
|
|
// using imperial units we may need to show the size in
|
|
|
|
|
// liters: if we don't have a working pressure, we cannot
|
|
|
|
|
// convert the cylinder size to cuft.
|
|
|
|
|
if (wp.mbar && prefs.units.volume == units::CUFT) {
|
|
|
|
|
value = ml_to_cuft(ml) * bar_to_atm(wp.mbar / 1000.0);
|
|
|
|
|
decimals = (value > 20.0) ? 0 : (value > 2.0) ? 1 : 2;
|
2017-01-16 11:30:57 +00:00
|
|
|
|
unit = CylindersModel::tr("cuft");
|
Don't use "get_volume_string()" for cylinder size string
We had two totally different usage cases for "get_volume_string()": one
that did the obvious "show this volume as a string", and one that tried
to show a cylinder size.
The function used a magic third argument (the working pressure of the
cylinder) to distinguish between the two cases, but it still got it
wrong.
A metric cylinder doesn't necessarily have a working pressure at all,
and the size is a wet size in liters. We'd pass in zero as the working
pressure, and if the volume units were set to cubic feet, the logic in
"get_volume_string()" would happily convert the metric wet size into the
wet size in cubic feet.
But that's completely wrong. An imperial cylinder size simply isn't a
wet size. If you don't have a working pressure, you cannot convert the
cylinder size to cubic feet. End of story.
So instead of having "get_volume_string()" have magical behavior
depending on working pressure, and getting it wrong anyway, just make
get_volume_string do a pure volume conversion, and create a whole new
function for showing the size of a cylinder.
Now, if the cylinder doesn't have a working pressure, we just show the
metric size, even if the user had asked for cubic feet.
[Dirk Hohndel: added call to translation functions for the units]
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-24 22:42:56 +00:00
|
|
|
|
} else {
|
|
|
|
|
value = ml / 1000.0;
|
|
|
|
|
decimals = 1;
|
|
|
|
|
unit = CylindersModel::tr("ℓ");
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-19 20:55:18 +00:00
|
|
|
|
return QString("%L1").arg(value, 0, 'f', decimals) + unit;
|
Don't use "get_volume_string()" for cylinder size string
We had two totally different usage cases for "get_volume_string()": one
that did the obvious "show this volume as a string", and one that tried
to show a cylinder size.
The function used a magic third argument (the working pressure of the
cylinder) to distinguish between the two cases, but it still got it
wrong.
A metric cylinder doesn't necessarily have a working pressure at all,
and the size is a wet size in liters. We'd pass in zero as the working
pressure, and if the volume units were set to cubic feet, the logic in
"get_volume_string()" would happily convert the metric wet size into the
wet size in cubic feet.
But that's completely wrong. An imperial cylinder size simply isn't a
wet size. If you don't have a working pressure, you cannot convert the
cylinder size to cubic feet. End of story.
So instead of having "get_volume_string()" have magical behavior
depending on working pressure, and getting it wrong anyway, just make
get_volume_string do a pure volume conversion, and create a whole new
function for showing the size of a cylinder.
Now, if the cylinder doesn't have a working pressure, we just show the
metric size, even if the user had asked for cubic feet.
[Dirk Hohndel: added call to translation functions for the units]
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-24 22:42:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-11 17:22:41 +00:00
|
|
|
|
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;
|
|
|
|
|
|
2018-02-19 20:55:18 +00:00
|
|
|
|
return QString("%L1 %2 %3").arg(vol, 0, 'f', decimals).arg(unit).arg(tail);
|
2017-01-11 17:22:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
Tweak cylinder equipment tooltips
While playing around with the current subsurface, I realized that while we
give the gas volume and Z factor for the beginning/end pressures in the
newly added tooltips, there is no way to actually see that same
information for the working pressure.
So if you have filled in cylinder type information, but don't have any
actual gas usage information, there will be no cylinder tooltips at all.
But you might still want to know what the actual volume for a particular
cylinder is, and what the Z value for that working pressure is.
So this tweaks the tool-tips a bit.
When mousing over the pressure fields (ie "working pressure", "start" and
"end"), it now always gives the cylinder gas volume and Z factor for that
pressure, so for example on an AL72 that has a working pressure of 3000
psi and that contains air the tooltip will say:
69 cuft, Z=1.040
when you mouse over the working pressure field (that's obviously with
imperial units, in metric you'll see liters of gas).
When mousing over the type/size field, it gives the used gas amounts, ie
something like this:
37 cuft (82 cuft -> 45 cuft)
but if the cylinder doesn't have starting/ending pressures (and thus no
used gas information), this patch will make subsurface show the working
pressure data instead, so that you at least get something.
This all seems more useful than what my first version gave.
NOTE! This makes commit adaeb506b7a1 ("Show both the nominal and "real"
size for an imperial cylinder") kind of pointless. You now see the real
size in the tooltip when you mouse over the size, and now it actually
works both for imperial and metric people, so the tooltip is in many ways
the better model.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-01-16 00:07:35 +00:00
|
|
|
|
static QVariant gas_wp_tooltip(cylinder_t *cyl);
|
|
|
|
|
|
2017-01-11 17:22:41 +00:00
|
|
|
|
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)
|
Tweak cylinder equipment tooltips
While playing around with the current subsurface, I realized that while we
give the gas volume and Z factor for the beginning/end pressures in the
newly added tooltips, there is no way to actually see that same
information for the working pressure.
So if you have filled in cylinder type information, but don't have any
actual gas usage information, there will be no cylinder tooltips at all.
But you might still want to know what the actual volume for a particular
cylinder is, and what the Z value for that working pressure is.
So this tweaks the tool-tips a bit.
When mousing over the pressure fields (ie "working pressure", "start" and
"end"), it now always gives the cylinder gas volume and Z factor for that
pressure, so for example on an AL72 that has a working pressure of 3000
psi and that contains air the tooltip will say:
69 cuft, Z=1.040
when you mouse over the working pressure field (that's obviously with
imperial units, in metric you'll see liters of gas).
When mousing over the type/size field, it gives the used gas amounts, ie
something like this:
37 cuft (82 cuft -> 45 cuft)
but if the cylinder doesn't have starting/ending pressures (and thus no
used gas information), this patch will make subsurface show the working
pressure data instead, so that you at least get something.
This all seems more useful than what my first version gave.
NOTE! This makes commit adaeb506b7a1 ("Show both the nominal and "real"
size for an imperial cylinder") kind of pointless. You now see the real
size in the tooltip when you mouse over the size, and now it actually
works both for imperial and metric people, so the tooltip is in many ways
the better model.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-01-16 00:07:35 +00:00
|
|
|
|
return gas_wp_tooltip(cyl);
|
2017-01-11 17:22:41 +00:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
Tweak cylinder equipment tooltips
While playing around with the current subsurface, I realized that while we
give the gas volume and Z factor for the beginning/end pressures in the
newly added tooltips, there is no way to actually see that same
information for the working pressure.
So if you have filled in cylinder type information, but don't have any
actual gas usage information, there will be no cylinder tooltips at all.
But you might still want to know what the actual volume for a particular
cylinder is, and what the Z value for that working pressure is.
So this tweaks the tool-tips a bit.
When mousing over the pressure fields (ie "working pressure", "start" and
"end"), it now always gives the cylinder gas volume and Z factor for that
pressure, so for example on an AL72 that has a working pressure of 3000
psi and that contains air the tooltip will say:
69 cuft, Z=1.040
when you mouse over the working pressure field (that's obviously with
imperial units, in metric you'll see liters of gas).
When mousing over the type/size field, it gives the used gas amounts, ie
something like this:
37 cuft (82 cuft -> 45 cuft)
but if the cylinder doesn't have starting/ending pressures (and thus no
used gas information), this patch will make subsurface show the working
pressure data instead, so that you at least get something.
This all seems more useful than what my first version gave.
NOTE! This makes commit adaeb506b7a1 ("Show both the nominal and "real"
size for an imperial cylinder") kind of pointless. You now see the real
size in the tooltip when you mouse over the size, and now it actually
works both for imperial and metric people, so the tooltip is in many ways
the better model.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-01-16 00:07:35 +00:00
|
|
|
|
static QVariant gas_wp_tooltip(cylinder_t *cyl)
|
|
|
|
|
{
|
|
|
|
|
return gas_volume_tooltip(cyl, cyl->type.workingpressure);
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-11 17:22:41 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
Don't use "get_volume_string()" for cylinder size string
We had two totally different usage cases for "get_volume_string()": one
that did the obvious "show this volume as a string", and one that tried
to show a cylinder size.
The function used a magic third argument (the working pressure of the
cylinder) to distinguish between the two cases, but it still got it
wrong.
A metric cylinder doesn't necessarily have a working pressure at all,
and the size is a wet size in liters. We'd pass in zero as the working
pressure, and if the volume units were set to cubic feet, the logic in
"get_volume_string()" would happily convert the metric wet size into the
wet size in cubic feet.
But that's completely wrong. An imperial cylinder size simply isn't a
wet size. If you don't have a working pressure, you cannot convert the
cylinder size to cubic feet. End of story.
So instead of having "get_volume_string()" have magical behavior
depending on working pressure, and getting it wrong anyway, just make
get_volume_string do a pure volume conversion, and create a whole new
function for showing the size of a cylinder.
Now, if the cylinder doesn't have a working pressure, we just show the
metric size, even if the user had asked for cubic feet.
[Dirk Hohndel: added call to translation functions for the units]
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-24 22:42:56 +00:00
|
|
|
|
|
2015-05-28 19:23:49 +00:00
|
|
|
|
static QVariant percent_string(fraction_t fraction)
|
|
|
|
|
{
|
|
|
|
|
int permille = fraction.permille;
|
|
|
|
|
|
|
|
|
|
if (!permille)
|
|
|
|
|
return QVariant();
|
2018-02-19 20:55:18 +00:00
|
|
|
|
return QString("%L1%").arg(permille / 10.0, 0, 'f', 1);
|
2015-05-28 19:23:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant CylindersModel::data(const QModelIndex &index, int role) const
|
|
|
|
|
{
|
|
|
|
|
QVariant ret;
|
|
|
|
|
|
|
|
|
|
if (!index.isValid() || index.row() >= MAX_CYLINDERS)
|
|
|
|
|
return ret;
|
2017-10-20 21:25:18 +00:00
|
|
|
|
|
2015-05-28 19:23:49 +00:00
|
|
|
|
cylinder_t *cyl = &displayed_dive.cylinder[index.row()];
|
2017-10-20 21:25:18 +00:00
|
|
|
|
|
2015-05-28 19:23:49 +00:00
|
|
|
|
switch (role) {
|
|
|
|
|
case Qt::BackgroundRole: {
|
|
|
|
|
switch (index.column()) {
|
|
|
|
|
// mark the cylinder start / end pressure in red if the values
|
|
|
|
|
// seem implausible
|
|
|
|
|
case START:
|
|
|
|
|
case END:
|
2017-03-20 21:10:42 +00:00
|
|
|
|
pressure_t startp, endp;
|
|
|
|
|
startp = cyl->start.mbar ? cyl->start : cyl->sample_start;
|
|
|
|
|
endp = cyl->end.mbar ? cyl->end : cyl->sample_end;
|
|
|
|
|
if ((startp.mbar && !endp.mbar) ||
|
|
|
|
|
(endp.mbar && startp.mbar <= endp.mbar))
|
2015-05-28 19:23:49 +00:00
|
|
|
|
ret = REDORANGE1_HIGH_TRANS;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case Qt::FontRole: {
|
|
|
|
|
QFont font = defaultModelFont();
|
|
|
|
|
switch (index.column()) {
|
2017-03-20 21:10:42 +00:00
|
|
|
|
// if we don't have manually set pressure data use italic font
|
2015-05-28 19:23:49 +00:00
|
|
|
|
case START:
|
|
|
|
|
font.setItalic(!cyl->start.mbar);
|
|
|
|
|
break;
|
|
|
|
|
case END:
|
2017-03-20 21:10:42 +00:00
|
|
|
|
font.setItalic(!cyl->end.mbar);
|
2015-05-28 19:23:49 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
ret = font;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case Qt::TextAlignmentRole:
|
|
|
|
|
ret = Qt::AlignCenter;
|
|
|
|
|
break;
|
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
|
case Qt::EditRole:
|
|
|
|
|
switch (index.column()) {
|
|
|
|
|
case TYPE:
|
|
|
|
|
ret = QString(cyl->type.description);
|
|
|
|
|
break;
|
|
|
|
|
case SIZE:
|
|
|
|
|
if (cyl->type.size.mliter)
|
Don't use "get_volume_string()" for cylinder size string
We had two totally different usage cases for "get_volume_string()": one
that did the obvious "show this volume as a string", and one that tried
to show a cylinder size.
The function used a magic third argument (the working pressure of the
cylinder) to distinguish between the two cases, but it still got it
wrong.
A metric cylinder doesn't necessarily have a working pressure at all,
and the size is a wet size in liters. We'd pass in zero as the working
pressure, and if the volume units were set to cubic feet, the logic in
"get_volume_string()" would happily convert the metric wet size into the
wet size in cubic feet.
But that's completely wrong. An imperial cylinder size simply isn't a
wet size. If you don't have a working pressure, you cannot convert the
cylinder size to cubic feet. End of story.
So instead of having "get_volume_string()" have magical behavior
depending on working pressure, and getting it wrong anyway, just make
get_volume_string do a pure volume conversion, and create a whole new
function for showing the size of a cylinder.
Now, if the cylinder doesn't have a working pressure, we just show the
metric size, even if the user had asked for cubic feet.
[Dirk Hohndel: added call to translation functions for the units]
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-24 22:42:56 +00:00
|
|
|
|
ret = get_cylinder_string(cyl);
|
2015-05-28 19:23:49 +00:00
|
|
|
|
break;
|
|
|
|
|
case WORKINGPRESS:
|
|
|
|
|
if (cyl->type.workingpressure.mbar)
|
|
|
|
|
ret = get_pressure_string(cyl->type.workingpressure, true);
|
|
|
|
|
break;
|
|
|
|
|
case START:
|
|
|
|
|
if (cyl->start.mbar)
|
|
|
|
|
ret = get_pressure_string(cyl->start, true);
|
|
|
|
|
else if (cyl->sample_start.mbar)
|
|
|
|
|
ret = get_pressure_string(cyl->sample_start, true);
|
|
|
|
|
break;
|
|
|
|
|
case END:
|
|
|
|
|
if (cyl->end.mbar)
|
|
|
|
|
ret = get_pressure_string(cyl->end, true);
|
|
|
|
|
else if (cyl->sample_end.mbar)
|
|
|
|
|
ret = get_pressure_string(cyl->sample_end, true);
|
|
|
|
|
break;
|
|
|
|
|
case O2:
|
|
|
|
|
ret = percent_string(cyl->gasmix.o2);
|
|
|
|
|
break;
|
|
|
|
|
case HE:
|
|
|
|
|
ret = percent_string(cyl->gasmix.he);
|
|
|
|
|
break;
|
|
|
|
|
case DEPTH:
|
|
|
|
|
ret = get_depth_string(cyl->depth, true);
|
|
|
|
|
break;
|
2016-07-06 12:40:32 +00:00
|
|
|
|
case MOD:
|
2016-07-06 12:40:35 +00:00
|
|
|
|
if (cyl->bestmix_o2) {
|
|
|
|
|
ret = QString("*");
|
|
|
|
|
} else {
|
|
|
|
|
pressure_t modpO2;
|
|
|
|
|
modpO2.mbar = prefs.bottompo2;
|
2017-03-11 09:37:43 +00:00
|
|
|
|
ret = get_depth_string(gas_mod(&cyl->gasmix, modpO2, &displayed_dive, M_OR_FT(1,1)), true);
|
2016-07-06 12:40:35 +00:00
|
|
|
|
}
|
2016-07-06 12:40:32 +00:00
|
|
|
|
break;
|
|
|
|
|
case MND:
|
2016-07-06 12:40:35 +00:00
|
|
|
|
if (cyl->bestmix_he)
|
|
|
|
|
ret = QString("*");
|
|
|
|
|
else
|
2017-03-11 09:37:43 +00:00
|
|
|
|
ret = get_depth_string(gas_mnd(&cyl->gasmix, prefs.bestmixend, &displayed_dive, M_OR_FT(1,1)), true);
|
2016-07-06 12:40:32 +00:00
|
|
|
|
break;
|
2015-05-28 19:23:49 +00:00
|
|
|
|
case USE:
|
|
|
|
|
ret = gettextFromC::instance()->trGettext(cylinderuse_text[cyl->cylinder_use]);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case Qt::DecorationRole:
|
|
|
|
|
case Qt::SizeHintRole:
|
2015-10-21 22:17:05 +00:00
|
|
|
|
if (index.column() == REMOVE) {
|
2017-10-20 11:30:04 +00:00
|
|
|
|
if ((in_planner() && DivePlannerPointsModel::instance()->tankInUse(index.row())) ||
|
2017-11-29 09:16:00 +00:00
|
|
|
|
(!in_planner() && is_cylinder_prot(&displayed_dive, index.row()))) {
|
2017-03-11 09:39:48 +00:00
|
|
|
|
ret = trashForbiddenIcon();
|
|
|
|
|
}
|
|
|
|
|
else ret = trashIcon();
|
2015-10-21 22:17:05 +00:00
|
|
|
|
}
|
2015-05-28 19:23:49 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Qt::ToolTipRole:
|
2016-08-02 01:02:14 +00:00
|
|
|
|
switch (index.column()) {
|
|
|
|
|
case REMOVE:
|
2017-10-20 11:30:04 +00:00
|
|
|
|
if ((in_planner() && DivePlannerPointsModel::instance()->tankInUse(index.row())) ||
|
2017-11-29 09:16:00 +00:00
|
|
|
|
(!in_planner() && is_cylinder_prot(&displayed_dive, index.row()))) {
|
2017-03-11 09:39:48 +00:00
|
|
|
|
ret = tr("This gas is in use. Only cylinders that are not used in the dive can be removed.");
|
|
|
|
|
}
|
|
|
|
|
else ret = tr("Clicking here will remove this cylinder.");
|
2016-08-02 01:02:14 +00:00
|
|
|
|
break;
|
Tweak cylinder equipment tooltips
While playing around with the current subsurface, I realized that while we
give the gas volume and Z factor for the beginning/end pressures in the
newly added tooltips, there is no way to actually see that same
information for the working pressure.
So if you have filled in cylinder type information, but don't have any
actual gas usage information, there will be no cylinder tooltips at all.
But you might still want to know what the actual volume for a particular
cylinder is, and what the Z value for that working pressure is.
So this tweaks the tool-tips a bit.
When mousing over the pressure fields (ie "working pressure", "start" and
"end"), it now always gives the cylinder gas volume and Z factor for that
pressure, so for example on an AL72 that has a working pressure of 3000
psi and that contains air the tooltip will say:
69 cuft, Z=1.040
when you mouse over the working pressure field (that's obviously with
imperial units, in metric you'll see liters of gas).
When mousing over the type/size field, it gives the used gas amounts, ie
something like this:
37 cuft (82 cuft -> 45 cuft)
but if the cylinder doesn't have starting/ending pressures (and thus no
used gas information), this patch will make subsurface show the working
pressure data instead, so that you at least get something.
This all seems more useful than what my first version gave.
NOTE! This makes commit adaeb506b7a1 ("Show both the nominal and "real"
size for an imperial cylinder") kind of pointless. You now see the real
size in the tooltip when you mouse over the size, and now it actually
works both for imperial and metric people, so the tooltip is in many ways
the better model.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-01-16 00:07:35 +00:00
|
|
|
|
case TYPE:
|
2017-01-11 17:22:41 +00:00
|
|
|
|
case SIZE:
|
|
|
|
|
return gas_usage_tooltip(cyl);
|
Tweak cylinder equipment tooltips
While playing around with the current subsurface, I realized that while we
give the gas volume and Z factor for the beginning/end pressures in the
newly added tooltips, there is no way to actually see that same
information for the working pressure.
So if you have filled in cylinder type information, but don't have any
actual gas usage information, there will be no cylinder tooltips at all.
But you might still want to know what the actual volume for a particular
cylinder is, and what the Z value for that working pressure is.
So this tweaks the tool-tips a bit.
When mousing over the pressure fields (ie "working pressure", "start" and
"end"), it now always gives the cylinder gas volume and Z factor for that
pressure, so for example on an AL72 that has a working pressure of 3000
psi and that contains air the tooltip will say:
69 cuft, Z=1.040
when you mouse over the working pressure field (that's obviously with
imperial units, in metric you'll see liters of gas).
When mousing over the type/size field, it gives the used gas amounts, ie
something like this:
37 cuft (82 cuft -> 45 cuft)
but if the cylinder doesn't have starting/ending pressures (and thus no
used gas information), this patch will make subsurface show the working
pressure data instead, so that you at least get something.
This all seems more useful than what my first version gave.
NOTE! This makes commit adaeb506b7a1 ("Show both the nominal and "real"
size for an imperial cylinder") kind of pointless. You now see the real
size in the tooltip when you mouse over the size, and now it actually
works both for imperial and metric people, so the tooltip is in many ways
the better model.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-01-16 00:07:35 +00:00
|
|
|
|
case WORKINGPRESS:
|
|
|
|
|
return gas_wp_tooltip(cyl);
|
2017-01-11 17:22:41 +00:00
|
|
|
|
case START:
|
|
|
|
|
return gas_start_tooltip(cyl);
|
|
|
|
|
case END:
|
|
|
|
|
return gas_end_tooltip(cyl);
|
2016-08-02 01:02:14 +00:00
|
|
|
|
case DEPTH:
|
|
|
|
|
ret = tr("Switch depth for deco gas. Calculated using Deco pO₂ preference, unless set manually.");
|
|
|
|
|
break;
|
|
|
|
|
case MOD:
|
2017-03-06 12:27:39 +00:00
|
|
|
|
ret = tr("Calculated using Bottom pO₂ preference. Setting MOD adjusts O₂%, set to '*' for best O₂% for max. depth.");
|
2016-08-02 01:02:14 +00:00
|
|
|
|
break;
|
|
|
|
|
case MND:
|
2017-03-06 12:27:39 +00:00
|
|
|
|
ret = tr("Calculated using Best Mix END preference. Setting MND adjusts He%, set to '*' for best He% for max. depth.");
|
2016-08-02 01:02:14 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2015-05-28 19:23:49 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cylinder_t *CylindersModel::cylinderAt(const QModelIndex &index)
|
|
|
|
|
{
|
|
|
|
|
return &displayed_dive.cylinder[index.row()];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// this is our magic 'pass data in' function that allows the delegate to get
|
|
|
|
|
// the data here without silly unit conversions;
|
|
|
|
|
// so we only implement the two columns we care about
|
|
|
|
|
void CylindersModel::passInData(const QModelIndex &index, const QVariant &value)
|
|
|
|
|
{
|
|
|
|
|
cylinder_t *cyl = cylinderAt(index);
|
|
|
|
|
switch (index.column()) {
|
|
|
|
|
case SIZE:
|
|
|
|
|
if (cyl->type.size.mliter != value.toInt()) {
|
|
|
|
|
cyl->type.size.mliter = value.toInt();
|
|
|
|
|
dataChanged(index, index);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case WORKINGPRESS:
|
|
|
|
|
if (cyl->type.workingpressure.mbar != value.toInt()) {
|
|
|
|
|
cyl->type.workingpressure.mbar = value.toInt();
|
|
|
|
|
dataChanged(index, index);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CylindersModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
|
|
|
|
{
|
|
|
|
|
QString vString;
|
|
|
|
|
|
|
|
|
|
cylinder_t *cyl = cylinderAt(index);
|
|
|
|
|
switch (index.column()) {
|
|
|
|
|
case TYPE:
|
|
|
|
|
if (!value.isNull()) {
|
|
|
|
|
QByteArray ba = value.toByteArray();
|
|
|
|
|
const char *text = ba.constData();
|
|
|
|
|
if (!cyl->type.description || strcmp(cyl->type.description, text)) {
|
|
|
|
|
cyl->type.description = strdup(text);
|
|
|
|
|
changed = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case SIZE:
|
|
|
|
|
if (CHANGED()) {
|
|
|
|
|
TankInfoModel *tanks = TankInfoModel::instance();
|
|
|
|
|
QModelIndexList matches = tanks->match(tanks->index(0, 0), Qt::DisplayRole, cyl->type.description);
|
|
|
|
|
|
2018-02-25 12:51:41 +00:00
|
|
|
|
cyl->type.size = string_to_volume(qPrintable(vString), cyl->type.workingpressure);
|
2015-05-28 19:23:49 +00:00
|
|
|
|
mark_divelist_changed(true);
|
|
|
|
|
if (!matches.isEmpty())
|
|
|
|
|
tanks->setData(tanks->index(matches.first().row(), TankInfoModel::ML), cyl->type.size.mliter);
|
|
|
|
|
changed = true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case WORKINGPRESS:
|
|
|
|
|
if (CHANGED()) {
|
|
|
|
|
TankInfoModel *tanks = TankInfoModel::instance();
|
|
|
|
|
QModelIndexList matches = tanks->match(tanks->index(0, 0), Qt::DisplayRole, cyl->type.description);
|
2018-02-25 12:51:41 +00:00
|
|
|
|
cyl->type.workingpressure = string_to_pressure(qPrintable(vString));
|
2015-05-28 19:23:49 +00:00
|
|
|
|
if (!matches.isEmpty())
|
|
|
|
|
tanks->setData(tanks->index(matches.first().row(), TankInfoModel::BAR), cyl->type.workingpressure.mbar / 1000.0);
|
|
|
|
|
changed = true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case START:
|
|
|
|
|
if (CHANGED()) {
|
2018-02-25 12:51:41 +00:00
|
|
|
|
cyl->start = string_to_pressure(qPrintable(vString));
|
2015-05-28 19:23:49 +00:00
|
|
|
|
changed = true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case END:
|
|
|
|
|
if (CHANGED()) {
|
2018-02-25 12:51:41 +00:00
|
|
|
|
//&& (!cyl->start.mbar || string_to_pressure(qPrintable(vString)).mbar <= cyl->start.mbar)) {
|
|
|
|
|
cyl->end = string_to_pressure(qPrintable(vString));
|
2015-05-28 19:23:49 +00:00
|
|
|
|
changed = true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case O2:
|
|
|
|
|
if (CHANGED()) {
|
2018-02-25 12:51:41 +00:00
|
|
|
|
cyl->gasmix.o2 = string_to_fraction(qPrintable(vString));
|
2016-05-22 01:00:22 +00:00
|
|
|
|
// fO2 + fHe must not be greater than 1
|
2016-07-06 12:40:35 +00:00
|
|
|
|
if (get_o2(&cyl->gasmix) + get_he(&cyl->gasmix) > 1000)
|
|
|
|
|
cyl->gasmix.he.permille = 1000 - get_o2(&cyl->gasmix);
|
2015-05-28 19:23:49 +00:00
|
|
|
|
pressure_t modpO2;
|
|
|
|
|
if (displayed_dive.dc.divemode == PSCR)
|
|
|
|
|
modpO2.mbar = prefs.decopo2 + (1000 - get_o2(&cyl->gasmix)) * SURFACE_PRESSURE *
|
|
|
|
|
prefs.o2consumption / prefs.decosac / prefs.pscr_ratio;
|
|
|
|
|
else
|
|
|
|
|
modpO2.mbar = prefs.decopo2;
|
2015-07-05 22:07:39 +00:00
|
|
|
|
cyl->depth = gas_mod(&cyl->gasmix, modpO2, &displayed_dive, M_OR_FT(3, 10));
|
2016-07-06 12:40:35 +00:00
|
|
|
|
cyl->bestmix_o2 = false;
|
2015-05-28 19:23:49 +00:00
|
|
|
|
changed = true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case HE:
|
|
|
|
|
if (CHANGED()) {
|
2018-02-25 12:51:41 +00:00
|
|
|
|
cyl->gasmix.he = string_to_fraction(qPrintable(vString));
|
2016-05-22 01:00:22 +00:00
|
|
|
|
// fO2 + fHe must not be greater than 1
|
2016-07-06 12:40:35 +00:00
|
|
|
|
if (get_o2(&cyl->gasmix) + get_he(&cyl->gasmix) > 1000)
|
|
|
|
|
cyl->gasmix.o2.permille = 1000 - get_he(&cyl->gasmix);
|
|
|
|
|
cyl->bestmix_he = false;
|
2015-05-28 19:23:49 +00:00
|
|
|
|
changed = true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case DEPTH:
|
|
|
|
|
if (CHANGED()) {
|
2018-02-25 12:51:41 +00:00
|
|
|
|
cyl->depth = string_to_depth(qPrintable(vString));
|
2015-05-28 19:23:49 +00:00
|
|
|
|
changed = true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2016-07-06 12:40:32 +00:00
|
|
|
|
case MOD:
|
|
|
|
|
if (CHANGED()) {
|
2018-02-25 12:51:41 +00:00
|
|
|
|
if (QString::compare(qPrintable(vString), "*") == 0) {
|
2016-07-06 12:40:35 +00:00
|
|
|
|
cyl->bestmix_o2 = true;
|
2017-03-06 12:27:39 +00:00
|
|
|
|
// Calculate fO2 for max. depth
|
2016-07-06 12:40:35 +00:00
|
|
|
|
cyl->gasmix.o2 = best_o2(displayed_dive.maxdepth, &displayed_dive);
|
|
|
|
|
} else {
|
|
|
|
|
cyl->bestmix_o2 = false;
|
|
|
|
|
// Calculate fO2 for input depth
|
2018-02-25 12:51:41 +00:00
|
|
|
|
cyl->gasmix.o2 = best_o2(string_to_depth(qPrintable(vString)), &displayed_dive);
|
2016-07-06 12:40:35 +00:00
|
|
|
|
}
|
|
|
|
|
pressure_t modpO2;
|
|
|
|
|
modpO2.mbar = prefs.decopo2;
|
|
|
|
|
cyl->depth = gas_mod(&cyl->gasmix, modpO2, &displayed_dive, M_OR_FT(3, 10));
|
2016-07-06 12:40:32 +00:00
|
|
|
|
changed = true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case MND:
|
|
|
|
|
if (CHANGED()) {
|
2018-02-25 12:51:41 +00:00
|
|
|
|
if (QString::compare(qPrintable(vString), "*") == 0) {
|
2016-07-06 12:40:35 +00:00
|
|
|
|
cyl->bestmix_he = true;
|
2017-03-06 12:27:39 +00:00
|
|
|
|
// Calculate fO2 for max. depth
|
2016-07-06 12:40:36 +00:00
|
|
|
|
cyl->gasmix.he = best_he(displayed_dive.maxdepth, &displayed_dive);
|
2016-07-06 12:40:35 +00:00
|
|
|
|
} else {
|
|
|
|
|
cyl->bestmix_he = false;
|
|
|
|
|
// Calculate fHe for input depth
|
2018-02-25 12:51:41 +00:00
|
|
|
|
cyl->gasmix.he = best_he(string_to_depth(qPrintable(vString)), &displayed_dive);
|
2016-07-06 12:40:35 +00:00
|
|
|
|
}
|
2016-07-06 12:40:32 +00:00
|
|
|
|
changed = true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2015-05-28 19:23:49 +00:00
|
|
|
|
case USE:
|
|
|
|
|
if (CHANGED()) {
|
2016-04-28 14:33:05 +00:00
|
|
|
|
int use = vString.toInt();
|
|
|
|
|
if (use > NUM_GAS_USE - 1 || use < 0)
|
|
|
|
|
use = 0;
|
|
|
|
|
cyl->cylinder_use = (enum cylinderuse)use;
|
2015-05-28 19:23:49 +00:00
|
|
|
|
changed = true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
dataChanged(index, index);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-21 15:53:42 +00:00
|
|
|
|
int CylindersModel::rowCount(const QModelIndex&) const
|
2015-05-28 19:23:49 +00:00
|
|
|
|
{
|
|
|
|
|
return rows;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CylindersModel::add()
|
|
|
|
|
{
|
|
|
|
|
if (rows >= MAX_CYLINDERS) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int row = rows;
|
|
|
|
|
fill_default_cylinder(&displayed_dive.cylinder[row]);
|
2018-01-25 10:25:47 +00:00
|
|
|
|
displayed_dive.cylinder[row].start = displayed_dive.cylinder[row].type.workingpressure;
|
2015-05-28 19:23:49 +00:00
|
|
|
|
displayed_dive.cylinder[row].manually_added = true;
|
|
|
|
|
beginInsertRows(QModelIndex(), row, row);
|
|
|
|
|
rows++;
|
|
|
|
|
changed = true;
|
|
|
|
|
endInsertRows();
|
2017-10-20 10:01:59 +00:00
|
|
|
|
emit dataChanged(createIndex(row, 0), createIndex(row, COLUMNS - 1));
|
2015-05-28 19:23:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CylindersModel::clear()
|
|
|
|
|
{
|
|
|
|
|
if (rows > 0) {
|
|
|
|
|
beginRemoveRows(QModelIndex(), 0, rows - 1);
|
|
|
|
|
endRemoveRows();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Tweak the "display_unused_tanks" preferences logic
This is really unrelated to my recent "multiple gas pressures" work, but
the test case from Gaetan Bisson showed that the logic for which
cylinders to show in the equipment tab was less than optimal.
We basically used to show only cylinders that were actively used, unless
you had the "display_unused_tanks" preference option set. That comes
from some dive computers reporting a *lot* of cylinders that the diver
really doesn't even have with him on the dive. And showing those extra
dummy cylinders gets pretty annoying after a time, which is why we
default to not showing unused tanks.
However, in Gaetan's case, he had a total of four cylinders on the dive:
the O2 and diluent bottle for the rebreather dive, and then bailout
bottles (both air and deco). And while the bailout bottles weren't
actually used, Gaetan had actually filled in all the pressure details
etc for them, and so you'd really expect them to show up. These were
*not* just some extraneous default cylinder filled in by an over-eager
dive computer.
But because the bailout wasn't used, the manual pressures at the end
were the same as at the beginning, and the "unused cylinder" logic
triggered anyway.
So tweak the logic a bit, and say that you show cylinder equipment not
only if it has been used on the dive, but also if it has any pressure
information for it.
So the o nly cylinders we don't show are the ones that really have no
interesting information at all, except for possibly the cylinder tank
type itself (which is exactly what the over-eager dive computer case
might fill in, usually in the form of a default cylinder type).
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-31 04:09:24 +00:00
|
|
|
|
static bool show_cylinder(struct dive *dive, int i)
|
|
|
|
|
{
|
|
|
|
|
cylinder_t *cyl = dive->cylinder + i;
|
|
|
|
|
|
|
|
|
|
if (is_cylinder_used(dive, i))
|
|
|
|
|
return true;
|
|
|
|
|
if (cylinder_none(cyl))
|
|
|
|
|
return false;
|
|
|
|
|
if (cyl->start.mbar || cyl->sample_start.mbar ||
|
|
|
|
|
cyl->end.mbar || cyl->sample_end.mbar)
|
|
|
|
|
return true;
|
|
|
|
|
if (cyl->manually_added)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The cylinder has some data, but none of it is very interesting,
|
|
|
|
|
* it has no pressures and no gas switches. Do we want to show it?
|
|
|
|
|
*/
|
|
|
|
|
return prefs.display_unused_tanks;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-28 19:23:49 +00:00
|
|
|
|
void CylindersModel::updateDive()
|
|
|
|
|
{
|
|
|
|
|
clear();
|
|
|
|
|
rows = 0;
|
2017-11-27 11:36:20 +00:00
|
|
|
|
#ifdef DEBUG_CYL
|
|
|
|
|
dump_cylinders(&displayed_dive, true);
|
|
|
|
|
#endif
|
2015-05-28 19:23:49 +00:00
|
|
|
|
for (int i = 0; i < MAX_CYLINDERS; i++) {
|
Tweak the "display_unused_tanks" preferences logic
This is really unrelated to my recent "multiple gas pressures" work, but
the test case from Gaetan Bisson showed that the logic for which
cylinders to show in the equipment tab was less than optimal.
We basically used to show only cylinders that were actively used, unless
you had the "display_unused_tanks" preference option set. That comes
from some dive computers reporting a *lot* of cylinders that the diver
really doesn't even have with him on the dive. And showing those extra
dummy cylinders gets pretty annoying after a time, which is why we
default to not showing unused tanks.
However, in Gaetan's case, he had a total of four cylinders on the dive:
the O2 and diluent bottle for the rebreather dive, and then bailout
bottles (both air and deco). And while the bailout bottles weren't
actually used, Gaetan had actually filled in all the pressure details
etc for them, and so you'd really expect them to show up. These were
*not* just some extraneous default cylinder filled in by an over-eager
dive computer.
But because the bailout wasn't used, the manual pressures at the end
were the same as at the beginning, and the "unused cylinder" logic
triggered anyway.
So tweak the logic a bit, and say that you show cylinder equipment not
only if it has been used on the dive, but also if it has any pressure
information for it.
So the o nly cylinders we don't show are the ones that really have no
interesting information at all, except for possibly the cylinder tank
type itself (which is exactly what the over-eager dive computer case
might fill in, usually in the form of a default cylinder type).
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-31 04:09:24 +00:00
|
|
|
|
if (show_cylinder(&displayed_dive, i))
|
2015-05-28 19:23:49 +00:00
|
|
|
|
rows = i + 1;
|
|
|
|
|
}
|
|
|
|
|
if (rows > 0) {
|
|
|
|
|
beginInsertRows(QModelIndex(), 0, rows - 1);
|
|
|
|
|
endInsertRows();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CylindersModel::copyFromDive(dive *d)
|
|
|
|
|
{
|
|
|
|
|
if (!d)
|
|
|
|
|
return;
|
|
|
|
|
rows = 0;
|
|
|
|
|
for (int i = 0; i < MAX_CYLINDERS; i++) {
|
Tweak the "display_unused_tanks" preferences logic
This is really unrelated to my recent "multiple gas pressures" work, but
the test case from Gaetan Bisson showed that the logic for which
cylinders to show in the equipment tab was less than optimal.
We basically used to show only cylinders that were actively used, unless
you had the "display_unused_tanks" preference option set. That comes
from some dive computers reporting a *lot* of cylinders that the diver
really doesn't even have with him on the dive. And showing those extra
dummy cylinders gets pretty annoying after a time, which is why we
default to not showing unused tanks.
However, in Gaetan's case, he had a total of four cylinders on the dive:
the O2 and diluent bottle for the rebreather dive, and then bailout
bottles (both air and deco). And while the bailout bottles weren't
actually used, Gaetan had actually filled in all the pressure details
etc for them, and so you'd really expect them to show up. These were
*not* just some extraneous default cylinder filled in by an over-eager
dive computer.
But because the bailout wasn't used, the manual pressures at the end
were the same as at the beginning, and the "unused cylinder" logic
triggered anyway.
So tweak the logic a bit, and say that you show cylinder equipment not
only if it has been used on the dive, but also if it has any pressure
information for it.
So the o nly cylinders we don't show are the ones that really have no
interesting information at all, except for possibly the cylinder tank
type itself (which is exactly what the over-eager dive computer case
might fill in, usually in the form of a default cylinder type).
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-31 04:09:24 +00:00
|
|
|
|
if (show_cylinder(d, i))
|
2015-05-28 19:23:49 +00:00
|
|
|
|
rows = i + 1;
|
|
|
|
|
}
|
|
|
|
|
if (rows > 0) {
|
|
|
|
|
beginInsertRows(QModelIndex(), 0, rows - 1);
|
|
|
|
|
endInsertRows();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Qt::ItemFlags CylindersModel::flags(const QModelIndex &index) const
|
|
|
|
|
{
|
2017-01-23 16:35:27 +00:00
|
|
|
|
if (index.column() == REMOVE || index.column() == USE)
|
2015-05-28 19:23:49 +00:00
|
|
|
|
return Qt::ItemIsEnabled;
|
|
|
|
|
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CylindersModel::remove(const QModelIndex &index)
|
|
|
|
|
{
|
|
|
|
|
int mapping[MAX_CYLINDERS];
|
2017-01-23 16:35:27 +00:00
|
|
|
|
|
|
|
|
|
if (index.column() == USE) {
|
|
|
|
|
cylinder_t *cyl = cylinderAt(index);
|
|
|
|
|
if (cyl->cylinder_use == OC_GAS)
|
|
|
|
|
cyl->cylinder_use = NOT_USED;
|
|
|
|
|
else if (cyl->cylinder_use == NOT_USED)
|
|
|
|
|
cyl->cylinder_use = OC_GAS;
|
|
|
|
|
changed = true;
|
|
|
|
|
dataChanged(index, index);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-05-28 19:23:49 +00:00
|
|
|
|
if (index.column() != REMOVE) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-10-08 03:14:57 +00:00
|
|
|
|
|
2017-10-20 11:30:04 +00:00
|
|
|
|
if ((in_planner() && DivePlannerPointsModel::instance()->tankInUse(index.row())) ||
|
2017-11-29 09:16:00 +00:00
|
|
|
|
(!in_planner() && is_cylinder_prot(&displayed_dive, index.row())))
|
2017-10-20 11:30:04 +00:00
|
|
|
|
return;
|
2017-03-11 09:39:48 +00:00
|
|
|
|
|
2015-05-28 19:23:49 +00:00
|
|
|
|
beginRemoveRows(QModelIndex(), index.row(), index.row()); // yah, know, ugly.
|
|
|
|
|
rows--;
|
2017-11-29 09:16:00 +00:00
|
|
|
|
|
|
|
|
|
remove_cylinder(&displayed_dive, index.row());
|
|
|
|
|
for (int i = 0; i < index.row(); i++)
|
|
|
|
|
mapping[i] = i;
|
|
|
|
|
// No mapping for removed gas, set to -1
|
|
|
|
|
mapping[index.row()] = -1;
|
|
|
|
|
for (int i = index.row() + 1; i < MAX_CYLINDERS; i++)
|
|
|
|
|
mapping[i] = i - 1;
|
|
|
|
|
|
2017-10-11 19:27:06 +00:00
|
|
|
|
cylinder_renumber(&displayed_dive, mapping);
|
2017-10-20 08:16:37 +00:00
|
|
|
|
if (in_planner())
|
|
|
|
|
DivePlannerPointsModel::instance()->cylinderRenumber(mapping);
|
2017-10-20 14:54:14 +00:00
|
|
|
|
changed = true;
|
|
|
|
|
endRemoveRows();
|
2017-10-08 03:14:57 +00:00
|
|
|
|
dataChanged(index, index);
|
2015-05-28 19:23:49 +00:00
|
|
|
|
}
|
2016-07-06 12:40:30 +00:00
|
|
|
|
|
2017-10-11 19:29:47 +00:00
|
|
|
|
void CylindersModel::moveAtFirst(int cylid)
|
|
|
|
|
{
|
|
|
|
|
int mapping[MAX_CYLINDERS];
|
|
|
|
|
cylinder_t temp_cyl;
|
|
|
|
|
|
|
|
|
|
beginMoveRows(QModelIndex(), cylid, cylid, QModelIndex(), 0);
|
|
|
|
|
memmove(&temp_cyl, &displayed_dive.cylinder[cylid], sizeof(temp_cyl));
|
|
|
|
|
for (int i = cylid - 1; i >= 0; i--) {
|
|
|
|
|
memmove(&displayed_dive.cylinder[i + 1], &displayed_dive.cylinder[i], sizeof(temp_cyl));
|
|
|
|
|
mapping[i] = i + 1;
|
|
|
|
|
}
|
|
|
|
|
memmove(&displayed_dive.cylinder[0], &temp_cyl, sizeof(temp_cyl));
|
|
|
|
|
mapping[cylid] = 0;
|
|
|
|
|
for (int i = cylid + 1; i < MAX_CYLINDERS; i++)
|
|
|
|
|
mapping[i] = i;
|
|
|
|
|
cylinder_renumber(&displayed_dive, mapping);
|
2017-10-20 08:16:37 +00:00
|
|
|
|
if (in_planner())
|
|
|
|
|
DivePlannerPointsModel::instance()->cylinderRenumber(mapping);
|
2017-10-20 14:54:14 +00:00
|
|
|
|
changed = true;
|
|
|
|
|
endMoveRows();
|
2017-10-11 19:29:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-06 12:40:30 +00:00
|
|
|
|
void CylindersModel::updateDecoDepths(pressure_t olddecopo2)
|
|
|
|
|
{
|
|
|
|
|
pressure_t decopo2;
|
|
|
|
|
decopo2.mbar = prefs.decopo2;
|
|
|
|
|
for (int i = 0; i < MAX_CYLINDERS; i++) {
|
|
|
|
|
cylinder_t *cyl = &displayed_dive.cylinder[i];
|
|
|
|
|
/* If the gas's deco MOD matches the old pO2, it will have been automatically calculated and should be updated.
|
|
|
|
|
* If they don't match, we should leave the user entered depth as it is */
|
|
|
|
|
if (cyl->depth.mm == gas_mod(&cyl->gasmix, olddecopo2, &displayed_dive, M_OR_FT(3, 10)).mm) {
|
|
|
|
|
cyl->depth = gas_mod(&cyl->gasmix, decopo2, &displayed_dive, M_OR_FT(3, 10));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
emit dataChanged(createIndex(0, 0), createIndex(MAX_CYLINDERS - 1, COLUMNS - 1));
|
|
|
|
|
}
|
2016-07-06 12:40:35 +00:00
|
|
|
|
|
2017-03-13 07:25:32 +00:00
|
|
|
|
void CylindersModel::updateTrashIcon()
|
|
|
|
|
{
|
|
|
|
|
emit dataChanged(createIndex(0, 0), createIndex(MAX_CYLINDERS - 1, 0));
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-06 12:40:35 +00:00
|
|
|
|
bool CylindersModel::updateBestMixes()
|
|
|
|
|
{
|
|
|
|
|
// Check if any of the cylinders are best mixes, update if needed
|
|
|
|
|
bool gasUpdated = false;
|
|
|
|
|
for (int i = 0; i < MAX_CYLINDERS; i++) {
|
|
|
|
|
cylinder_t *cyl = &displayed_dive.cylinder[i];
|
|
|
|
|
if (cyl->bestmix_o2) {
|
|
|
|
|
cyl->gasmix.o2 = best_o2(displayed_dive.maxdepth, &displayed_dive);
|
|
|
|
|
// fO2 + fHe must not be greater than 1
|
|
|
|
|
if (get_o2(&cyl->gasmix) + get_he(&cyl->gasmix) > 1000)
|
|
|
|
|
cyl->gasmix.he.permille = 1000 - get_o2(&cyl->gasmix);
|
|
|
|
|
pressure_t modpO2;
|
|
|
|
|
modpO2.mbar = prefs.decopo2;
|
|
|
|
|
cyl->depth = gas_mod(&cyl->gasmix, modpO2, &displayed_dive, M_OR_FT(3, 10));
|
|
|
|
|
gasUpdated = true;
|
|
|
|
|
}
|
|
|
|
|
if (cyl->bestmix_he) {
|
2016-07-06 12:40:36 +00:00
|
|
|
|
cyl->gasmix.he = best_he(displayed_dive.maxdepth, &displayed_dive);
|
2016-07-06 12:40:35 +00:00
|
|
|
|
// fO2 + fHe must not be greater than 1
|
|
|
|
|
if (get_o2(&cyl->gasmix) + get_he(&cyl->gasmix) > 1000)
|
|
|
|
|
cyl->gasmix.o2.permille = 1000 - get_he(&cyl->gasmix);
|
|
|
|
|
gasUpdated = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-07-06 12:40:37 +00:00
|
|
|
|
/* This slot is called when the bottom pO2 and END preferences are updated, we want to
|
|
|
|
|
* emit dataChanged so MOD and MND are refreshed, even if the gas mix hasn't been changed */
|
2017-12-01 11:49:38 +00:00
|
|
|
|
if (gasUpdated)
|
|
|
|
|
emit dataChanged(createIndex(0, 0), createIndex(MAX_CYLINDERS - 1, COLUMNS - 1));
|
2016-07-06 12:40:35 +00:00
|
|
|
|
return gasUpdated;
|
|
|
|
|
}
|