Commit graph

10374 commits

Author SHA1 Message Date
Dirk Hohndel
605d085573 QML UI: resolve confusion about dive list model ordering
Oops, I forgot to take the sort model on top of the model into account.
Now everything should stay consistent - ListView order when accessed from
QML, but internal order when accessing the underlying array.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-03-02 09:02:00 -08:00
Dirk Hohndel
cd713d421b QML UI: update profile when editing duration of manually added dive
We need to make sure that a new fake DC is created after the duration was
changed.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-03-02 06:28:00 -08:00
Dirk Hohndel
880f1c5644 QML UI: update the correct dive in the model when committing a change
When manually adding a dive and moving it in the dive list (by editing
it's start time) we could create a situation where the dive list
internally was correct, but the dive list model on screen showed an
incorrect dive list with the new dive in two different spots.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-03-02 04:52:44 -08:00
Dirk Hohndel
62f54b54a2 QML UI: create a chronological dive list when manually adding dive
The dive list might contain dives in the future, don't add the new dive to
then end but instead add it at the correct spot in the list

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-03-02 04:50:00 -08:00
Dirk Hohndel
ce83357889 QML UI: after adding a dive, jump to it in the list
Don't do the slow motion scrolling through the list if we previously
showed a different dive in the list.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-03-02 04:47:51 -08:00
Dirk Hohndel
3b37844708 Add helper functions to identify the position of a dive in the dive list
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-03-02 04:46:26 -08:00
Lubomir I. Ivanov
b275e604c1 templatelayout.cpp: fix potential issue in preprocessTemplate()
The function preprocessTemplate(), did not account well
for indexes in Grantlee variables, such as:
dive.weight# (where # is the index)
dive.cylinder#

To solve the issue the list (QList<QPair<QString, QString> >)
for variables to be replaced is populated will all possible
indexes:
0 - MAX_WEIGHTSYSTEM for weights
0 - MAX_CYLINDERS for cylinders

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-29 15:42:33 -08:00
Dirk Hohndel
abab031ed2 QML UI: implement undelete
This code is very similar to the undo code in the desktop UI, but
untangling that from the desktop seemed massive overkill; we don't have
lists of dives to delete and undelete here - so this is actually much
simpler and easier to maintain (I hope).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-29 15:42:33 -08:00
Dirk Hohndel
e39e9eee3b QML UI: present an undo dialog after delete
The dialog gives the user 3 seconds to undo the delete and then disappears
without any user interaction.

This isn't hooked up, yet.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-29 15:41:58 -08:00
Robert C. Helling
84769dc2f6 This computes the compressibility of the gas depending on the mixture.
As it turns out, the van der Waals equation gives results that are
numerically not really useful, so we use the Redlich Kwong equation
which is, according to Wikipedia, much more accurate, which can be confirmed
given the empirical values for air.

As opposed to the previous approach with a look-up table, this takes
into account the actual gasmix. This always assumes the gas to be at
20 degrees Centigrade.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-29 08:58:16 -08:00
Lubomir I. Ivanov
f2fa087b3b user-manual.txt: mention some more Grantlee variables
With the recent refactoring of the DiveHelperObject class, some
more Q_PROPERTIES were added and can be used with the Grantlee engine.
We expose some of the additions to the user via the manual.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-29 07:33:47 -08:00
Lubomir I. Ivanov
1d06c383a2 DiveHelperObject: add the weightList and cylinderList properties
"weights" and "cylinders" are QStringList Q_PROPERTIES, and Grantlee
should be able to render them, but it doesn't.

To be able to print the whole list of weights and cylinders we
introduce two new QString properties "weightList" and "cylinderList".

The variable replacement in the previous patch deals with the
conversation of the user side HTML, e.g.:

USER                  ->   INTERNAL
"{{ dive.weights }}   ->   {{ dive.weightList }}"
"{{ dive.cylinders }} ->   {{ dive.cylinderList }}"

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-29 07:33:31 -08:00
Lubomir I. Ivanov
0aa8ef918d templatelayout.cpp: add a HTML preprocessor stage
The current Grantlee template loading scheme does not
allow a preprocessing layer. With the recent DiveObjectHelper
changes the layer is required if we don't want to add a set
of dummy methods and Q_PROPERTIES which will only inflate
the DiveObjectHelper class.

Use the already present helper readTemplate() to load the
raw HTML template and pass it to a static function which
does some variable replacement to accomudate DiveObjectHelper.

This change is done for the sake of not breaking the Grantlee
HTML variables on the user side!

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-29 07:32:57 -08:00
Dirk Hohndel
0b7be8ec5e QML UI: small adjustment to DiveDetailsView
This reduces the margin to use more of the available space and also makes
the first column slightly wider so the word "Cylinder" isn't broken on a
Nexus 6p.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-28 17:18:56 +01:00
Dirk Hohndel
2bf6f4e45d QML UI: ensure that after a dive edit the profile is redrawn
Normally this is triggered when the DiveDetailsView component is
completed, but since QML isn't recreating this component unless we switch
to a dive a couple of spots in the dive list away from this one, we
wouldn't get any changes in the data reflected in the profile.

But since this now redraws the same dive that potentially was drawn last,
we need to make sure we call plotDive() with force=true.

I also suspect that this could help with the strange bug that sometimes we
show a blank profile after certain edits.

See #1013

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-28 16:46:50 +01:00
Dirk Hohndel
10af45d6dc QML UI: we no longer use the return value of commitChanges()
So make it a void function.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-28 15:45:26 +01:00
Robert C. Helling
26779a9af5 If salinity is not density, add density of fresh water
There was a reported case of an import of a dive that gave a salinity of
35g/l. This is an actual salinity (an amount of salt in the water) but
for subsurface the salinity is actually the density of the water. So for
too small values of the salinity add the density of fresh water.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-28 15:39:52 +01:00
Linus Torvalds
45ed0ec757 gas pressures: use an actual compressibility table for air
We could in theory make this dependent on the gasmix, but for now let's
just assume (incorrectly) that everything we breathe acts like air.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-25 01:22:32 +01:00
Linus Torvalds
adaeb506b7 Show both the nominal and "real" size for an imperial cylinder
This is questionable, but perhaps useful.

When showing imperial cylinder sizes, show both the nominal value (with
no compensation for compressibility of the gas) and the "actual" amount
of gas the cylinder contains.

So an AL80 will show as a size of "80 (77)cuft", because while 80 is the
nominal size, the actual amount of gas that will fit is just 77 cuft.

[Dirk Hohndel: adjusted to take translation of the unit into account]

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-25 01:19:00 +01:00
Linus Torvalds
288aff9dbb 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-25 00:58:09 +01:00
Linus Torvalds
7ebc31c1ec gas pressures: do not use gas compressibility for cylinder naming
This actually didn't make a difference for the common case, since our
simplified gas compressibility model had a compressibility factor of 1.0
up to 200 bar, and increased smoothly from there.  As a result, the
common 2400 and 3000 psi workpressures didn't really see an effect from
this.

Not taking compressibility into account does kind of make sense for
cylinder naming, since the cylinder may be used for different gases with
very different compressibility characteristics.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-25 00:45:38 +01:00
Linus Torvalds
82c003c914 gas pressures: do some initial cleanup
This marks "surface_volume_multiplier()" static in preparation for
changing it to use an actual honest-to-goodness compressibility
estimation.  Without that, it wasn't obvious that the function wasn't
used in other random places.

Also, remove the "wet_volume()" function.  It was unused, but more
importantly, it was wrong.  Yes, it was the inverse of "gas_volume()",
but when you calculate wet volumes from the imperial sizes, you don't
actually use the "real" gas volume, you use the idealized one.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-25 00:45:35 +01:00
Miika Turkia
7564c89360 Initialize the random number generator
We use random numbers for file names, both temporary filename when
creating a zip for divelogs.de upload and for filename on form data for
facebook upload. This does not require for true randomness but we still
want these to not be constant on each run of Subsurface. Thus we need to
initialize the random number generator.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-25 00:38:13 +01:00
Miika Turkia
2b8e8849e6 Use full precision on weight system on XSLT transforms
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-25 00:38:03 +01:00
Dirk Hohndel
86ec3d06a2 Correctly round total weight displayed
The code was wrong (and in the case of metric display for weights >= 20kg,
spectacularly wrong) in more or less all cases.

Rounding. It's good for the sole.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-24 08:20:24 +01:00
Dirk Hohndel
6d52d0f761 QML UI: add context menu to delete dive
This allows the user to delete the currently shown dive. This action takes
effect right away, no confirmation, it gets right away written to the
local git cache.

One idea for an undo operation here could be to simply reset the git tree
to HEAD^ and reload. Not elegant, but would work.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-23 14:07:49 +01:00
Dirk Hohndel
2772ab8764 Add helper to delete dive from QML
Once again we make this save the changes to the local cache without being
prompted.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-23 14:07:49 +01:00
Miika Turkia
ae22b7cae0 Divelogs.de import: encode + character on password
Upload seems to work as is...

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-23 14:07:49 +01:00
Linus Torvalds
10ae00db3c pressure interpolation: incrementally update interpolation data
Instead of re-calculating all the interpolation data for each plot entry
(which means that we have a quadratic algorithm that walks over all the
plot-info points for each plot-info point), we can just update it
incrementally within any particular interpolation segment.

The previous cleanups made the code sane enough to understand, and makes
it trivial to see how you don't have to recalculate the full thing.

This gets rid of the O(n**2) algorithm, and it instead becomes O(n*m)
where 'n' is the number of plot entries, and 'm' is the number of gas
segments (which is usually a much smaller numer, typically "1").

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-21 16:36:10 -08:00
Linus Torvalds
b71fc7ffb2 pressure interpolation: further code simplification
With the two bigger simplications, this just re-organizes the code to do
the "interpolate.pressure_time" update that is shared among all the
"after segment start" cases in just one place.

That leaves the get_pr_interpolate_data() much simpler, and makes it
much clearer what it actually does.

In particular, it becomes very obvious that "interpolate.pressure_time"
is constant for one particular segment (it's the total pressure time),
and that "interpolate.acc_pressure_time" is the one that gets updated
for every entry.

The next step is to only call this for the first entry, and then update
just the "acc_pressure_time" in the caller.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-21 16:34:46 -08:00
Linus Torvalds
398cd5d9cc pressure interpolation: simplify code
Getting rid of the pointless always-zero pressure now makes it obvious
how some of the remaining code can just be removed too: there is no
point in re-initializing the pressure_time entries to zero at the
segment start, because they started out zero and we just checked that we
don't do anything to them before we hit the segment start.

Similarly, now that the silly pressure testing is gone, it is obvious
that the code for "i < cur" and "i == curr" cases is identical, and the
two cases can just be collapsed.

Signed-off-by: Linus Torvalds <torvalds@ linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-21 16:33:39 -08:00
Linus Torvalds
1f7f3c4af5 pressure interpolation: get rid of pointless and confusing code
In the function fill_missing_tank_pressures(), we only ever call
get_pr_interpolate_data() if "pressure" is zero.  So passing it in as an
argument, and then testing whether it is zero or not, is just totally
pointless, and only obfuscates things.

This whole thing seems to be due to people editing the code over time,
with the tests becoming superfluous as the code around it changed, and
nobody looking at whether it actually made sense any more.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-21 16:32:45 -08:00
Dirk Hohndel
5da9486533 QML UI: further validation in the C++ code
Don't allow negative depth or depth beyond 500m.

Additional checks that the gas mix is possible (even thought QML code
SHOULD only allow valid combinations).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-20 22:11:03 -08:00
Dirk Hohndel
a550467e8b QML UI: make unit matching case insensitive
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-20 22:00:07 -08:00
Dirk Hohndel
8b39352d4e QML UI: only allow valid gas mixes
The input is restricted to

EAN100
EANxx  (with 'x' one of 0..9)
AIR
xx/xx  (with 'x' one of 0..9)
xxx    (with 'x' one of 0..9 and the number <= 100)

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-20 21:57:53 -08:00
Dirk Hohndel
e22a452cf5 QML UI: don't allow negative duration or depth
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-20 21:50:11 -08:00
Dirk Hohndel
38ab11a6c0 Add option to allocate the samples in fake_dc()
We (ab)use fake_dc() to create a pleasing profile for a manually added
dive. Based on it's intended use, fake_dc() simply handed back a dc
structure that pointed at staticly allocated samples - that's obviously
(now that I think about it) going to blow up in my face if I edit a
manually added dive more than once.

So now we have an option for fake_dc() to actually allocate the samples -
this way the rest of the code can treat these samples as we would treat
samples created any other way. We can free them and replace them with a
new set.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-20 09:36:14 -08:00
Dirk Hohndel
0b0e56edeb After freeing the samples, clear the pointer
Otherwise we might end up trying to free them a second time.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-20 07:39:25 -08:00
Dirk Hohndel
5fc16910c2 QML UI: fix recreation of profile after dive edit
We only need to deal with this if the dive changed. And in that case, if
we calculate a new fake DC, we need to clear out the meandepth as
otherwise the algorithm will try to match both max and mean depth. Since
the user potentially changed the max depth that could have very odd
consequences.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-20 07:33:05 -08:00
Dirk Hohndel
97d6a1e779 QML UI: no longer change unit preferences when parsing edits
When the user explicitly sets the units when editing or adding dives, we
used to change the display preferences. This was changed for some but not
all fields in commit 6252d0cd3b ("While parsing weight and pressure we
should not change the users settings")

Now we do this consistently for all inputs.

Also, when editing the depth of a manually added dive, we now throw away
the samples (as those are certain to be inconsistent).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-15 07:54:35 -08:00
Dirk Hohndel
75bd37e3e5 Clean up conversion helpers
- coding style (ugh - I should have fixed that when I first committed them)
- remove redundant variables
- add similar code to the length and temperature helpers

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-15 07:50:30 -08:00
Dirk Hohndel
bbbd479914 QML UI: better text when no profile is shown for a dive
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-15 07:27:00 -08:00
Dirk Hohndel
a3189a9b3e QML UI: don't show an odd profile for zero duration dive
A dive with zero duration creates an odd profile that is 2min 30seconds
long and looks just weird. Instead, simply show a text that there is on
profile shown for such a dive.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-14 16:27:41 -08:00
Dirk Hohndel
06ad45c48f Add dive property to easily test if there isn't an actual dive
Right now this just tests for zero duration, but maybe this should also
return true for positive duration and max depth of 0.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-14 16:26:37 -08:00
Dirk Hohndel
58f014728c Remove debug output
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-14 16:08:50 -08:00
Miika Turkia
8e4b4c788a Grab pressures from samples if required
If cylinder does not have start and end pressures assigned, attempt to
grab them from the samples instead.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-14 12:37:37 -08:00
Miika Turkia
8c38dbf3b7 Test cylinder usage properly
It is better to use the proper function to test if cylinder is in use
than just checking the description.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-14 12:37:30 -08:00
Dirk Hohndel
c97ed010c7 QML UI: back key on dive list exits the app
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-14 12:17:24 -08:00
Dirk Hohndel
f2c8aed07b QML UI: when canceling a dive add, go back to dive list
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-13 23:54:40 -08:00
Dirk Hohndel
3413dfc3aa QML UI: simplify and correct top bar layout
Now things are centered and reasonably well spaced

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-13 23:44:59 -08:00