Commit graph

199 commits

Author SHA1 Message Date
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
Tomaz Canabrava
cdac737925 Better positioning of the text on Weightsystems table.
Same as the cylinder, but for weightsystem.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-22 07:34:45 -08:00
Tomaz Canabrava
bc461d091c Added a bunch of tooltips where I thought it was sane.
I think we should actually fill the app with tooltips and
whatsthis hints. justsain ;p

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-22 07:34:24 -08:00
Tomaz Canabrava
cee021ddd3 Better positioning of the text on the table cells.
Better positioning of the text on the table cells. On KDE systems the
text got too near the line that divided the cells, this way the text is
placed on the middle of the cell.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-22 07:33:49 -08:00
Dirk Hohndel
995192c5fb Work around QMessageBox not showing its title on Mac
This is a bit hacky and simply adds the title to the message text when
compiling on a Mac, but hopefully this will be enough.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-21 04:23:10 -08:00
Anton Lundin
8aadd4d372 Quiet down warning about return in non-void
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-21 03:35:02 -08:00
Dirk Hohndel
0d512b2dd9 Small whitespace cleanup
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-19 18:17:50 -08:00
Dirk Hohndel
6acff53735 Fix trip summary line in dive list
Two errors fixed.

- With no location set, the summary line would start with a ','.
- When auto creating a trip for a manually added dive or when editing the
  dates of dives in a trip, the timestamp for the trip was not updated
  after editing the dive.

Fixes #293

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-19 14:20:18 -08:00
Dirk Hohndel
1a5e94006c Sanity check on gas percentages
O2 + He + N2 = 100%
(well, there are some other gases, but this is close enough)

Since N2 can't be negative that means we should refuse any change where
O2 + He > 100% (or o2.permille + he.permille > 1000).

Fixes #280

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-19 05:02:08 -08:00
Tomaz Canabrava
66fdd9bc91 Do not let the dive have the 0 value.
The number 0 means "this dive has not been numbered". So manually
assigning this seems wrong.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-18 16:54:59 -08:00
Tomaz Canabrava
61ac0a7c8d Make it posible to renumber dives.
If the user doubleclicks on the number of the dive in the dive list,
this will present to him a dialog to change that number. Pressing enter
will renumber the dive if there's no dive with the same number already.

Fixes #288

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-18 16:53:16 -08:00
Tomaz Canabrava
4f9526ef81 Fix wrong handling of Dive Table, and revert some wrong changes.
This patch just reverts some wrong changes that I'v done on a
past commit ( sorry ) and correctly handles the selectDive,
by using a IDX instead of the dive pointer, as dirk told me
it's extremely error-prone since the pointer can change.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-16 20:19:55 -08:00
Tomaz Canabrava
8827ea6f5d This moves the removal code to the model.
It's very important when programming via Model/View, in gtk or qt,
to not mess with the model data outside of the model. We were
deleting stuff that the model controlled outside of the model, so
it thought that there was still data there. This fixes the deletion
part, but there are also lots of other parts that I'll tackle in
the next commits.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-15 15:13:53 -08:00
Tomaz Canabrava
a07c3d62af Use the correct font for the Air Types Model.
The air types model had a font bigger than the
other models, this patch creates a data() method
that correctly delivers the correct font.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-15 09:21:05 +09:00
Tomaz Canabrava
96d5687ab8 Correctly handle changes on the CylinderModel to update the AirModel.
What happened before was that the AirTypes model was only being updated
when the user requested to change the air by clicking directly
on the Air, in the planner ( but not on the Air Table. ).

This fixes it by calling 'repopulate' whenever the cylinder model
changes ( by adding, removing and changing something.)

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-15 09:19:14 +09:00
Tomaz Canabrava
9f8577a5ea Fix edition of alphanumeric input on equipments.
This patch fixes the edition of alphanumeric input,
columns like depth accepted '23ft', '20m' or '30', with
an inplicit conversion to the unit. But the code ignored
that the input could have a 'ft' or 'm' ( ot anything else
for that matter.

Signed-off-by: Taiane Ramos <exhora.tat@gmail.com>
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-14 21:24:48 +09:00
Dirk Hohndel
d7fb6853a3 Connect changes in the tanks with the dive that is being added
- you can no longer delete a tank when its gas is in use
- therefore you can no longer delete the last tank
- when you change the gas mix of a tank, the corresponding segments in the
  dive change as well
- when changing gas for a segment the correct available gases are offered

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-13 21:56:22 +09:00
Dirk Hohndel
83a7f1f5b4 Use existing helper function
And remove spurious extra ';'

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-12 16:33:01 +09:00
Dirk Hohndel
d72c69db7a Add depth colum to cylinder model
To make the planner work this adds a new column to the Cylinder widget
(depth - for the depth at which we want to change to a certain gas
during deco).

This also tries to hide that column in the equipment view and hide the
start/end pressure columns in the planner view. Oddly that fails :-(

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-12 11:17:40 +09:00
Dirk Hohndel
ea2e517e39 Fix crash when cancelling dive add on empty dive list
Don't pass NULL dives around.

Fixes #231

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-11 05:55:20 +09:00
Dirk Hohndel
aa4931e8c6 Show a cylinder widget in the dive planner
This is intended to allow the user to provide the gases / cylinders that
she will be diving with. With that information the planner can warn the
user about insufficient gases, but more importantly it can show relevant
gases in the gas select drop down.

Right now the add cylinder button doesn't add a cylinder - that's a
problem.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-10 07:07:59 +09:00
Lubomir I. Ivanov
861b524e7a Helpers: move some date related function to qt-gui.cpp
divelist.c:
get_dive_date_string()
get_short_dive_date_string()
get_trip_date_string()

MinGW support for *printf and parameter positions (e.g. %1$d)
is horribly broken. Instead of implementing *proper* support
for this feature Microsoft decide to ignore the standard (again)
and they implement new functions with the '_p' suffix,
such as 'sprintf_p', which seem to be available from a 2003 runtime.
To top that 'sprintf_p' is not really a 'sprintf' but rather
a 'snprintf'.

It seems that the MinGW people ignore the issue and do not provide
wrappers of any sort, or at least for the current recommended compiler
for Qt 4.8.5 on Windows - which is a 4.4.0. A note of warning;
inspecting how MinGW does certain things in headers such as stdio.h,
can ensue bad dreams or other negative effects on to the viewer.

This forces us to move the following functions from the 'back-end'
(divelist.c) to the 'front-end' (qt-gui.cpp) and use QString.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-16 15:04:44 -07:00
Robert Helling
c59d594e00 Printing adjustments
Add units to the SAC in the print-out, reduce max depth in metric to one
decimal place, and leave some more characters of the notes to be printed..

Signed-off-by: Robert C. Helling <helling@atdotde.de
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-15 10:34:40 -07:00
Lubomir I. Ivanov
88b1e09dee printlayout.cpp: Increase the font size in tables bellow profile
Because of varying font (screen) DPI we use pixel sized fonts
when printing. Apparently 8px does not look that good on Windows
default fonts, but kinda OK on Linux. We compensate by
increasing the font size and table rows to 9px.

Also decrease the padding between the table and profile to 5px.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-15 04:23:56 -07:00
Lubomir I. Ivanov
a2a93ff04b Models: fix two potential crashes
CylinderModels::setDive() and WeightModel::setDive() have
potential to pass the 'last' argument to beginInsertRows() as
a negative number which triggers an assert that 'last' cannot
be smaller than 'first'.

Patch attempts to fix that by only calling beginInsertRows()
when there is at least one row to insert.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-13 11:31:25 -07:00
Tim Wootton
a014fb1099 Adds missing "EndPress" column header for cylinder table
The end pressure was appearing in the column headed "O2"

Signed-off-by: Tim Wootton <tim@tee-jay.demon.co.uk>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-13 11:30:56 -07:00
Tomaz Canabrava
beb40ae494 Finish clearing up the TableModels
There are other models ( Tree Models and Model Items
) that are not affected by this commits, this is
already a good cleanup but it can be extended
to also fix those two other possibilities.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-10-11 11:42:33 -03:00
Tomaz Canabrava
fac316865c Another Model Cleanup
Conversion of the WSInfoModel, that populates the list
of weigthsystems in the Equipment tab.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-10-11 11:13:16 -03:00
Tomaz Canabrava
a4efa8c444 Second model converted to be less boilerplated.
Second model converted to be less boilerplated,
there are right now 7 models that will need to
be ported. each model can remove around 30 to 40
LOC, so this is not such a bigger improvement,
but it's an 'keeping an eye on the future'.

Also fixed a bug where the returned value was dummy.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-10-11 11:04:27 -03:00
Tomaz Canabrava
26c87fafc2 Begin to Cleanup the Models, trying to reduce boilerplate.
The Model View system in Qt is *very* verbose, this is the
beginning of a series of patches that will concentrate
the boilerplate somewhere and reduce the amount of lines
and will also try to make the code cleaner and easyer to
understand,

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-10-11 10:50:40 -03:00
Tomaz Canabrava
1b9a4f2bf8 Good deal of whitespace fixes and code cleanup.
I just went thru all of subsurface code removing
some whitespaces issues and trying to make the
code prettyer, I also removed a few QString issues.d

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-10-11 10:21:04 -03:00
Benjamin
ae713763c7 Add a helper function to calculate weight display string
Add a helper function to unify the calculation of the
weight display string, instead of having the same calculation
in two places in the code.

Signed-off-by: Benjamin Fogel <nystire@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-04 11:57:28 -07:00
Benjamin
9961cf13b1 Use the same conversion grams->lbs in dive and equipment list
Subsurface stores weight values in grams. When displaying lbs,
the dive list was not rounding the converted weights up, but
rather truncating the value at the decimal place. The equipment
list was rounding the converted weights up. This gave two
different displayed values for the same weight value.

Signed-off-by: Benjamin Fogel <nystire@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-04 09:40:05 -07:00
Lubomir I. Ivanov
e727b899a6 Print: provide means to print profile tables
This patch adds a couple of classes and some other modifications
in PrintLayout that handle the printing of tables under a profile.

models.h : ProfilePrintModel
The class uses a 'struct *dive' to output all required data
for a certain dive at specific rows and columns. It also handles
font formatting and text alignment.

modeldelagatates.h : ProfilePrintDelegate
The class is used only for drawing a custom grid for profile tables.

PrintLayout::createProfileTable()
The function is used to create and setup the profile table object

PrintLayout::printProfileDives()
The function now has correct padding of dive profiles on a page
and also the printing of actual tables below them.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-03 09:38:37 -07:00
Tomaz Canabrava
94c8f64316 Only mark dive list as changed if 'Accepted' was clicked.
The old code marked the dive list as changed on any
of the changes in the model, this was incorrect since
the user could just cancel the edition, wich means
that the divelist shouldn't be marked as changed at all.

when the user clicks on'accept', and the item is indeed
changed on the dive list, then we mark_divelist_changed
to TRUE

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-09-25 14:30:03 -03:00
Tomaz Canabrava
2c14f3aa3b Added a 'changed' member on Cylinder/Weigth models to know when to Apply a change.
Added a 'changed' member on Cylinders and weigth models to mark when
one was changed or not. Only the changed data should be inserted on
the selected dives, so if the user changes the cylinders on a multi
edit, there's no need ( and it will actually break things if we did that )
set the weigths too.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-09-25 14:23:51 -03:00
Dirk Hohndel
f5b33dede3 Fix row counting bug
When updating the weight system model we have to remove the old ones and
then correctly count the new ones.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-09-10 14:55:30 -07:00
Dirk Hohndel
e7fd45c7ef Change ws_info and tank_info types
This is correct C. But debuggers in C++ mode are broken and can't display
the global variables. While I hate having to do this change, I hate not
being able to debug my software because of broken tools even more.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-09-10 11:44:49 -07:00
Dirk Hohndel
e91ac60f49 Fill ws_info structure and use it when entering weight systems
The code to initialize the weight systems from the last datafile loaded
had not been brought over from the Gtk version.

We now correctly update the data structure when loading file (but not yet
when editing values).

Most likely the same needs to be done for the tanks as well.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-09-10 11:42:26 -07:00
Lubomir I. Ivanov
e5b18db802 Print: improve table printing by using QTableView
The current QTextDocument implementation is slow due to
HTML parsing. By using QTableView with QAbstractTableModel
we boost the performance of the table print drastically.
This patch completely replaces the old solution.

There is a hidden QTableView widget which is populated
with all data and rendered using a QPainter attached to
the printer device.

A couple of new classes are added in models.h/cpp
that handle the table print model and these are then used
in printlayout.h/cpp.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-08-05 06:59:19 +02:00
Tomaz Canabrava
8ad7216e70 Fixes incorrect editing policies.
The Working Press didn't correctly updated when there was a 'bar'
or 'psi' in the string ( and that was defalt behaviour );

The o2 didn't correctly updated when there was a '%' on the string
(and that was default behaviour ),

The He didn't correctly updated when there was a '%' on the string,
and that was also default behavior.

Now all of them correctly updates.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-07-18 12:01:48 -07:00
Tomaz Canabrava
3aa55462dc Added the code to revert Weigths when user cancels edition
This is a follow up commit to the previous one that
enabled cancel for cylinders, everything in the commit
log for the cylinders also applyes here.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-07-18 12:01:48 -07:00
Tomaz Canabrava
7e029980b8 'Cancel' action Cancels editing Cylinders.
Made the default 'Cancel' action correctly cancel
the cylinder edition. This is needed only because
we bypassed the default behavior on Qt that took
care of this, because we wanted to have more control
on how the view would update the items accordingly
with wich one of the cylinders were selected
on the edition pane - the pressure and size of the
cylinders needed to have it's data set, but the Qt
Model/View system *thinks* that cancel-edition is
simply 'do not commit the edition data, then.' wich
would not work with us, because we passed the strange
data already. So, I created a backup data that serves
us very well. When the user cancels, this backup data
is added back on the cylinder, making everything as
it was before.

[Dirk Hohndel: removed the inadvertendly added boost header]

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-07-18 12:01:05 -07:00
Tomaz Canabrava
1a0a4b7e08 Fixes the Combobox behavior on the inline-edit
This patch fixes the combobox behavior on the inline edit
to what it was ( well, similar to ) the GTK version,
up and arrow keys will walk you to the list of choices,
and it will update the other data as soon as you walks over it

one drawback is that you cant ( for now, since I do have a
very big headache at the moment ) cancel, since the cancel
will just forgets the item and do not call 'setData' on the
model, but we already called it while walking on the list.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-07-16 19:13:58 -03:00
Lubomir I. Ivanov
127cd21137 Models: add the DiveItem::displayDate() helper
Add this helper so that we can easily wrap the required
memory release after calling get_dive_date_string()
(fixes a small memory leak).

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2013-07-11 12:41:50 +03:00
Lubomir I. Ivanov
adb7dc6fac Models: move the declaration of DiveItem to the header
This should allow external use of the type by
including models.h.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2013-07-11 12:40:08 +03:00
Linus Torvalds
5ce5b05521 Qt: Implement trip merging logic
So during my Maui trip, I had a short hiatus in diving, causing
subsurface to start a new trip for the last day of diving.  I could have
just started the old gtk branch to fix it up, but decided that I might
as well try to implement the "merge trip" logic in the Qt branch instead.

This is the end result of that.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-07-04 23:00:12 -07:00
Linus Torvalds
09ee8ece5c Show sample pressures in the cylinder equipment page
If we don't have any manually set pressure data, show the data from the
samples instead.  It uses an italic font for this case, mainly because I
couldn't figure out how to gray things out.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-06-19 21:53:34 -07:00
Linus Torvalds
bc24b9320f Don't show '0.0%' gas percentages
It's just distracting.  Leave it empty.  No helium should be visually
very different from actual trimix, and for oxygen, zero means something
different anyway (it's air).  In neither case is '0.0%' a good string to
show, just show it as empty.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-06-19 21:52:58 -07:00
Linus Torvalds
45d9ca09de Fix the imperial cylinder size calculations in equipment handling
This makes us use the same linear calculations as we did in the Gtk
branch.  We don't take compressibility into account, since tank
manufacturers don't seem to either.  A Luxfer AL80 is 11.1 liters, and
with the standard (non-compressibility) calculations, 80 cuft of air at
3000 psi is 11.094 liter, so that is the right model to use.

Also, stop with the horrible "units in edited numbers" stuff.  It uses
up precious space, and doesn't look any better.  If the user asked for
cuft, give him cuft without making a big deal about it.

Oh, and if the working pressure doesn't exist, sizes are always in
liters.  That's what we did in the Gtk branch, that's what we do here.
Again, no reason to even bother stating units, it's not helping.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-06-19 21:40:38 -07:00
Linus Torvalds
02f2768148 O2/He percentages aren't integral
We do gas mixes in permille, not in percent.  Some people really like
using the value they got from the analyzer, which is generally something
like 29.4% or whatever.  So don't truncate percentages to integers.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-06-19 21:39:12 -07:00
Dirk Hohndel
77725ecfe9 Replace wet_volume calculation with straight forward pressure formula
Since no one else approximates gas volumes at higher pressures, we
shouldn't do that either when converting imperial tank names (cuft @
working pressure) into wet volumes.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-06-19 14:36:48 -07:00
Dirk Hohndel
88f0f60439 Fix cylinder data O2/He percentage entry braindamage
I can't even begin to explain what got me to write this in the first
place. It makes no sense from any angle I look at it...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-06-19 13:46:00 -07:00
Dirk Hohndel
138a00bd10 Improve readability of yearly statistics
Make the entries for years bold, keep the months non-bold.
It's still a sea of data, but this is an improvement.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-06-19 10:31:01 -07:00
Dirk Hohndel
0a92052765 Fix yearly statistics
This commit fixes two issues. One is that there were situations where
the code would read an uninitialized parent pointer, the second was that
instead of the monthly statistics the tree view would show the yearly
statistics again under the yearly entries.

I assume that the second part of the fix (initializing the parent
pointers) actually takes care of both of them (that patch was suggested
by Tomaz), but the first part that just makes sure the pointer is at
least initialized to NULL seems to be at least not harmful, so I kept it
as well.

With this the yearly / monthly statistics seem to be pretty much at
feature parity.

Fixes: #115

Suggested-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-06-18 13:31:12 -07:00
Dirk Hohndel
370673cc99 Improve display of yearly statistics
Display the units in the header, make the header more consistent
looking, convert the values into the right units with appropriate
precision.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-06-18 10:48:46 -07:00
Dirk Hohndel
dda28c76aa Reduce the bleeding in my eyes
This is all just coding style and white space cleanup.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-06-18 09:27:34 -07:00
Dirk Hohndel
f780a56847 Clean up the last merge
While the code is correct, splitting the class like this is silly and will
confuse me later.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-06-18 09:25:24 -07:00
Dirk Hohndel
0773172f66 Merge branch 'qtHelper'
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-06-18 00:33:03 -07:00
Dirk Hohndel
29b242c703 Converting the device_info list into a Qt data structure
This data structure was quite fragile and made 'undo' when editing
rather hard to implement. So instead I decided to turn this into a
QMultiMap which seemed like the ideal data structure for it.

This map holds all the dive computer related data indexed by the model. As
QMultiMap it allows multiple entries per key (model string) and
disambiguates between them with the deviceId.

This commit turned out much larger than I wanted. But I didn't manage to
find a clean way to break it up and make the pieces make sense.

So this brings back the Ok / Cancel button for the dive computer edit
dialog. And it makes those two buttons actually do the right thing (which
is what started this whole process). For this to work we simply copy the
map to a working copy and do all edits on that one - and then copy that
over the 'real' map when we accept the changes.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-06-18 00:24:28 -07:00
Tomaz Canabrava
87e380c7a2 Yearly stats are being displayed.
Yearly stats are being displayed. the code is similar to the GTK one,
but I advise the reader that it's a bit risky  ( I got an unreproducible
crash but it seems to be fixed now. ). The selection behavior is *weird*
and I have no idea why, but I'm very sleepy - will try to look at
it again tomorrow.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-06-17 21:05:17 -03:00
Tomaz Canabrava
a05ea5a6e8 Create a view for the Statistics Model and Fix displaying the header
This simply creates a view to show the model, while doing that
I noticed that the model header wasn't showing, so I fixed it too.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-06-17 20:02:30 -03:00
Tomaz Canabrava
240cfa74be Started to do the Yearly Statistics
This is the fisrt bunch of compilable code for the new Yearly Statistics
there's nothing to see here, move along...

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-06-17 19:41:05 -03:00
Tomaz Canabrava
ae68ae38bb Changed a lot of code to reduce boilerplate on models in the future.
So, I changed a lot of code to reduce boilerplate on models in the
future. Currently we do not have a lot of models, but this can increase
quite rapdly. There's a second TreeModel in the works, the Yearly
Statistics, this patch will save around 250 LOC for this new model,
and more and more models will give us a greater saving.

Iwll do that for the table models in the future too - I did the tree
models now because they are the most complex case and I didn't wanted
to create a second tree model without this.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-06-17 18:59:50 -03:00
Dirk Hohndel
1ee894dced Show the device id in hex
This is consistent with what we used to do

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-06-17 12:46:35 -07:00
Dirk Hohndel
f465230263 Merge branch '119_divecomputerManagement' of github.com:tcanabrava/subsurface
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-06-17 11:12:10 -07:00
Tomaz Canabrava
20849f014e Make the columns have a sane default width for 'type'
Make the columns on Cylinders edit and Wheight Edit to
have sane values for 'type', this is needed because the
old behavior was to set it fixed size, and the default fixed
size was silly. this calculates a good predefined value
taking the font size in consideration.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-06-16 13:28:59 -03:00
Tomaz Canabrava
f9b4c6b889 Better handling of default sizes on the Cylinder and Weight widgets
Better handling of default sizes on the Cylinder and weight widgets,
the weigth widget didn't had a CSS applied so it looked odd compared
to the cylinder one, also the default behavior for the combobox delegate
didn't worked very well with the css applied, being too small.
this patch fixes that.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-06-16 12:33:27 -03:00
Tomaz Canabrava
349a084496 Made all models have the same font.
The models were a bit messy - some of them got the correct font,
other didnt. This patch creates a new function 'defaultModelFont()'
that is being used to return the font in all cases now.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-06-16 11:13:32 -03:00
Linus Torvalds
84d4a2dae0 Partially fix dive downloading
The Qt branch didn't set the preexisting dive count, so matching old
dives didn't work and it always downloaded all of them.

Also, we need to autogroup dives before displaying them if autogrouping
is on.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-06-15 17:03:23 -07:00
Linus Torvalds
788c513dd4 Improve the trip header
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-06-13 20:00:20 +02:00
Dirk Hohndel
e34da61362 Merge branch 'linusDiveList' of https://github.com/tcanabrava/subsurface
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-06-13 19:56:36 +02:00
Tomaz Canabrava
ab0213f28e Implements the DiveList to behave like Linus Explained.
Implements the divelist to behave like linus explained,
essentially, it filters the layoutChanges of the model,
greps for trips, and for each trip that it finds, it set
the 'firstColumnSpanned' property, to make the column
to have the size of the whole table. e

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-06-12 14:14:25 -03:00
Dirk Hohndel
04a7374917 Display the correct metric SAC rate in divelist
We were doing integer math by mistake.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-06-12 11:58:57 -04:00
Linus Torvalds
c9113a1f42 Sort 'dive number' column by date, not number
Ok, so this sounds insane, but it fixes our currently broken sorting
of dive trips vs plain dives not in trips.

The reason for that is simple: the dive trips are sorted by date, but
that's column #0, and for plain dives is the dive number.

So currently the trip-vs-dive sorting looks at the date of the trip,
and compares that to the number of the dive. Since the date of the
trip is expressed as seconds-since-1970-in-UTC, unsurprisingly the
dive number is generally much smaller (even for some very avid divers
;), and so the plain dives end up sorting way at the bottom (or at the
top, if you do "oldest trips first"

Since the dive number *should* sort as the date, this stupid attached
patch just makes us return the dive date instead.

Now, there are other possible solutions to this:

 - make the date of the dive be column 0, and make the dive number be column 1.

   Quite frankly, while more logical for this particular problem, it
probably sucks as a solution. We do want to have a column we can sort
dives by that is date-based, but doesn't include trips. And while the
dive number *should* sort identically to the date one, the fact is
that you can have dives without any numbering, so it doesn't.

   In contrast, all dives have dates, and sorting numbered dives by
date should still result in sane behavior (and if it doesn't, then the
insanity comes from the dive numbering, and odd sorting is the fault
of the user and indicative of a problem)

 - We could possibly do something magical like sorting dives by number
when they are inside trips, or when no trips exist at all. But then
we'd sort by date when there are trips and the dive is outside the
trip. But quite frankly, that just sounds insane.

So on the whole, I don't love this patch, but it seems to be the least
confusing of the possibilities.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-06-08 20:45:29 -07:00
Tomaz Canabrava
54128aa52f Added the code to remove a dive computer.
Added the code to remove a dive computer, plus a few fixes

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-06-07 15:25:29 -03:00
Tomaz Canabrava
478c24d797 Removed the buttons on the Edit Dive computers.
This edit dive computers thing doesn't really need buttons anyway.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-06-07 14:59:06 -03:00
Tomaz Canabrava
24446f9c3c Edit the name of the Dive Computer via dialog.
The GTK version seems to be bugged on this, since the dialog
doesn't save the dive computer nickname that I setted, but
the Qt version shows less dive-computers than the GTK one on the
same dive. I want somebody to do a quick review of my code too. :)

I also plan to remove the 'OK' and 'Cancel' buttom, they seem to
be overrated on this dialog - fairly uneeded.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-06-07 12:57:35 -03:00
Tomaz Canabrava
ebed836ee5 Created a new dialog - Edit DiveComputer
Created a new dialog, Edit Divecomputer, it will currently only lists
the divecomputers that are used on the xml file. I used the same method
that the gtk version used, but only 2 divecomputers got visualized in the
dirk dive data. I'll assume that it's correct and will fix it in the next
couple of commits.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-06-07 11:43:45 -03:00
Dirk Hohndel
85e3a4ad29 Fix sorting by rating
In commit beb4ed38f264 ("Add a "sort role" for sorting the dive list")
Linus forgot to add a case for the rating value.

Now all columns sort correctly.

With this I think we can close the bug...

Fixes #111

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-30 05:53:50 +09:00
Dirk Hohndel
f037b9e13f Code layout changes
Tomaz convinced me (with help from Linus) that it might be a good idea
to go with the compacter "single line" case statements in some specific
instances where this makes the code much more compact and easier to
read.

While doing that I changed Linus' code to do 'retVal = ...; break;'
instead of just 'return ...;' - this is more consistent and makes
debugging a little easier.

And while doing all that, I also cleaned up divelistview.cpp a little bit.
And removed an unused variable.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-30 05:49:41 +09:00
Linus Torvalds
bb77f5a44e Add a "sort role" for sorting the dive list
By default, sorting is done by the display role, but then we end up
sorting by the string we display, which is almost always the wrong thing.

So this adds a new "SORT_ROLE" that is used for sorting, and then the
data lookup can return the raw data we want to sort by.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-29 20:10:20 +09:00
Tomaz Canabrava
c6f84de37c Adds the code to make the dive list behave like tree or list
This code adds the possibility to make the DiveList behave
like a Tree or a List, depending on what layout is set.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-05-28 16:56:58 -03:00
Dirk Hohndel
81e27b6db9 Try to make the equipment tab more compact
My attempts to actually set the width of the columns with the
SizeHintRole all failed - so I gave up on that and am forcing things to
work by making the texts in the header somewhat longer and then resizing
to that. Definitely not what I wanted to do - but that plus reducing the
font size gives us a much more reasonable / compact look.

I really hope that someone else can explain to me how to get the
SizeHintRole to affect the width (and not just the height - that part
worked just fine) of a the cells in a column. Then we can replace this
hack by a much better solution (that won't fail if the translated strings
look different).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-25 20:07:36 -07:00
Alberto Mardegan
5e0a3cdad8 Fix usage of temporary QByteArrays
This commit fixes three different things:
 - a memory leak in WeightModel::setData()
 - getSetting() calling strdup() on a QByteArray
 - a possible usage of memory after deallocation

Here's an explanation of the last issue (taken from the mailing list, slightly
adapted):

toByteArray(), as well as others "toSomething()" methods, returns
a new object which the compiler allocates on the stack.  The compiler
will consider it a temporary data, and destroy it on the next line.  So,
when one does

	char *text= value.toByteArray().data(); // line 1
	if (strcmp(description, text)) {        // line 2

the compiler creates a QByteArray on line 1, calls ::data() on it, which
returns a valid char *, and assigns its value to "text".  So far, so
good.  But before jumping to line 2, the compiler destroys the temporary
QByteArray, and this will in turn invoke the QByteArray destructor,
which will destroy the internal data. The result is that on line 2,
"text" will point to some memory which has already been freed.

One solution is to store a copy of the temporary QByteArray into a local
variable: the compiler will still destroy the temporary QByteArray it created,
but (thanks to the reference-counted data sharing built in QByteArray) now the
destructor will see that the data is referenced by another instance of
QByteArray (the local variable "ba") and will not free the internal data.
In this way, the internal data will be available until the local variable is
destroyed, which will happen at the end of the {} block where it is defined.

Please note that when one uses the data in the same line, one doesn't need to
worry about this issue. In fact,

  text = strdup(value.toString().toUtf8().data());

works just fine.

Signed-off-by: Alberto Mardegan <mardy@users.sourceforge.net>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-24 06:18:27 -07:00
Dirk Hohndel
90a24255b2 Correctly add new weight / cylinder types, even when hitting 'tab'
We now detect if a weight / cylinder with this description exists and if
not add it on the fly. We also remember the additional values (weight and
size / workingpressure) for new entries and take the values for these
fields into account when autocompleting.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-23 23:26:17 -07:00
Dirk Hohndel
01a3bd2cc6 Add weightsystem delegate to enable editing of weightsystem
This is very much analogous to the way cylinders are implemented.
That means that just like with cylinders, if the user enters a new type
and hits 'tab' before hitting 'enter', Subsurface will crash.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-23 21:36:33 -07:00
Dirk Hohndel
ecbcd4db47 Enable the weightsystem info and move the declarations to dive.h
Having the tank_info declared in models.cpp seemed unintuitive.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-23 21:33:19 -07:00
Dirk Hohndel
d273694954 Allow the CylindersModel delegate to pass data in without unit conversions
With this we should have tank editing mostly done.

See #122

(it's not quite fixed, we need the equivalent code for weight systems)

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-23 13:31:46 -07:00
Tomaz Canabrava
babbfa9204 Added support for Completing on the Cylinder Type delegate
I had to immprove the TankInfoModel with two new methods,
insertRows and setData, because the delegate used this
model to show what kind of Tanks we are offering.
Since the user can enter a new type of Tank, it's important
to add this tank to all lists using the delegates.

I Also added two new methods on the delegate itself,
to correctly shows the data, and set the data on the
model. This also will help dirk with a working example
on how to edit things while using a delegate.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-05-23 15:33:20 -03:00
Dirk Hohndel
115e5e5fbc The never ending, futile fight for whitespace consistency
I just need to write a tool that does this...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-22 21:31:45 -07:00