Commit graph

203 commits

Author SHA1 Message Date
Tomaz Canabrava
f14c14c383 Mark a lot of TODO's where I think it should be moved to C code.
This marks a lot of todo's where I think there's core stuff being mangled
on the interface - we should remove this from the interface to make
testing and maintenability easier.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-17 08:33:51 -07:00
Robert Helling
9ddef367b5 Improvement for various bits of the planner
Rewrite of the actual planner logic. Now ascend to the next potential stop
depth. There the state is cached and we try to ascend to the next stop
depth. If we hit the ceiling while doing that we go back to the cached
state and wait there for a minute. Then we try again. Then loop.

Converted all depth related variables from unsigned int to int. During
planning, in a time step the current depth can temporarily be negative and
comparisons of a negative int with an unsigned it have not the result I
expected ( (int) -2 < (unsigned int) 3 turns out to be false). And we
don’t really need the 32nd bit that unsigned buys us for depths.

Deco stops are now shown in the same table as manually entered stops in
boldface (I removed the second table to save screen estate).

The gas shown in the table is still misleading as it means the gas used on
the segment leading up to that event.

The update of the profile only works partially upon changes in the list of
available gases.

Treatment of various gases is basically there but needs some more love.

The ascent velocity is now provided by a function that takes the current
depth as argument. Currently it always returns 10m/min but that will later
be variable (and hopefully user configurable).

The profile is not redrawn while deco is computed (avoiding an infinite
recursion).

The table got a new column for the duration of a segment while the old
“duration” column was renamed “Runtime” to reflect what it actually shows.
Currently, only the run time but not the duration are editable.

All deco gases are used from the depth where their pO2 is 1.4bar. This
should become more flexible.

Calculation of the pressure drop in cylinders without configured volumes
is suppressed. This solves a problem with the planner crashing when saving
a dive where not all cylinders had been manually given a volume.

[Short rant break: Treating 0/0 as air bites back at so many places. E.g.
Cylinder data is initialized with memsetting the whole structures to 0.
Then later suddenly this totally unconfigured cylinder is being treated as
it would contain air. Maybe at some point this was a feature. But it lead
to a naughty bug which took me over an hour to resolve. We should
seriously reconsider this choice and better move to 209/0 being air if
changing this everywhere is not too much trouble]

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-17 07:29:44 -07:00
Anton Lundin
8bc2ad1473 Enable parts of planner based on define
In bf205726 DEPTH/Switch at was disabled by commenting out that code.
This puts it back behind ifdefs

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-23 17:24:40 -07:00
Dirk Hohndel
36ba353450 Correctly check if tank is in use
We always checked if the tank was in use by the planner / dive editor -
even if we were not in dive edit mode.

With this patch, when not in dive edit mode, we check our cylinder "used"
flag instead.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-15 14:56:32 -07:00
Dirk Hohndel
1b103c5c69 Another small tweak to whitespace tool
clang-format doesn't appear to reindent multi line #define statements
correctly - so this hopefully will clean those up.

The included whitespace corrections to the code should stay in place when
using the updated tool.

This includes cleaning up some multi-line comments that were messed up the
last time around as well as a few other minor changes.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-05 13:02:23 -08:00
Dirk Hohndel
2513410132 Fix possibly uninitialized value
I'm not sure about this one. It's possible that there's something
happening behind the scenes that I don't understand. But let's just
initialize this to 0 and be sure.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-03 22:21:33 -08:00
Dirk Hohndel
76e6420f6b Massive automated whitespace cleanup
I know everyone will hate it.
Go ahead. Complain. Call me names.
At least now things are consistent and reproducible.
If you want changes, have your complaint come with a patch to
scripts/whitespace.pl so that we can automate it.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-27 20:09:57 -08:00
Boris Barbulovski
c86822c2f4 Replace mainWindow() with MainWindow::instance()
C++ style of accessing single instance class object.

Signed-off-by: Boris Barbulovski <bbarbulovski@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-12 11:42:59 -08:00
Dirk Hohndel
6332976c3d Whitespace and dead code cleanup
The coding style for switch isn't the prettiest, but let's at least keep
things consistent.

Also, those ugly break statements never got reached, anyway.

And there was no need to re-declare and re-generate currentString.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-12 06:22:10 -08:00
Boris Barbulovski
a3d82bf9b1 Update #include statement for QStringListModel
Signed-off-by: Boris Barbulovski <bbarbulovski@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-11 12:36:53 -08:00
Dirk Hohndel
bf20572630 Disable the switching depth column for cylinders
Since the planner is disabled this column isn't needed.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-26 07:37:11 -08:00
Boris Barbulovski
6cc65f5e1c Fix some memory leaks.
Memory leaks were caused by broken parent/child relations.

Signed-off-by: Boris Barbulovski <bbarbulovski@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-16 12:15:47 +07:00
Dirk Hohndel
a27f67c026 Whitespace and coding style updates
Another futile attempt to cleanup the code and make coding style and
whitespace consistent. I tried to add a file that describes the key points
of our coding style. I have no illusions that this will help the least
bit...

This commit should ONLY change whitespace

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-16 11:50:56 +07:00
Dirk Hohndel
630eece8b2 Fix "hide unused cylinder" behavior
There are at least two scenarios where our old code was flat out wrong.
If you manually add a cylinder (because you may want to switch to it in
the profile), then at least until the next time you restart Subsurface
this cylinder should be shown.

Also, when you switch to a cylinder by adding a gas switch event on the
profile, that change should then make that cylinder visible.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-15 16:40:40 +07:00
Anton Lundin
781b99170c In Qt5 reset() is depricated.
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-15 15:52:51 +07:00
Anton Lundin
7e9582631d Convert to TRUE/FALSE to stdbools true/false
I had problems with this one on Qt5.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-15 15:52:31 +07:00
Dirk Hohndel
23973e8abd Don't show tanks that aren't used during a dive
Some dive computers will always download all tanks that they store, not
just the ones used in a dive. Most people only want to see the tanks that
they actually used during the dive (and for the others there's an option
to go back to the old behavior, just in case).

All this is only in memory / during runtime. If the dive computer provided
the extra data we will not throw it away.

Fixes #373

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-11 22:02:35 +07:00
Linus Torvalds
7ba167e1b3 Remove now stale arguments to "CHANGED()" macro
We now never remove units or percentage signs, and always just compare
the string data, so we should remove the hacky arguments that are no
longer used.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-09 15:51:21 +08:00
Linus Torvalds
1d2238b110 Add and use 'string_to_fraction()' helper converter function
This matches the pattern of unit conversion, and will allow us to remove
all the code that uses the old complex "CHANGED()" macro that tries to
remove units or percent signs.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-09 15:51:18 +08:00
Linus Torvalds
4f982c1758 Add unit-aware cylinder size string parserc
Whittling down on the string parsing that doesn't check user-specified
units.  Still need to handle temperatures (and will do percentages to
match the pattern too), but this is getting us closer to always honoring
user-specified units.

With this you can say that you have a "10l" cylinder at "3000psi", and
it will do the right thing (it's basically a 72 cuft cylinder in
imperial measurements).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-09 15:51:03 +08:00
Linus Torvalds
9c06938adc Add unit-aware conversion of pressure data
This just adds (and uses) a string_to_pressure() to parse pressure units
correctly when filling in cylinder pressures.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-09 09:10:29 +08:00
Linus Torvalds
cc33ff2fe2 Add a string_to_depth() helper function to match our string_to_weight one
It's currently only used for the setting of the cylinder switching
depth, but now that one should work with user-specified units (so you
can set a max depth in feet even if you use metric, and vice versa).

In the future, if we also make the unit preferences something you can
pass in (with user preferences as a default argument value), we might
want to use this for parsing the XML too, so that we'd honor explicit
units in the XML strings.  But the XML input unit preferences are not
necessarily at all the same as the user preferences, so that does
require us to extend the conversion functions to do possibly explicit
unit preference selection.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-08 16:38:52 +08:00
Linus Torvalds
2d1d78ebfe const'ify our strtod() helper functions
The C library doesn't use const char pointers for legacy reasons (and
because you *can* modify the string the end pointer points to), but
let's do it in our internal implementation just because it's a nice
guarantee to have.

We actually used to have a non-const end pointer and replace a decimal
comma with a decimal dot, but that was because we didn't have the fancy
"allow commas" flags.  So by using our own strtod_flags() function, we
can now keep all the strings we parse read-only rather than modify them
as we parse them.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-08 16:38:47 +08:00
Linus Torvalds
19b982d3df Make 'string_to_grams()' use proper type safe types
Make it use 'weight_t' and hide the "grams" part inside the type.  That
was the whole point of the weight_t type, after all.  Returning a
"double" was always bogus, since we internally always do integer grams
(and the function actually used "rint()" to get all the rounding right
anyway).

As a result, it's now called "string_to_weight()".

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-08 16:38:43 +08:00
Dirk Hohndel
409c2e9bcf Not everything can be done with the diveId
In commit c3fe1a9e9f ("Get rid of pointers to dive structures in the
UI") I was a bit too aggressive moving away from pointers to dives.

This is only needed for pointers that are held across operations that
could change the dive_table. I figured that it wouldn't hurt to get rid of
some more pointers as well, but it turns out I was wrong. The current dive
that we store in the Cylinder and Weight models can be a dive that isn't
in the dive_table at all: the multiEditEquipmentPlaceholder. And when
using the diveId we end up finding the original dive in the dive_table and
therefore modify the wrong structure.

This undoes two thirds of the above mentioned commit.

Reported-and-analyzed-by: Patrick Valsecchi <patrick@thus.ch>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-07 22:10:41 +08:00
Dirk Hohndel
a8db19f548 Restructure overly agressive Q_ASSERT
Turns out this function can be called when there is no valid dive - so
only protect those parts that dereference the dive.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-07 12:22:22 +08:00
Dirk Hohndel
c3fe1a9e9f Get rid of pointers to dive structures in the UI
The assumption that the pointer will keep pointing to a valid structure is
fundamentally flawed. And even if that is true today, it might change in
the future - just don't do it. Use the diveId instead.

The exception is when you own the structure and use it within one UI
interaction during which any way to change the dive_table is disabled
(e.g., while adding / editing a dive).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-07 12:10:19 +08:00
Dirk Hohndel
32d26b751a Parse localized weight units
We have the wonderful Qt string functions. Let's use them to make the code
simpler and easier to read.

Suggested-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-03 11:22:37 -08:00
Linus Torvalds
4cce5df7e2 Fix imperial cylinder sizes in equipment tab
The imperial cylinder sizes are not just in cubic feet: they are in
cubic feet of gas at STP. So the imperial/metric difference is not
just about converting blindly from liters to cubic feet, you also have
to take the working pressure of the cylinder into account.

This was broken by commit f9b7c5dfe9 ("Make units in cells
consistant in CylindersModel"), because those poor sheltered Swedish
people have never had to work with the wondrous imperial cylinder
sizing, and think that units should make _sense_. Hah.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-02 22:40:50 -08:00
Linus Torvalds
c49d3885f5 Allow the user to specify weight units explicitly
Instead of always assuming that all numbers are in the users locale
weight units, allow the user to say "kg" or "lbs" explicitly.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-02 21:17:51 -08:00
Dirk Hohndel
5511a0e14e Ignore units when entering values for equipment
Note that this is IMHO the wrong fix. Because we shouldn't just ignore the
units, we should do correct conversions.

Before this patch, if the user is in metric mode and then types in 4.5kg
or 10lbs for a weight, Subsurface ignores the entry and throws it away.
Very much not the expected behavior.

With this patch Subsurface will take the value, but ignore the unit and
assume that the user meant kg (since it's in metric mode). Still not
really the expected behavior for 10lbs (which is now 10kg), but if the
user typed 4.5kg (which admittedly is much more likely), then with this
change Subsurface will do the right thing.

Fixes #395

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-02 09:12:32 -08:00
Tomaz Canabrava
c5c44e3a82 Kill the use of CSS - Fixes a Lot of issues on dark color schemes.
The css was done by me in the first days of subsurface for Qt, and it
was a code that I was never proud of. Mostly because I tougth at the
time that it was better to write it into CSS than to create a new class
just to take care of the size of the default cell height on a tree view.

Now I see that it was a biased approach since it created issues on
dark color schemes and it also didn't make a 'native' experience on
Gnome or OSX, only on KDE.

This fixes that.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-12 03:26:39 +01:00
Sergey Starosek
4623d7098b Build language list from Subsurface translations
On Windows platform translation/ folder contains Qt translation
files as well. This results in extra languages in preferences.
From now we filter these translations and choose only those matching
^subsurface_*.qm$

Fixes #339

Signed-off-by: Sergey Starosek <sergey.starosek@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-07 12:06:33 -08:00
Sergey Starosek
482214703b Language chooser improvements
Show language instead of country, sort the list.
Show country in brackets to avoid ambiguity for locales like
de_DE and de_CH.

Signed-off-by: Sergey Starosek <sergey.starosek@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-07 08:09:05 -08:00
Anton Lundin
f9b7c5dfe9 Make units in cells consistant in CylindersModel
Now they all have units in the cells.

Fixes #259

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-07 07:39:12 -08:00
Tomaz Canabrava
61d5aac2e8 Do not change the current Directory
Qt has a really strange API for directories. when you create a QDir
and set's the currentDir on *that* QDir you created, it's for the
whole application and not just for that variable. Then when the
variable is out of scope, the directory doesn't change back - ugh.

The solution is not to call setCurrentDir on the newly created QDir (which
was quite good since it's also a code cleanup. )

[Dirk Hohndel: modified to undo the far less elegant fix I had made in an
               earlier commit]

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-06 13:21:24 -08:00
Dirk Hohndel
e015effb47 Don't change working directory when looking for tranlations
And only replace 'bin' if there is a bin in the path...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-06 12:03:12 -08:00
Tomaz Canabrava
9b7b477d7c Added 'English' and 'Use System Default' options.
These complete the ability to select languages from the preferences panel.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-06 11:58:29 -08:00
Tomaz Canabrava
4e263bae98 Added a language preference to the Settings.
When the user first opens the application the default language is
selected; this can be changed to a hardcoded one by going to system
preferences and choosing the one you want.

Restart required.

Fixes #136

[Dirk Hohndel: whitespace fixes, removed qDebug() call, rephrased the
               message displayed prompting the user to restart.]
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-06 09:49:05 -08:00
Lubomir I. Ivanov
bfe5ccda1c Print: add a safe-guard if table print rows are too big
We do not support rows larger than a single page as the
PrintLayout algorithm will enter an infinite loop,
therefore we put a limit of 15 lines for the location text.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-06 09:35:09 -08:00
Henrik Brautaset Aronsen
9b51901f35 Text cleanup to amend lacking consistency
- Removed the "Visible:" header on the column selector.  It doesn't
  have to be there, and it's not in the similar equipment column selector
- PO2 --> pO₂ (and others)
- Use same initial case in the units selector in preferences

Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-03 13:01:14 -08:00
Dirk Hohndel
43630cabd6 Don't store translated standard weight system names
For the names that we have in our "default set" we need to store the
English name so Subsurface will "do the right thing" when opening the file
in a different locale.

With manually entered names in a local language there's not much we can
do.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-02 12:41:23 -08:00
Anton Lundin
6294c6b14b Remove unused variable
Leftover from previous code that called get_gas_string

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-02 12:33:38 -08:00
Dirk Hohndel
768cab66cc Third time's a charm: translating weight system description
Still trying to fix the same issue that I already tried to address in
commit e0b70b82ca ("Fix translation of weightsystem names") and before
in commit dc03b7e7d6 ("We need the correct context to translate event
names").

I missed the WeightModel. Hopefully this was indeed the real fix.

Fixes #312

(I know, I keep saying that)

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-02 10:19:59 -08:00
Dirk Hohndel
e0b70b82ca Fix translation of weightsystem names
This is very much the same as in commit dc03b7e7d6 ("We need the correct
context to translate event names"). I didn't pay enough attention when
reading the bug report and missed that the weight system names were also
not correctly translated.

Fixes #312

(I hope this time for real)

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-02 07:36:40 -08:00
Thiago Macieira
b22f1da59e Fix all leak-at-exit from singletons in Subsurface
Subsurface creates a lot of singleton instances on demand, but nothing
ever deleted them. Since they are singletons, these memory allocations
are technically not leaks. However, they clutter the output in valgrind
and other memory analysers, hiding the real issues.

The solution is to delete these items at exit. For the models and for
gettextFromC, the solution is to use a QScopedPointer, which will delete
its payload when it gets destroyed. For the dialogs and other widgets,
we can't do that: they need to be deleted before QApplication exits, so
we just set the parent in all of them to the main window.

Signed-off-by: Thiago Macieira <thiago@macieira.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-30 09:28:42 -08:00
Lubomir I. Ivanov
22e0323d6a Print: fix wrong Max. CNS / SAC columns
Swap the places of the CNS and SAC values in the profile tables.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2013-11-30 19:10:47 +02:00
Dirk Hohndel
a268311a0b Merge branch 'print' of github.com:neolit123/subsurface 2013-11-30 07:55:58 -08:00
Miika Turkia
5a1a25a476 Fix a crash when no trip exists
When there are no trips at all, we have to skip the Yearly statistics
alltogether, including the header line (that should display all the
dives added together).

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-30 07:46:17 -08:00
Lubomir I. Ivanov
d4766a8cce Print: yet another font adjustment for the profile table
We now only use a slightly large font for the "Dive #" entry.
All other font sizes remain at 9px.

Another change is that we now attempt to use 11px for
individual row height. This makes the table at least 12px bigger
(n_rows * increment), but does not cut letters like 'g',
which go slightly bellow the font baseline.

Perhaps this can be improved later by adjusting the font
and row sizes again.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2013-11-30 17:37:27 +02:00