Commit graph

205 commits

Author SHA1 Message Date
Oliver Schwaneberg
eb38a64149 Do not remove seconds from duration input field
This change deals with issue #554.
If you enter a dive duration manually, the cell renderer cuts the seconds
away when the changes are saved. I added the helper "render_seconds_to_string"
as a counterpart to "parseDurationToSeconds". The helper keeps the seconds,
if not null. The rendering of the cell is done at two places in the code,
so I think it is cleaner to add a dedicated method for it.

Signed-off-by: Oliver Schwaneberg <oliver.schwaneberg@gmail.com>
2018-02-04 13:40:02 -08:00
Berthold Stoeger
6a07ccbad2 Use helper function empty_string() instead of manual checks
For code consistency, substitute boolean expressions:
 s && *s     -> !empty_string(s)
 s && s[0]   -> !empty_string(s)
 !s || !*s   ->  empty_string(s)
 !s || !s[0] ->  empty_string(s)

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-11 06:07:13 +01:00
Berthold Stoeger
e85ecdd925 Introduce helper function empty_string()
There are ca. 50 constructs of the kind
  same_string(s, "")
to test for empty or null strings. Replace them by the new helper
function empty_string().

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-11 06:07:13 +01:00
Robert C. Helling
3985a8aa8f Allow to read factor cache concurrently
In a session with the profile I saw that the planner spends
a lot of time waiting to obtain the lock for the factor cache.
Most of the time we are only reading that cache and that
is save to do in parallel (according to the Qt IRC channel).

So we can use a QReadWriteLock instead of a QMutex. This
appears to be quite a performance boost, in particular
for VPM-B

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-12-18 11:29:17 -08:00
Berthold Stoeger
7b88f8301e Elevate "can't write hashes" message from debug to warning level
I never realized that my hashes weren't written, because it only
outputs a debug instead of a warning message.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-18 15:23:12 +01:00
Berthold Stoeger
074ddc0596 Remove function isCloudUrl()
The function isCloudUrl() was only called in one place, parse_file().
But, isCloudUrl() could only return true if the filename was of the
git-repository kind (url[branch]). In such a case, control flow would
never reach the point where isCloudUrl() is called, since
is_git_repository() returns non-NULL and the function returns early.

Therefore, remove this function. Moreover, adapt the affected if-statement
by replacing "str && !strcmp(str, ...)" with the more concise
"same_string(str, ...)".

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-14 17:01:05 +01:00
Berthold Stoeger
ae26875a61 Use the copy_string() helper function in set_filename()
copy_string() does the same as the current code, but in one instead
of four lines. Strictly speaking, it does not exactly the same thing
because the empty string ("") case is handled differently. copy_string()
returns NULL instead of a copy of "", which is probably preferred anyway.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-11 00:17:39 +01:00
Berthold Stoeger
ea0cbba804 Remove second parameter (bool force) in set_filename()
The last force=false case was removed in commit 96d1cc570e.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-11 00:17:39 +01:00
Robert C. Helling
a9ceecc2e3 Run variations calculation in background
but there are still side effects and thus it crashes.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-11-25 20:13:01 +01:00
Berthold Stoeger
6ae16b87d0 Constify strings in pref.h
Make all char * pointers in pref.h const to make it clear that these
strings are not mutable. This meant adding a number of (void *) casts
in calls to free(). Apart from being the right thing to do, this commit
makes the code more consistent, as many of the strings in pref.h were
already const.

While touching core/qthelper.cpp turn three instances of (void*) into
(void *).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-11-18 21:57:33 +01:00
Dirk Hohndel
bcabe6ec9f Add details about key libraries when showing version
Also fixed a spelling error and apparently some whitespace issue.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-11-09 16:21:31 -08:00
Lubomir I. Ivanov
56e755b711 Use lrint() for all degrees_t related rounding
In certain places the '(int)' cast is used, while in other the
llrint() or lrint() functions. Make the conversation from degrees
in the 'double' form to the 'int' degrees_t consistent using lrint().

lrint() is the function which should give the best results,
because it accepts a 'double' and results in a 'long'
even if degrees_t is 'int'. If the truncation from 'long' to 'int'
is discarding some of the precision then the next step
would be to turn degrees_t into a 64bit signed integer type.

Possible fix for #625.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-10-09 13:38:58 +03:00
Robert C. Helling
456e2cec89 Cache all Buehlmann factors
not just the last one.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-08-29 06:49:44 -07:00
Jan Mulder
a072c635bc fix weights rounding
Simplify and fix prestation of weights. Due to the attempt to round
only the grams part (by just adding 50 to it, and truncating
afterwards) a weird effect was introduced. For example, a value
0.98 was presented as 0.10. Just replay the old logic, and see
what happens. Rewrote the logic to a simpler and better one.

fixes: #532

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-08-10 09:13:26 -07:00
Stefan Fuchs
b109b51f7f Translate "more than n days" for surface interval
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-06-23 22:43:39 +09:00
Lubomir I. Ivanov
e7a7bd4de2 qthelper.cpp: leave lbs rounding to QString().arg() with 'f'
The following call in weight_string():
str = QString("%1").arg(lbs, 0, 'f', lbs >= 40.0 ? 0 : 1);

will make values in lbs larger or equal to 40 to have no fractional
part and be rounded to nearest, while values less than 40 will have one
decimal place.

fixes #412

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-11 16:03:38 -07:00
Stefan Fuchs
e6d884cf26 Creation of dive duration string and surface interval string
Update the function to create the dive duration string in a way that
it can be used also in info and stats tab and added some more flexibility.

Changed layout for <1h freedives to "0:05:35" (w/o units) or "5:35min"
(with units and :) or "5min 35sec" (with units with space).

Add a new function to create the surface interval string.

Completely remove old function get_time_string() and get_time_string_s().

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-05-26 15:50:52 -07:00
Miika Turkia
ccf916344b Include some extradata info on Seabear import
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-05-07 21:36:50 -07:00
Dirk Hohndel
d7cf3408e5 Merge branch 'seabear-refactor'
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-05-07 07:52:55 -07:00
Miika Turkia
d851549d9c Remove debug output
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-05-07 16:00:52 +03:00
Miika Turkia
221f67206b Make parsing of Seabear header more robust
This should work even if some header line is missing from some DC.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-05-07 15:53:35 +03:00
Miika Turkia
6e1c00078d Add dive mode support for Seabear import
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-05-07 15:34:27 +03:00
Miika Turkia
cef56c6290 Import dive number from Seabear CSV file
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-05-07 14:19:58 +03:00
Miika Turkia
0dfa448d8c Refactor Seabear import
Moving the GUI independent Seabear import functionality to Subsurface
core. This will allow Robert to call it directly from download from DC.

Tested with H3 against released and daily versions of Subsurface. The
result differs somewhat, but it is actually fixing 2 bugs:
- Temperature was mis-interpreted previously
- Sample interval for a dive with 1 second interval was parsed
  incorrectly

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-05-07 13:53:52 +03:00
Miika Turkia
ab1813a445 Move intdup to qthelper
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-05-07 09:41:27 +03:00
Dirk Hohndel
92d24a2912 Consistently show dive duration based on preferences
We now respect the settings in the preferences and also only show
the duration as minutes and seconds if the dive is a free dive.

Fixes #361
Fixes #362

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-05-06 17:43:32 -07:00
Robert C. Helling
462797396b File selector should filter images we can actually handle.
So better ask Qt about image formats known to it.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-05-06 08:07:16 -07:00
Dirk Hohndel
b368ecd5aa Add SPDX header to remaining core files
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-04-29 13:32:55 -07:00
Stefan Fuchs
c9c9b1b399 Add creation date and Subsurface version to planner output
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-04-06 18:29:11 -07:00
Jeremie Guichard
597539ce39 Fix double to int truncation in C++ code
Wfloat-conversion enabled for C++ part of the code
Fix warnings raised by the flag using lrint

Original issue reported on the mailing list:
The ascent/descent rates are sometimes not what is expected.
E.g. setting the ascent rate to 10m/min results in an actual
ascent rate of 9m/min.
This is due to truncating the ascent rate preference,
then effectively rounding up the time to reach each stop to 2s intervals.
The result being that setting the ascent rate to 10m/min
results in 20s to ascend 3m (9m/min), when it should be exactly 18s.

Reported-by: John Smith <noseygit@hotmail.com>
Reported-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Jeremie Guichard <djebrest@gmail.com>
2017-03-24 09:39:25 -07:00
Jeremie Guichard
406e4287eb Change calls to rint into lrint avoiding conversion warnings
Using gcc option "-Wfloat-conversion" is useful to catch
potential conversion errors (where lrint should be used).
rint returns double and still raises the same warning,
this is why this change updates all rint calls to lrint.
In few places, where input type is a float, corresponding
lrinf is used.

Signed-off-by: Jeremie Guichard <djebrest@gmail.com>
2017-03-08 14:04:17 +07:00
Dirk Hohndel
e9debdf281 Add helper to parse duration text
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-03-04 12:16:49 -08:00
Robert C. Helling
dbd99f706e Many filenames are const strings
So we can use string constants for those

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-02-21 13:14:56 -08:00
Robert C. Helling
dc55ee4a23 Update exif.cpp from upstream
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-02-19 15:29:40 -08:00
Dirk Hohndel
1ab6e7fc8a Prevent crash on Mac when typing comma in GPS coordinates field
Our attempt to skip any white space after the comma causes an ASSERT (strangely
only on Macs).

This closes #158

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-01-14 09:09:58 -08:00
Robert C. Helling
935734100f Rename prefs.deco_mode to prefs.planner_deco_mode
This is to avoid confusion with planner.display_deco_mode.
When accessing the "current deco mode" use the decoMode()
helper function.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-01-06 20:43:23 -08:00
Robert C. Helling
bb4bf639c3 Fix deco_mode confusion
We have two prefernces determining the deco_mode (BUEHLMANN vs VPMB
vs RECREATIONAL): One for the planner (deco_mode) and one for
displaying dives (display_deco_mode). The former is set in the planner
settings while the latter is set in the preferences.

This patch clears up a confusion which of the two to use by introducing
a helper function that selects the correct variable.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-01-06 20:43:23 -08:00
Robert C. Helling
10b8bda662 Fix picture hashing logic for pictures on the web.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2016-12-30 19:43:00 +01:00
Tomaz Canabrava
27b4ef321a Correctly open the resource file
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-12-27 08:27:21 -08:00
Robert C. Helling
3e4ea9e084 Get rid of debug messages
...that managed to sneak in in a previous commit.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-12-26 13:09:05 -08:00
Robert C. Helling
1ab5db3726 Empty image hashes are not valid
I don't know how those arose in the first place, but an
empty QByteArray is never a valid hash value for an image. So
we should not store those in our translation tables and also
get rid of them when loading the tables from disk.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-12-04 05:37:16 +09:00
Dirk Hohndel
f4ca863a91 Correctly pick up the UI language from settings
While Linux can set the locale from the language text, Windows needs the
correct locale value (which makes more sense to use, anyway - that's why
we save it).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-09-22 22:07:42 -07:00
Dirk Hohndel
5fdbc1ffc3 Language preference: once we figure out the locale, remember it
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-09-20 12:40:30 -07:00
Dirk Hohndel
743f73e4a3 Don't look up the setting again
This caused us to do the wrong thing if the setting wasn't set at all.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-09-20 12:38:23 -07:00
Tomaz Canabrava
0a6f6b4382 Settings update: Fix missing groups and Language initialization
There's one function named uiLanguage() that should return
the current uiLanguage() that subsurface is running, but
it actually sets a whole lot of preferences, I think
that the general idea of that function is okay, but it seems
broken for me.

still, I used it to load the correct language from the preferences
since it's what this function is currently doing right now.

Also, a lot of missing groups where added.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-08-27 22:37:15 -07:00
Tomaz Canabrava
9b2404fcb4 Settings update: Move loadPreferences out of qt-helper.cpp
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-08-27 11:40:45 -07:00
Tomaz Canabrava
9299e3c42b Settings update: Correct comment
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-08-27 11:40:44 -07:00
Tomaz Canabrava
ee91002fdb Settings update: Remove unused include and add FIXME comment
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-08-27 11:40:44 -07:00
Miika Turkia
38a2db05c0 Include full year for trip on divelist
Having only the last 2 digits of the year is somewhat confusing as one
can easily think that to be the day. Thus it is more clear to use full
year for the trip header.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-08-10 15:08:04 -07:00
Rick Walsh
b1ed04a7f4 Have divedatapoint store cylinder id instead of gasmix
Determining the correct cylinder index from a known gas mix can be
complicated, but it is trivial to look up the gasmix from the cylinder_t
structure.

It makes sense to remember which cylinder is being used. This simplifies
handling changing a cylinder's gas mix, either directly by the user, or
indirectly in the planner. It also permits tracking of multiple cylinders of
the same mix, e.g. independent twins / sidemount.

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-07-09 12:07:25 -07:00
Rick Walsh
8acbeed555 Add some gas mix validation to the planner
A few basic rules for gas validation:
	We can't have <0%, or >100% of either O2 or He
	O2 + He must not be >100%
	Switch depth can't be <0%

This places limits on user-input values

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-05-28 14:24:10 -07:00
Robert C. Helling
2e6588dc0e Protect access to image hash dictionaries with lock
Otherwise we step on our own feet when downloading several images,
like after import from divelogs.de with many linked images.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-29 09:08:20 -07:00
Linus Torvalds
56ed3f1c61 Fix Qt date interfaces for times before 1970
This seems to work around the crazy QDateTime::fromTime_t() problem in Qt.

It is *very* lightly tested. In fact, the only test is that "test0.xml"
change that is part of this patch.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-29 09:07:41 -07:00
Linus Torvalds
ff8392da54 Remove unused and buggy get_cylinder_used_gas_string() function
It's good that this is unused, because it does the calculations wrong.

Due to the gas compressibility the gas use calculations should subtract
the gas_volume() values at the differing pressures, not the pressures
themselves.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-05 16:52:58 -07:00
Dirk Hohndel
7be962bfc2 Move subsurface-core to core and qt-mobile to mobile-widgets
Having subsurface-core as a directory name really messes with
autocomplete and is obviously redundant. Simmilarly, qt-mobile caused an
autocomplete conflict and also was inconsistent with the desktop-widget
name for the directory containing the "other" UI.

And while cleaning up the resulting change in the path name for include
files, I decided to clean up those even more to make them consistent
overall.

This could have been handled in more commits, but since this requires a
make clean before the build, it seemed more sensible to do it all in one.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-04 22:33:58 -07:00
Renamed from subsurface-core/qthelper.cpp (Browse further)