aboutsummaryrefslogtreecommitdiffstats
path: root/qt-ui/models.cpp
AgeCommit message (Collapse)Author
2013-11-21Work around QMessageBox not showing its title on MacGravatar Dirk Hohndel
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-21Quiet down warning about return in non-voidGravatar Anton Lundin
Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-19Small whitespace cleanupGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-19Fix trip summary line in dive listGravatar Dirk Hohndel
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-19Sanity check on gas percentagesGravatar Dirk Hohndel
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-18Do not let the dive have the 0 value.Gravatar Tomaz Canabrava
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-18Make it posible to renumber dives.Gravatar Tomaz Canabrava
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-16Fix wrong handling of Dive Table, and revert some wrong changes.Gravatar Tomaz Canabrava
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-15This moves the removal code to the model.Gravatar Tomaz Canabrava
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-15Use the correct font for the Air Types Model.Gravatar Tomaz Canabrava
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-15Correctly handle changes on the CylinderModel to update the AirModel.Gravatar Tomaz Canabrava
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-14Fix edition of alphanumeric input on equipments.Gravatar Tomaz Canabrava
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-13Connect changes in the tanks with the dive that is being addedGravatar Dirk Hohndel
- 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-12Use existing helper functionGravatar Dirk Hohndel
And remove spurious extra ';' Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-12Add depth colum to cylinder modelGravatar Dirk Hohndel
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-11Fix crash when cancelling dive add on empty dive listGravatar Dirk Hohndel
Don't pass NULL dives around. Fixes #231 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-10Show a cylinder widget in the dive plannerGravatar Dirk Hohndel
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-10-16Helpers: move some date related function to qt-gui.cppGravatar Lubomir I. Ivanov
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-15Printing adjustmentsGravatar Robert Helling
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-15printlayout.cpp: Increase the font size in tables bellow profileGravatar Lubomir I. Ivanov
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-13Models: fix two potential crashesGravatar Lubomir I. Ivanov
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-13Adds missing "EndPress" column header for cylinder tableGravatar Tim Wootton
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-11Finish clearing up the TableModelsGravatar Tomaz Canabrava
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-11Another Model CleanupGravatar Tomaz Canabrava
Conversion of the WSInfoModel, that populates the list of weigthsystems in the Equipment tab. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-10-11Second model converted to be less boilerplated.Gravatar Tomaz Canabrava
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-11Begin to Cleanup the Models, trying to reduce boilerplate.Gravatar Tomaz Canabrava
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-11Good deal of whitespace fixes and code cleanup.Gravatar Tomaz Canabrava
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-04Add a helper function to calculate weight display stringGravatar Benjamin
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-04Use the same conversion grams->lbs in dive and equipment listGravatar Benjamin
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-03Print: provide means to print profile tablesGravatar Lubomir I. Ivanov
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-09-25Only mark dive list as changed if 'Accepted' was clicked.Gravatar Tomaz Canabrava
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-25Added a 'changed' member on Cylinder/Weigth models to know when to Apply a ↵Gravatar Tomaz Canabrava
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-10Fix row counting bugGravatar Dirk Hohndel
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-10Change ws_info and tank_info typesGravatar Dirk Hohndel
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-10Fill ws_info structure and use it when entering weight systemsGravatar Dirk Hohndel
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-08-05Print: improve table printing by using QTableViewGravatar Lubomir I. Ivanov
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-07-18Fixes incorrect editing policies.Gravatar Tomaz Canabrava
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-18Added the code to revert Weigths when user cancels editionGravatar Tomaz Canabrava
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'Cancel' action Cancels editing Cylinders.Gravatar Tomaz Canabrava
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-16Fixes the Combobox behavior on the inline-editGravatar Tomaz Canabrava
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-11Models: add the DiveItem::displayDate() helperGravatar Lubomir I. Ivanov
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-11Models: move the declaration of DiveItem to the headerGravatar Lubomir I. Ivanov
This should allow external use of the type by including models.h. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2013-07-04Qt: Implement trip merging logicGravatar Linus Torvalds
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-06-19Show sample pressures in the cylinder equipment pageGravatar Linus Torvalds
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-19Don't show '0.0%' gas percentagesGravatar Linus Torvalds
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-19Fix the imperial cylinder size calculations in equipment handlingGravatar Linus Torvalds
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-19O2/He percentages aren't integralGravatar Linus Torvalds
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-19Replace wet_volume calculation with straight forward pressure formulaGravatar Dirk Hohndel
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-19Fix cylinder data O2/He percentage entry braindamageGravatar Dirk Hohndel
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-19Improve readability of yearly statisticsGravatar Dirk Hohndel
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>