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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>