aboutsummaryrefslogtreecommitdiffstats
path: root/qt-ui/models.cpp
AgeCommit message (Collapse)Author
2013-05-29Add a "sort role" for sorting the dive listGravatar Linus Torvalds
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-28Adds the code to make the dive list behave like tree or listGravatar Tomaz Canabrava
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-25Try to make the equipment tab more compactGravatar Dirk Hohndel
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-24Fix usage of temporary QByteArraysGravatar Alberto Mardegan
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-23Correctly add new weight / cylinder types, even when hitting 'tab'Gravatar Dirk Hohndel
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-23Add weightsystem delegate to enable editing of weightsystemGravatar Dirk Hohndel
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-23Enable the weightsystem info and move the declarations to dive.hGravatar Dirk Hohndel
Having the tank_info declared in models.cpp seemed unintuitive. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-23Allow the CylindersModel delegate to pass data in without unit conversionsGravatar Dirk Hohndel
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-23Added support for Completing on the Cylinder Type delegateGravatar Tomaz Canabrava
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-22The never ending, futile fight for whitespace consistencyGravatar Dirk Hohndel
I just need to write a tool that does this... Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-22Small fixes to the modelGravatar Dirk Hohndel
Prevent a crash when no cylinder type description is set. Correctly calculate the cylinder volume. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-22Get the math right for cylinder model setData functionGravatar Dirk Hohndel
This is a fun one. We only want to mark the divelist changed if the user actually changed something. So we try really hard to compare what was entered with what was there and only if it is different do we overwrite existing values and record this as a change to the divelist. An additional challenge here is the fact that the user needs to enter a working pressure before they can enter a size (when in cuft mode). That is not really intuitive. We work around this by assuming working pressure is 3000psi if a size is given in cuft - but then if the user changes the working pressure, that changes the volume. Now going back and changing the volume again does the trick. Or enter the working pressure FIRST and then the volume... This also changes the incorrect MAXPRESSURE to WORKINGPRESSURE and uses the text WorkPress in English (Gtk code used MaxPress which was simply wrong - this is just the design pressure or working pressure, not some hard maximum. In fact, people quite commonly "overfill" these tanks. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-22Merge branch 'comboBoxDelegate' of https://github.com/tcanabrava/subsurfaceGravatar Dirk Hohndel
2013-05-22Removed the unused add cylinder and add weigthsystem dialogs.Gravatar Tomaz Canabrava
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-05-22Removed unused debug, and set the correct data on the delegates.Gravatar Tomaz Canabrava
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-05-22Actually remove cylinders and weightsystems from the data structuresGravatar Dirk Hohndel
The UI had only stubbed this code out. This adds the implementation of the helpers and calls them. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-22Added basic editing functionality for Cylinders and WeigthsystemsGravatar Tomaz Canabrava
This patch adds basic editing functionality for Cylinders and Weigthsystems, it still doesn't use delegates to show the data to the user in a better way, and it does not take in consideration user preferences yet, but it's a starting point. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-05-22Extend a bit the skeleton 'removes' on cylinder and weigth to help dirk.Gravatar Tomaz Canabrava
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-05-22Added a 'trash' icon on the Cylinders and Weigthsystem modelsGravatar Tomaz Canabrava
So, the Cylinders and Weigthsystems got a new Trash icon, and the interface already intercepts the clicks ( on all columns ) and send this to the 'remove' method on boch models. On the model I'm just filtering the indexes that are not 'DELETE' and creating a stub method to be filled later. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-05-21Correctly format the values shown for cylinders and weightsGravatar Dirk Hohndel
Make use of all the nice helpers that we have... Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-21Correctly use the weightsystem_none / cylinder_none helpersGravatar Dirk Hohndel
Plus a couple of minor formatting changes Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-21Added support for visualization the Weigthssystems on the Equipment Tab.Gravatar Tomaz Canabrava
This patch adds support showing and for editing weigthsystems in the equipment tab, so, now the two things that are missing are 'edit' and 'delete', wich are quite easy to do. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-05-21Added the code to show the cylinders from a dive.Gravatar Tomaz Canabrava
i Added the code to show the cylinders from a dive, this code also already permits additions from the interface, so the user can click 'add' and insert what he wants there. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-05-19Make the Text on the DiveList be 30% smaller than other textGravatar Tomaz Canabrava
This makes the DiveList be similiar to the GTK one, comparing the size of the text. The current code makes text on the table be 30% smaller. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-05-14Don't add half a kilo/pound when adding weightsGravatar Henrik Brautaset Aronsen
The weight management widget added 500 grams / 0.5 lbs when a new entry was added. Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-14Fix inaccurate weight and temperature display in dive listGravatar Henrik Brautaset Aronsen
A nonexisting temperature (mkelvin==0) was displayed as -273°C. Weight was always displayed with an extra 500 grams/0.5 lbs. Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-14Clean up some typosGravatar Henrik Brautaset Aronsen
Cosmetic commit to clean up some of the annoying typos in qt-ui Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-13Trying to make the DiveList selection behave correctlyGravatar Tomaz Canabrava
And rip out all the code that Dirk put there to do that. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-11Fix crash in DiveTripModel.Gravatar Amit Chaudhuri
A left click in the treeview header leads to a call to createIndex which results in a null pointer dereference. Signed-off-by: Amit Chaudhuri <amit.k.chaudhuri@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-06Start populating the maintab Dive Info widgetGravatar Dirk Hohndel
Establish some useful helpers and use them when updating the values. One of the helpers (from statistics.c) puzzlingly doesn't link - so that's ifdefed out. Also had to re-arrange the settings reading code (it came too late) and to extract the expanding code of the top dive from the settings reading code (as it had no business being there to begin with). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-02Merge branch 'tomaz-css' into QtGravatar Dirk Hohndel
Tomaz' code does a much better job of shading the dive list! Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-02Added code to Select a dive, fixed minor annoyances.Gravatar Tomaz Canabrava
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-02Test the CSS for styling the TableViewGravatar Tomaz Canabrava
This is a test and I shouldn't be taken seriously. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-02Alternate background colors for dive listGravatar Dirk Hohndel
This was written with massive hand-holding by Tomaz - actually, this was mostly proposed via IRC by Tomaz and then implemented by me... Right now because of the list-of-lists nature of the model we have the small issue that every trip starts with a dark background dive, even if the trip itself has a dark background. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-02Set better column widths in the dive listGravatar Dirk Hohndel
This code seems rather crude to me. I'm sure this could be done better. This also makes the column alignment work again. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-02Show cylinder and gas used in the Qt dive listGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-02Show trip date (with number of dives) in dive/trip listGravatar Dirk Hohndel
That was easy :-) Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-01Minor style updatesGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-01Merge branch 'Qt' into RenderStarsOnTableGravatar Tomaz Canabrava
2013-05-01Added Support for the Trips and Dives on the DiveList model.Gravatar Tomaz Canabrava
Now the list and dives will work in the same way that the GTK version does. The code got changed heavly because the old one was just looking at the dives and didn't worked like a tree. small adaptations on the list view and model delegates because of the changes done on this model. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-05-01Don't add cylinders and weightsystems past the MAXGravatar Dirk Hohndel
We actually should disable the 'Add' button, I guess. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-01Hook up adding a weightsystemGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-01Add data and add functions for WeightModelGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-01Use the existing current_dive macro in Qt codeGravatar Dirk Hohndel
Replicating this with the currentDive member seems to make no sense. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-28Fixed loading the stars when opening with file as argv. minor cleanupGravatar Tomaz Canabrava
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-04-27Added support for showing the Stars on the DiveTableGravatar Tomaz Canabrava
For the stars on the dive table I had to rework a bit my StarRating widget, because it used a pixmap for each widget that were created. Not it uses only 2 pixmaps: the active and inactive ones. A new file was created named modeldelegates(h, cpp) that should hold all delegates of the models. For the GTK / C folks, a 'Delegate' ia s way to bypass the default behavior of the view that's displaying the data. I also added the code to display the stars if no delegate is set ( good for debugging. ) Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-04-25Remove the explicit UTF-8 conversionsGravatar Dirk Hohndel
Thanks to commit bdbfdcdfa0fb ('Ask Qt 4 to use the UTF-8 codec as the "codec for C strings"') we no longer need the explicit UTF-8 conversion when creating QStrings from char *. Suggested-by: Thiago Macieira <thiago@macieira.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-25Minor cleanup of constructors and one accessor for DiveItemGravatar Dirk Hohndel
Suggested-by: Thiago Macieira <thiago@macieira.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-25Remove useless members of DiveItemGravatar Henrik Brautaset Aronsen
Just use the dive struct directly. Suggested-by: Dirk Hohndel <dirk@hohndel.org> Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-25Simplify DiveItemGravatar Henrik Brautaset Aronsen
The DiveItem constructor had 13 variables. By passing it the full dive we reduce that to 2. [Dirk Hohndel: changed to use "struct dive *" instead of just "dive *"] Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>