Commit graph

70 commits

Author SHA1 Message Date
Robert C. Helling
9c8fbe494d Planner: Add option to treat O2 as narcotic
When computing the best mix for a target depth, for helium, one
can either require that the partial pressure of N2 is the same
as at the target depth or the partial pressure of N2 plus O2.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-10-31 00:30:38 -07:00
Berthold Stoeger
00944f7a02 Core: pass dive, cylinder-id to fill_default_cylinder
The fill_default_cylinder() function calculated the MOD based
on the currently displayed dive. This does not seem to make sense:
- When importing dives, why would we care about the altitude and
  salinity of the currently displayed dive, possibly from a different
  trip.
- The planner is supposed to be thread-safe and should not touch
  global variables.

Of course this means that the importing-functions have to fill
out altitude and salinity before creating the default cylinder,
but this is their problem. For a freshly created dive they will
get the default values, which still seems less random than the
values from the displayed dive.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-08 16:26:31 -07:00
Berthold Stoeger
8f119dcf72 Cleanup: remove includes from qthelper.h
To reduce interdependencies, remove the dive.h and divelist.h
includes in qthelper.h

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-18 05:42:55 -07:00
Berthold Stoeger
27944a52b1 Undo: don't send signals batched by trip
Since the default view is batched by trips, signals were sent trip-wise.
This seemed like a good idea at first, but when more and more parts used
these signals, it became a burden. Therefore push the batching to the
part of the code where it is needed: the trip view.

The divesAdded and divesDeleted are not yet converted, because these
are combined with trip addition/deletion. This should also be detangled,
but not now.

Since the dive-lists were sorted in the processByTrip function, the
dive-list model now does its own sorting. This will have to be
audited.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-23 20:08:46 +02:00
Berthold Stoeger
38ba434966 Cleanup: return directly from data() methods
There is this anti-pattern in QModel data() functions to assign
to a "ret" variable and return at the end of the function. This
is inefficient, as the object is not directly constructed at
the space reserved by the caller.

Change the functions in WeightModel and CylinderModel to return
the objects directly.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-19 13:11:10 -07:00
Berthold Stoeger
7f4d9db962 Cleanup: move trip-related functions into own translation unit
These functions were spread out over dive.c and divelist.c.
Move them into their own file to make all this a bit less monolithic.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-19 13:11:10 -07:00
Berthold Stoeger
9fd87fa080 Undo: update cylinder and weight models on paste
When pasting (or undoing paste) the cylinders or weights may change.
Send the appropriate signals and update the models accordingly.
Currently, this means copying from current dive to displayed dive,
but hopefully we can get rid of "displayed_dive" in the not so
distant future.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
dd12bdaf94 Dive site: add dive site list tab
Add a very simple tab-widget presenting the list of known dive sites.
The table is rendered using our custom "TableView".
The (mis)uses the "LocationInformationModel". It moves the items
to be displayed (delete, name, description, number of dives) to the
front and makes the others hidden.

Moreover, it was necessary to limit the geo-tag decoration role to
the name to avoid having the icon next to each column.

Make the trash-can icon active and the name and description editable.
This is modelled after the cylinders-table code.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Robert C. Helling
30746e5d3f Make sure surface air is not considered a deco gas
it creapt in through the gaschange events.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-03-29 06:51:12 -07:00
Berthold Stoeger
360f07e453 Cleanup: pass gasmix by value
In a previous commit, the get_gasmix_* functions were changed to
return by value. For consistency, also pass gasmix by value.

Note that on common 64-bit platforms struct gasmix is the size
of a pointer [2 * 32 bit vs. 64 bit] and therefore uses the
same space on the stack. On 32-bit platforms, the stack use
is probably doubled, but in return a dereference is avoided.

Supporting arbitrary gas-mixes (H2, Ar, ...) will be such an
invasive change that going back to pointers is probably the
least of our worries.

This commit is a step in const-ifying input parameters (passing
by value is the ultimate way of signaling that the input parameter
will not be changed [unless there are references to said parameter]).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-23 05:16:38 -07:00
Berthold Stoeger
879cb73b8b Localization: remove gettextFromC::instance()
There were a handfull instances of the kind
1) gettextFromC::instance()->tr(...)
2) gettextFromC::instance()->trGettext(...)

1) is pointless, as tr is a static function.

All instances of 2) were likewise pointless, because trGettext()
returns a C-string, which was then immediately converted to a
QString.

Thus, replace both constructs by gettextFromC::tr(...).

After this change there was only one user of gettextFromC::instance()
left, viz. the C-interface funtion trGettext(). Therefore, remove
gettextFromC::instance() and do all the caching / translating
directly in the global trGettext().

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-06-24 20:31:14 +02:00
Berthold Stoeger
36b9e5e31e Cleanup: fold core/helpers.h into core/qthelper.h
helpers.h included qthelper.h and all functions declared in helpers.h
were defined in qthelper.h. Therefore fold the former into the latter,
since the split seems completely arbitrary.

While doing so, change the return-type of get_dc_nichname from
"const QString" to "QString".

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-06-04 08:50:10 -07:00
jan Iversen
b0e48a5e8f qt-models: Change Q_UNUSED to no parameter name
C++ permits use of parameters without name, which signals unused

Signed-off-by: Jan Iversen <jani@apache.org>
2018-05-21 12:48:04 -07:00
Dirk Hohndel
ea83b5ed37 Core: remove dive.h from files that don't need it
Of course, quite a few of them indirectly get it through other header
files.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-05-14 10:13:39 -07:00
Berthold Stoeger
b72cc1f317 Cleanup: consistently use qPrintable()
Replace constructs of the kind
  s.toUtf8().data(),
  s.toUtf8().constData(),
  s.toLocal8Bit().data(),
  s.toLocal8Bit.constData() or
  qUtf8Printable(s)
by
  qPrintable(s).

This is concise, consistent and - in principle - more performant than
the .data() versions.

Sadly, owing to a suboptimal implementation, qPrintable(s) currently
is a pessimization compared to s.toUtf8().data(). A fix is scheduled for
new Qt versions: https://codereview.qt-project.org/#/c/221331/

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-14 13:55:36 +02:00
Stefan Fuchs
aacc688670 Use correct numeric format based on selected locale (Qt domain part)
This changes the numeric format of many values printed to the UI to
reflect the correct numeric format of the selected locale:
- dot or comma as decimal separator
- comma or dot as thousands separator

In the Qt domain the `L` flag is used case specific mostly
in qthelper.cpp.
Then the helper functions get_xxx_string() are used more consistently.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-03-05 16:28:18 +01:00
Stefan Fuchs
4cbf8b87a3 Updated strategy for removing cylinders
Change the strategy when to allow cylinder removal from a dive:
- Not remove when cylinder has gas switch events, in any other cases
  allow removal
- Remove this whole "cylinder with same gas" thing being a criteria
  for cylinder removal

When removing a cylinder which has corresponding pressure info in
samples, also remove this pressure info from the samples.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-02-27 09:17:57 +01:00
Robert C. Helling
6d3c2327bd Initialise cylinder start pressure with working pressure
In the planner, this is the natural assumption.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-01-26 07:04:45 +01:00
Berthold Stoeger
130f109442 Remove superfluous QScopedPointer<>s in singletons
There was a curious pattern of singletons being implemented based on
QScopedPointer<>s. This is an unnecessary level of indirection:
The lifetime of the smart pointer is the same as that of the
pointed-to object. Therefore, replace these pointers by the respective
objects.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-24 11:04:10 -08:00
Robert C. Helling
4d605ce51f Prevent redundant replanning
Planning dives is heavy on CPU, so better be sure we only
do it when needed. In particular, when moving around dive
points, we only want a new plan once per move and not three
times (triggered at various points in the chain of events).

This should significantly improve planner snappiness.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-12-01 15:47:51 -08:00
Stefan Fuchs
8a92484b0c Add debug function dump_cylinders
This function can be used to dump print all cylinder data.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-11-27 22:40:16 +01:00
Stefan Fuchs
2bfcc5554f Tidy up code for cylinder remove decision in cylindermodel.cpp
Replace currentMode() != ...:NOTHING with equivalent in_planner()

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-10-30 21:45:56 +01:00
Stefan Fuchs
96d2e57843 When removing a cylinder completely fill the mapping table
When deleting a cylinder the mapping was not filled with all
necessary values. Values for cylinders before deleted cylinder were
missing.

Plus do the endRemoveRows at the right time.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-10-21 15:33:57 -04:00
Dirk Hohndel
27c49fe3ad Silence random warnings
None of these seem to point to actual issues, so let's quiet them.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-10-20 17:25:18 -04:00
Stefan Fuchs
748bb90a73 Update dive planner points cylinder names also when cyl is added
Amendment to c29456f0bb

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-10-20 07:55:18 -04:00
Stefan Fuchs
93e2bda070 Do cylinder renumber for dive data points only when in planner mode
Amendment to 73d2ab8099

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-10-20 07:55:18 -04:00
Stefan Fuchs
24bd5a8dce Planner: Autom. move first datapoint gas to first gaslist position
In the planner it is best practise to start the dive with the first
gas in the gaslist. Otherwise one would get a gaschange event at the
very beginning of a dive.
This change implements the following feature:
Automatically move a gas to position 0 in the gaslist if the user selects
this gas for the first dive data point.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-10-16 17:14:17 +02:00
Stefan Fuchs
73d2ab8099 Update diveplannerpoints cylinderidx when deleting a cylinder
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-10-16 17:14:17 +02:00
Stefan Fuchs
c29456f0bb Used gas in dive planner points: Support for multiple cyl with same gas
In the planner if one adds two or more cylinders with the same gasmix
(e.g. back gas and bottom stage 18/45) the drop down and data in the
used gas column of the planner points table will be filled with a more
verbose string mentioning also the cyl number and the cyl type
description.
Makes it easier in such a case to select the right cylinder.

Introduces also a helper function which tells you if there is another
cylinder with the same gasmix as the provided cylinder.
This also has an option if it should consider unused cylinders or not.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-10-16 17:14:17 +02:00
Stefan Fuchs
8fd1c72f04 Removing cylinders in planner: Be more restrictive
Be even more restrictive regarding which cylinders can be removed from
the cylinder table in the planner.
Only if a cyliner is not used in the planned part of the dive
it can be removed.
It doesn't matter if there is another cylinder with same gasmix.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-10-16 17:14:17 +02:00
Linus Torvalds
2fa66f7ab1 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-30 21:28:38 -07:00
Dirk Hohndel
5372f12d8b Add SPDX header to Qt models
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-04-29 13:32:55 -07:00
Stefan Fuchs
d83449f3b5 Don't erroneously mark the cylinder pressure red - second try
Second attempt to do the thing with the red background color for cylinder
start and end pressure correctly. This now should cover all scenarios.

This rewrites and partitially reverts commit b8e044d

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-03-24 09:35:51 -07:00
Stefan Fuchs
8834fc0443 Correctly trigger update of cylinder table trash icons in planner
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-03-13 10:26:18 -07:00
Stefan Fuchs
ac52034778 Correct trash or trashforbidden icon and tooltip in cylinder table
Display the correct trash or trashforbidden icon and tooltip in the cylinder table.
This should fit together with if it is really possible to remove a cylinder.

Search for "same gas" based on used cylinders only. Otherwise one could remove
a used cylinder because there is an unused cylinder with same gas.

ToDo:
In planner update trash icon on change of planner points.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-03-11 16:01:53 -08:00
Stefan Fuchs
b11af5a1ce Add units (m or ft) for MOD and MND in cylinder table in planner
We do display the unit for "Gas change at" today so we should also display it for MOD and MND.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-03-11 16:01:53 -08:00
Martin Měřinský
dcf2542215 Use abbreviations with dots. 2017-03-11 08:09:07 -08:00
Stefan Fuchs
b8e044dee3 Don't erroneously mark the cylinder pressure red and set font italic
In the cylinder table today the cylinder start and end pressure fields
are marked red and the end pressure font is set to italic if cyl->end is 0.
But sometimes with planned dives there is no cyl->end but only cyl->sample_end.
This is taken into account now.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-03-11 07:27:18 -08:00
Stefan Fuchs
ab887e4438 Fix cyclinder table issue "workingpressure" in planner
Fixes the issue that the cylinder table in the planner is messed up after
changing the table header.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-03-11 07:27:18 -08:00
Robert C. Helling
0eb42b35b8 Call the cylinder working pressure "starting pressure" in planner
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-02-26 08:20:31 -08:00
Dirk Hohndel
08c42813e5 Revert "In statistics, ignore gas use of planned dives"
This reverts commit 1d8662006c.

Mistakenly pushed to master

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-02-03 07:31:03 -08:00
Robert C. Helling
1d8662006c In statistics, ignore gas use of planned dives
When merged with real dives, those would double count otherwise.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-02-02 12:37:24 -08:00
Robert C. Helling
c1dc0c9ce0 Allow user to disable a cylinder in planner
In the cylinder table, the last column ("use") always showed
OC-GAS. Editing was enabled, but the user had to guess to enter
a small integer meaning dilluent or CCR oxygen cylingder. I guess,
nobody has ever done that.

This patch makes this column clickable. A click toggles if the cylinder
is used for planning or not. This wait it is much easier to investigate
the consequences of gas loss on a plan.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-01-23 22:11:51 -08:00
Dirk Hohndel
7f7c008247 Revert "Show both the nominal and "real" size for an imperial cylinder"
This reverts commit adaeb506b7.

commit a8e8d56ec0 ("Tweak cylinder equipment tooltips") does a much
better job allowing the user to know the true volume of the cylinder
(given the gas entered) and clutters the UI a lot less.
2017-01-16 03:30:57 -08:00
Linus Torvalds
a8e8d56ec0 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 adaeb506b7 ("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 03:22:33 -08:00
Linus Torvalds
638e7fb28f 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>
2017-01-12 14:17:09 -08:00
Rick Walsh
9710ac8926 CylindersModel: add tooltips for Deco switch at, Bot MOD and MND
Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-08-10 15:05:14 -07:00
Rick Walsh
b78e6525eb Remove unnecessary DivePlannerPointsModel functions and variables
Commit b1ed04a means that DivePlannerPointsModel::rememberTanks() and related
functions and variables are no longer required

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-07-23 10:54:51 +09:00
Rick Walsh
f96f3abcdc Relabel cylindermodel "Deco MOD" column to "Deco switch at"
Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-07-23 10:53:39 +09:00
Rick Walsh
bb31517951 Planner: update cylinder mixes and MND and MOD when prefs are changed
Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-07-09 12:08:48 -07:00