Commit graph

189 commits

Author SHA1 Message Date
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
Henrik Brautaset Aronsen
10a43af066 Minor text cleanup
Use the same case for the first letter in the dive table column headers,
use '%' for both gases in the planner, and show "Start time" instead of
"Starttime".

Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-30 07:19:48 -08:00
Lubomir I. Ivanov
d439d381ca Print: update the values for DM, buddy, suit, etc
We update the values for divemaster, buddy and etc...
Rating and visibility are currently displayed as "x / 5"
values.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2013-11-30 17:12:08 +02:00
Lubomir I. Ivanov
156815f041 Print: update printing for gas, CNS, SAC and weights
Following the new layout for the profile print, we separate
the used gas like so:
AL80 / EAN33 / ...

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2013-11-30 16:51:28 +02:00
Lubomir I. Ivanov
35f1f716a5 Print: add more table headings for Divemaster, Buddy, etc..
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2013-11-30 16:23:19 +02:00
Lubomir I. Ivanov
ab8e781660 Print: set correct row/column location for profile notes
NOTE: also comment out the old cylinder/weight printing code...

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2013-11-30 16:10:48 +02:00
Lubomir I. Ivanov
19b68d38ac Print: update the profile print table Gas, SAC, CNS titles
This only updates the titles to correct column offsets.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2013-11-30 16:03:46 +02:00
Lubomir I. Ivanov
89ba9b113d Print: remove the helper function to truncate strings
ProfilePrintPmode::truncateString() was not really needed,
because long text *should* be trunctated by the table itself.
Also we now are going to have multiple lines for notes,
so the auto-trim should work.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2013-11-30 15:46:13 +02:00
Lubomir I. Ivanov
a60475d336 Print: adjustments to font sizes and alignment
The new profile table requires different alignment and
different font sizes for specific cells.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2013-11-30 15:41:18 +02:00
Lubomir I. Ivanov
3b7500fd33 Print: setup for a new profile table layout
- Adjust the new rows and column count
- Set new row and column spans

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2013-11-30 15:32:14 +02:00
Dirk Hohndel
adf6d1e22d Units should be lower case
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-29 10:20:10 -08:00
Anton Lundin
57fb878b41 Show/save weights up to and including last valid
Previous show and save code would have aborted at the first invalid
weight system. This makes sure we save and show all weight systems up
until and including the last valid.

If we had:
integrated: 1kg
belt: 2kg
ankle: 3kg

And changed belt to 0 kg, we would have only saved integrated 1kg, and
nothing about the belt or the ankle weights. This will save all of them,
and show all of them.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-27 14:13:47 -08:00
Anton Lundin
ab4115791b Show cylinders up to and including the last valid
Previous code aborted at the first invalid cylinder. This instead finds
the last valid and prints all the ones up until that one.

Fixes #295

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-27 14:13:02 -08:00
Miika Turkia
ce525bd285 Adding trip based statistics
This adds trip based statistics to the Yearly Statistics
view.

Signed-off-by: Miika Turkia <miika.turkia@nixu.fi>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-23 22:07:18 -08:00
Tomaz Canabrava
7ed2fde778 Small code cleanup on the CylindersModel
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-22 07:35:03 -08:00