Search the index of an item in a container. Compare by
equality or a lambda. The lack of these have annoyed me for a
long time. Return the index of the first found element or
-1 if no element found.
Currently, only supports random-access operators. Might be
trivially changed for forward iterators.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The chances that their are still users of the old thumbnail
format (i.e. all thumbnails saved in the hash file) are basically
0. If there are they will just get their thumbnails rebuilt
when opening the individual dives.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This source file was looping over descriptors in a classical
"for (int i = 0; i < size; ++i)" loop.
However, the index is not really used, except for fetching the
actual elements.
Replace by range-based for loops. This prevents the potential
error of using the wrong size.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In the printing-template code, we loop through a vector and
then determine the index of the current element by searching
the vector. This irks me.
Since looping over a collection with an index is a rather
common theme, implement an enumerating iterator that can
be used as in:
for (auto [idx, item]: enumerated_range(v)) {
...
}
For now, use it for the above vexing case. Convert other
iterations of this theme later.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The moveInVector() function was defined in qthelper.h, even
though it has nothing to do with Qt. Therefore, move it into
its own header.
Morover, since it is a very low-level function, use snake_case.
And rename it to move_in_range(), because it does not only
work on vectors, but any range with random-access iterators.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
For reasons of symmetry (there is a is_manually_added_dc()
function), create a make_manually_added_dc() function.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This causes UI confusion. Notably we go into edit mode and
reduce the number of samples, leading to loss of information.
If someone really manually adds a dive with more than 50
samples, they should still be able to explicitly open the
dive in the planner.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
fixup_dc_sample_sensors() would make sure that any pressure sensor
indexes were in range of the cylinders by just clearing the pressure
data if the sensor index was larger than the number of cylinders in the
dive.
That certainly makes the sensor index data consistent, but at the cost
of just dropping the sensor data entirely.
Dirk had some cases of odd sensor data (probably because of an older
version of subsurface, but possibly due to removing cylinders manually
or because of oddities with the downloader for the Atomic Aquatics
Cobalt dive computer he used), and when re-saving the dive, the pressure
data would magically just get removed due to this.
So rewrite the sensor data fixup to strive very hard to avoid throwing
pressure sensor data away. The simplest way to do that is to just add
the required number of cylinders, and then people can fix up their dives
manually by remapping the sensor data.
This whole "we clear the pressure data" was at least partly hidden by
two things:
(1) in the git save format, we don't rewrite dives unless you've
changed the dive some way, so old dives stay around with old data
in the save until explicitly changed.
(2) if you had multiple dive computers, and one dive computer does not
have any pressure data but another one does, our profile will use
that "other" dive computer pressure data (because often times you
might have only one dive computer that is air integrated, but you
still want to see the tank pressure when you look at other dive
computers - or you have one dive computer give pressure data for
your deco bottle, and another for your travel gas etc).
So those two facts hid the reality that we had actually cleared the tank
sensor data for Dirk's dive with the Atomic Aquatics dive computer,
because we'd still see pressure data in the profile, and the git data
would still be the old one.
Until Dirk renumbered his dives, and the data was rewritten.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
It returned a 'uint8_t', which clashes pretty badly with NO_SENSOR being
-1, and turned it into 255. That then ended up historically working,
because before commit 0c84f369c3 ("core: use int16_t for sensor-id")
we actually did that everywhere:
#define NO_SENSOR ((uint8_t)-1)
...
uint8_t sensor[MAX_SENSORS];
but that was changed to
#define NO_SENSOR -1
...
int16_t sensor[MAX_SENSORS];
and this helper type became wrong.
Just make it return 'int', avoiding any type narrowing issues.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
A QVariant was initialized but never used.
While doing so, remove construct/assign pairs of a number of
QStrings. Directly construct the QStrings with the desired
values.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The get_minutes() function formats a time as m:ss
and returns a static C-string. Since all callers are
C++ anyway and transform directly into QString, let us
move this to the other string formatting function.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The SSRF_INFO() macro is widely used, and there's a lot of confusion
about whether the newline at the end should be done by the SSRF_INFO or
be in the format string passed to it. End result: we end up doing both,
and there are empty lines in the output as a result.
Clean this up by just using our existing 'strip_mb()' to strip any
whitespace at the end of the generated string, and then adding one final
newline when logging it.
Also, make sure to log our 'report_error()' messages, which apparently
only used to be showin in the red error bar on the display.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
No reason to keep this as a macro - a function is easier to
read, type safe and easier to debug. Moreover, give it the
more appropriate name "nearly_equal()". After all, it precisely
does NOT check floating points for equality.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The FP_IS_SAME macro uses a relative precision to compare
floating points. This fails when comparing to 0. Therefore,
use an absolute precision in this case. Implement as an
inline function.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
For Ratio dive computers we can't tell by the Bluetooth name which model it is.
There are BT only models and BLE only models. The failure case here was a user
on iOS (BLE only) with a BLE only dive computer which we didn't recognize
because previously we returned a BT only device (which isn't supported on an
iPhone), and the lookup won't return a valid descriptor if the transport needed
isn't available.
These days BLE is far more common, so return a BLE enabled name by default, but
try a BT only name just in case.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
When a dive has both real dive computers as well as at
least a planned version (which is just another dive
computer with a special name), only use the data from
real dive computers for aggregate values like maxdepth,
dive time, average depth etc in order not to have
imagined data on the dive list, statistics etc.
Macro-magic-provided-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Robert C. Helling <helling@atdotde.de>
One would think that calling free() on a dive structure, as the code
did in some places, would lead to a memory leak.
(Insert rant about C memory management.)
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This is stored as uint32_t, so no reason to use the larger time_t.
It appears to be, after all, relative to the dive start.
Coverity was complaining about the down-conversion later in the code.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Adds a preference setting in the "Default" settings tab to toggle whether
to display shortened names in the Map.
TODO: instead of using the generic "settingsChanged" signal, it would be much
more efficient to only update items based on the actual setting which was
changed.
Signed-off-by: Michael WERLE <micha@michaelwerle.com>
In bc3b56a969, the import of the dive mode was simplified,
by replacing an if-else-if chain by bit manipulations.
However, the bitmask was wrong: 0b00111000 is 0x38 not 0x30,
which means that "odd" dive modes were not recognized as such.
Bug found by coverity.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The git save format is designed to be entirely line-based, where all the
dive data is on individual lines that are independent.
That is very much by design, so that you can merge these files
automatically, and not worry about what it does to the context (contrast
this to structured files like JSON or XML, where you have multiple
levels of indentation, and the context of a line matters).
So the parser can just ignore any conflict markers, and parse everything
one line at a time.
Well, almost.
We do have *one* special form of multi-line context, where flowed text
(think things like dive notes) will have one "header line" that starts
the note, and then it can continue for several lines until the final
line that ends the quote.
In such a situation, the dive merging can result in a partially merged
string note, which has the ending line from one dive, and then continues
with more string data from the other dive.
That will confuse our parser mightily, because it will have seen the end
of the string, and parsed the rest of those string comments as garbage lines.
That part in itself is fine - the garbage lines won't pass as any real
data (because they don't start with a proper keyword), but while parsing
that garbage the *next* end of the string will be seen as a start of a
new string.
And *that* then confuses the git parser to think that the line after
that is now part of the string, and so it won't correctly parse the
non-string line that follows.
To give a more concrete example, the git dive data (here indented and
abbreviated) might look like this:
suit "5mm long + 3mm hooded vest"
notes "First boat dive.
Giant-stride entry."
Saw a turtle."
cylinder vol=10.0l description="10.0ℓ" depth=66.019m
where the two notes from the two dives were
notes "First boat dive.
Giant-stride entry"
and
notes "First boat dive.
Saw a turtle."
respectively, and the merged result contained parts of both.
When we parse this, we will parse the 'notes' line as having the string
First boat dive.
Giant-stride entry
which is fine. But then the next line will be that
Saw a turtle."
and now the ending double quote character on that line will be seen as
the beginning of a new string, and the cylinder information on the next
line will then be mixed up. The resulting mess will be ignored, but in
the process the data on the "cylinder" line will basically have been
lost.
There are several ways to deal with this, but this particular fix
depends on the fact that we can recognize stale string continuation
lines: they are either empty (for an empty line), or they start with a
TAB character.
So to solve the problem with the mis-identified end quote, this
recognizes that we're in such a "stale left-over comment line" context,
and will just skip such lines entirely.
That does mean that when you have conflicts in dive note sections due to
having edited the dive concurrently on different machines, you may just
lose some of the edits.
But this way at least you shouldn't lose any other data due to the merge
conflict.
NOTE! We could try to improve on this by instead noticing that a "end of
multi-line string has a continuation entry on the next line", and just
say "ok, that wasn't a real end after all".
But that would be an independent thing anyway - this "ignore stale text
comment lines" logic would be required anyway, in case those stale text
comments ended up somewhere *else* than right after another text line.
So do this more important fix first.
Reported-by: Michael Werle
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
In utc_mkdate() we find the interesting statement
val = timestamp /= 60;
which not only calculates timestamp / 60, but also overwrites
timestamp with the new value. However, timestamp is never used
in the remainder of the function, because the whole point is to
switch to 32-bit types. Thus, replace the division-assignment
by a simple division operator to avoid head-scratching.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The liter symbol is written as 'ℓ'. To allow searching for
that, normalize unicode strings to their base letter. This
corresponds to the 'compatibility' mode.
We might also think about stripping diacritics.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The code works ok falling back to just Perdix and Petrel 2, but
it looks confusing to the user to see an incorrect name in the
connection drop down.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
It's confusing to have the same name refer to two different models.
Unfortunately, that's what Aqualung is doing by simply changing the
model number and serial number, but not the external branding.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
In a sign how few people use these additional properties AND use multiple
dive computers, this took a couple of years to get noticed... but yes, we
do need to merge those properties as well.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
When computing plan variations, deco can get shorter when
staying longer when the last step is actually already at
off gasing depth. FRACTION forces unsiged, so this introduces
a sign aware version of FRACTION that returns a sign character
in addition.
Reported-by: Patrick Naujoks <p.naujoks@me.com>
Signed-off-by: Robert C. Helling <helling@atdotde.de>
This allows having 3m depth grid for metric users.
* All original properties ( named diferently ) were renamed to three_m_based_grid everywhere to be consistent.
* Plus other small changes requested during review.
Signed-off-by: Vlad A. <elf128@gmail.com>
Signed-off-by: Vlad A <elf128@gmail.com>
The Seac importer was getting samples based only on dive number,
which was causing samples from different computers but with the
same dive number to become interleaved.
To correct this, the SQL statement was updated to use the
dive_id to query for samples. The table schema uses dive_id
as a primary key, which will enforce uniqueness.
Additionally, deviceid is hashed from the the device_id string.
Reported-by: David Brebera <david.brebera@gmail.com>
Signed-off-by: Jim Wobser <james.wobser@gmail.com>
The calculation of the deco steps shown in the profile
infobox is somewhat independent of the planner. When
set to imperial units, the distance between deco stops
should be 10ft rather than 3m as 15m is only 49ft.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
The cylinder_with_sensor_sample() function only tests "do we have a mapping to
this cylinder for this sample". It also needs to test if there are any tank
pressure readings for that cylinder.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Arguably every dive should at least have one cylinder, but an imported
dive from divelogs.de might end up without one. Sadly, that breaks
assumptions that we make in the cylinder remapping.
To work around it, force at least on cylinder to be assumed in the merge
code.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
.. at least if the local repository exists and can be opened.
If the local repo cannot be directly opened, we will still try to sync
with the remote first, but this way the *common* git save situation is
that we save locally before we then try to sync with the remote.
That means that if we have network problems, the save will happen before
we possibly hang due to really really slow networking.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
We had various random "free parts of the git info" left-overs from when
we passed down the git repo data ad-hoc. Get rid of it, and replace it
with just doing a 'cleanup_git_info()' that does the final cleanup of it
all.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
That function name was incomprehensible. What did it check? And what
did the return value mean?
So let's rename it to something that actually describes what it does,
and reverse the meaning of the return value while at it.
So now it's called 'remote_repo_uptodate()', and it returns true if the
remote repository branch has the same value as our 'saved_git_id'.
It's still a bit obscure, but at least within the context of the only
user, the code now makes _more_ sense than it used to:
if (remote_repo_uptodate(fileNamePrt.data(), &info)) {
appendTextToLog("Cloud sync shows local cache was current");
but maybe we could come up with even better semantics and naming, and
make it even clearer.
Requested-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
We currently only have one single caller of update_local_repo(), and
instead of that caller checking whether the existing repo is a
directory, just make it open the git repository.
This avoids duplicate error handling and simplifies the code.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Because of the old connect syntax used the incorrect signal names weren't
caught at compile time. To switch to the new syntax we had to make two
functions pure virtual in the WebServices class - let's hope I got that right.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Making this simply depend on Qt5 or Qt6 was short-sighted as work on QtLocation
upstream continues. Instead break this out as its own option.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Just like the rest of the git repo related information, this is already
included in the git_info struct.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
We have this nasty habit of randomly passing down all the different
things that we use to look up the local and remote git repository, and
the information associated with it.
Start collecting the data into a 'struct git_info' instead, so that it
is easier to manage, and easier and more logical to just look up
different parts of the puzzle.
This is a fairly mechanical conversion, but has moved all the basic
information collection to the 'is_git_repository()' function. That
function no longer actually opens the repository (so the 'dry_run'
argument is gone, and instead a successful 'is_git_repository()' is
followed by 'opn_git_repository()' if you actually want the old
non-dry_run semantics.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
It appears to send a first sample with a water temperature of 0 C. If the next
sample contains a more likely water temperature, overwrite the first one.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>