aboutsummaryrefslogtreecommitdiffstats
path: root/desktop-widgets
AgeCommit message (Collapse)Author
2019-11-09Desktop: support no-cylinders in dive information tabGravatar Berthold Stoeger
The tab was crashing if there were no cylinders because 1) per_cylinder_mean_depth() would access non-existing cylinders. 2) TabDiveInformation::updateProfile() would access a non-existing mean. Fix both of these crash conditions by checking whether the dive actually has cylinders. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09Core: remove MAX_CYLINDERS restrictionGravatar Berthold Stoeger
Instead of using fixed size arrays, use a new cylinder_table structure. The code copies the weightsystem code, but is significantly more complex because cylinders are such an integral part of the core. Two functions to access the cylinders were added: get_cylinder() and get_or_create_cylinder() The former does a simple array access and supposes that the cylinder exists. The latter is used by the parser(s) and if a cylinder with the given id does not exist, cylinders up to that id are generated. One point will make C programmers cringe: the cylinder structure is passed by value. This is due to the way the table-macros work. A refactoring of the table macros is planned. It has to be noted that the size of a cylinder_t is 64 bytes, i.e. 8 long words on a 64-bit architecture, so passing on the stack is probably not even significantly slower than passing as reference. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09Undo: Make PasteState cylinders list dynamically allocatedGravatar Berthold Stoeger
Instead of using a sub-array, use a std::vector<>. This is a necessary step in removing the MAX_CYLINDERS restriction. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09Cylinders: dynamically allocate cylinder arraysGravatar Berthold Stoeger
When keeping track of cylinder related data, the code was using static arrays of MAX_CYLINDERS length. If we want to use dynamically sized cylinder arrays, these have to be dynamically allocated. In C++ code, this is trivial: simply replace the C-style arrays by std::vector<>. Don't use QVector, as no reference counting or COW semantics are needed here. These are purely local and unshared arrays. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09Core: dynamically allocate the result of get_gas_used()Gravatar Berthold Stoeger
get_gas_used() returns the volume of used gases. Currently, an array with MAX_CYLINDERS is passed in. If we want to make the number of cylinders dynamic, the function must use an arbitrarilly sized array. Therefore, return a dynamically allocated array and free it in the caller. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-08Profile: remove ProfileWidget2::recalcCeiling()Gravatar Berthold Stoeger
The ProfileWidget2::recalcCeiling() function is used in one place, namely when an undo-command changes the mode. It recalculates decompression data and repaints the ceilings and thus avoids a full profile-redraw. This is smart, but it becomes problematic when the dive is changed and the ceiling is recalculated before the profile is redrawn. The DivePlotDataModel then still has data from the previous dive but cylinders of the new dive are accessed. This kind of situation may arise if multiple dive fields are updated, as for example when replanning a dive. Currently, this only causes a temporary mis-calculation. When removing MAX_CYLINDERS this will lead to crashes. One might attempt to fix the whole data-dependency mess. This commit goes the cheap route and simply redraws the profile when the mode is changed. Yes, it is in a way ineffective, but we do worse things. The ProfileWidget2::recalcCeiling() thus becomes unused and is removed. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-31Planner: Add option to treat O2 as narcoticGravatar Robert C. Helling
When computing the best mix for a target depth, for helium, one can either require that the partial pressure of N2 is the same as at the target depth or the partial pressure of N2 plus O2. Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-10-28Cleanup: better handling of NULL dive in setCurrentDiveSiteGravatar Dirk Hohndel
We test for d being NULL so that's clearly an option we worried about, yet we already called get_dive_site_for_dive(d) which dereferences d. Found by Coverity. Fixes CID 350118 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-28Desktop: fix dive site editingGravatar Berthold Stoeger
When clicking "done" on the dive site edit screen, the diveSite member variable was reset to nullptr in acceptChanges() at the beginning of the function. This prevented posting an undo-command as a consequence of the active widget losing focus. Reset the diveSite variable after exiting dive-site mode, which causes the active widget to lose focus. Reported-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-27Don't expose 'detach_buffer()' to membuffer usersGravatar Linus Torvalds
The native buffer of a membuffer is not NUL-terminated, so when you want to detach it and use it as a C string, you had to first do 'mb_cstring()' that adds the proper termination/ This was all documented in the header files, and all but two users did it correctly. But there were those two users, and the exported interface was unnecessarily hard to use. We do want the "just detach the raw buffer" internally in the membuffer code, but let's not make the exported interface be that hard to use. So this switches the exported interface to be 'detach_cstring()', which does that 'mb_cstring()' for you, and avoids the possibility that you'd use a non-terminated memory buffer as a C string. The old 'detach_buffer()' is now purely the internal membuffer implementation, and not used by others. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-10-27Cleanup: NULL check pointer before dereferencingGravatar Dirk Hohndel
Found by Coverity. CID 350081, 350087, 350095 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-27Cleanup: prevent uninitialized pointerGravatar Dirk Hohndel
This should never matter as we should never call undoit before redoit. Extra ensurance that we don't access random data. Found by Coverity. Fixes CID 350076 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-27Cleanup: avoid out of bounds accessGravatar Dirk Hohndel
This one is a bit complicated as it depends on a specific flow, but it seems like setup_cvs_parms might indeed write NULL to the element at index 49 of parm. I'm not 100% sure that the sequence of events required for this can happen, but adding one more pointer to the array seems like cheap insurance. Found by Coverity. Fixes CID 350120 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-26Undo: simplify profile repainting codeGravatar Berthold Stoeger
The profile repainting code that was called when a dive changed was located in a separate function. Not only did it take a redundant parameter, it also performed very weird stuff like entering and exiting plan state. That did not work at all. Replace by a simple call to plotDive() and things work much better. There was a comment about DivePlannerPointsModel and profile getting out of sync. So let's keep an eye out for that. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-26Undo: turn dive- and trip-fields into flagsGravatar Berthold Stoeger
The divesEdited signal sends the changed field as a parameter. Since some undo-commands change multiple fields, this led to numerous signals for a single command. This in turn would lead to multiple profile-reloads and statistic recalculations. Therefore, turn the enum into a bitfield. For simplicity, provide a constructor that takes classical flags and turns them into the bitfield. This is necessary because C-style named initialization is only supported on C++20 onward! Is this somewhat overengineered? Yes, maybe. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-26Undo: update statistics if dive changedGravatar Berthold Stoeger
On undo/redo, the dive statistics tab was not updated even if a selected dive was changed. Fix that. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-26Undo: implement ReplanDive commandGravatar Berthold Stoeger
Implement an undo command that overwrites the dive-computers and cylinders of the current dive with a given dive. This will be used when replanning a dive. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-26Desktop: make salinity a field known to the undo systemGravatar Berthold Stoeger
The undo system sets updates individual dive fields on redo respectively undo. Make salinity such a field, since it is changed on replanning a dive. To do this, break out the "update salinity" functionality into its own function, add an entry to the DiveField enum and add the corresponding switch-case. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-20Cleanup: use pointer-to-member-function in addAction() callsGravatar Berthold Stoeger
Since requiring Qt >= 5.9.1, we can use the pointer-to-member-function overloads of addAction (introduced in Qt 5.6). This has the advantage of compile-time checking of the signal/slot parameters. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-02Import: extract number of dives from model not from threadGravatar Berthold Stoeger
The plan is to make the model the authoritative source of the imported dives. Therefore, access the number of downloaded dives from there. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-02Import: clear table via model not via threadGravatar Berthold Stoeger
Clearing the table in the thread leaves the model in an inconsistent state. Don't do that. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-02Import: get tables from DiveImportedModel not DownloadThreadGravatar Berthold Stoeger
When importing dives, consume the tables from DiveImportedModel and not the DownloadThread. This appears more logical and avoids an inconsistent state of the DiveImportedModel: On import the tables would be reset, but the DiveImportedModel wasn't informed of that. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-02Documentation: add comment to Command::importDivesGravatar Berthold Stoeger
Add a comment that the passed-in dives are consumed. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-02Desktop: Use DiveImportedModel::deleteDeselected()Gravatar Berthold Stoeger
In DownloadFromDCWidget::on_ok_clicked() deselected dives were directly deleted from the dive table, leaving DiveImportedModel in an inconsistent state. Use the function in DiveImportedModel instead. This also removes code duplication. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-02Import: Make DownloadThread a subobject of DiveImportedModelGravatar Berthold Stoeger
Currently, desktop and mobile are accessing the DownloadThread and the DiveImportedModel concurrently. This makes a big data flow mess. To achieve a more hierarchical data flow, start by making the DownloadThread a subobject of DiveImportedModel. Start the download by calling a function in DiveImportedModel. Route the finished signal through DiveImportedModel. Thus, the model can reload itself with the new data. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-27Revert the singleton PRGravatar Dirk Hohndel
It turns out that this isn't working the way it was intended to. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-09-25Cleanup: unify idiosyncratic singletonsGravatar Berthold Stoeger
The way we handle singletons in QML, QML insists on allocating the objects. This leads to a very idiosyncratic way of handling singletons: The global instance pointer is set in the constructor. Unify all these by implementing a "SillySingleton" template. All of the weird singleton-classes can derive from this template and don't have to bother with reimplementing the instance() function with all the safety-checks, etc. This serves firstly as documentation but also improves debugging as we will now see wanted and unwanted creation and destruction of these weird singletons. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-21If only one dive selected, only one temperature in stats tabGravatar Fabio Rueda
In stats tab, when only one dive is selected, on one stat, only average is shown, except temperature which 3 same temps for max, min and avg are shown. [Dirk Hohndel: fixed whitespace] Signed-off-by: Fabio Rueda <avances123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-09-21Export: special case dive site mode when exporting dive sitesGravatar Berthold Stoeger
In dive site mode, export selected dive sites, not dive sites of selected dives. Fixes #2275. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-21Cleanup: return each dive site only once in selectedDiveSites()Gravatar Berthold Stoeger
In TabDiveSite::selectedDiveSites(), the QItemSelectionModel:: selectedIndexes() function was used. Thus for every selected dive site 8 entries were added to the return-vector! Instead, use the QItemSelectionModel::selectedRows() function. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-21Export: move dive site selection logic to C++Gravatar Berthold Stoeger
When exporting dive sites, the dive sites to be selected were collected in the C-core. But that doesn't have access to the selected dive sites if in dive site mode. Therefore, collect the dive sites in C++ and pass down to the core. Use a std::vector to avoid memory management woes. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-15if only one dive, max depth show in average fieldGravatar Fabio Rueda
Signed-off-by: Fabio Rueda <avances123@gmail.com>
2019-09-14Grantlee: split out grantlee-only property from DiveObjectHelperGravatar Berthold Stoeger
The cylindersObject list was only used by grantlee but not by the mobile code. Since it is quite heavy, split it out and thus don't generate it for every dive on mobile. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-14Mobile: transform DiveObjectHelper into value-typeGravatar Berthold Stoeger
Instead of handing a reference-to-dive to QML, prerender all the needed properties and store them as values in DiveObjectHelper. Exception: - date(): generated from timestamp - time(): generated from timestamp - cylinderList(): does not depend on dive anyway and should be made static. This hopefully avoids the random mobile crashes that we are seeing. Clearly, this code needs to be optimized, but it is a start. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-14DiveObjectHelper: Turn DiveObjectHelper into Q_GADGET based objectGravatar Berthold Stoeger
DiveObjectHelper is a tiny wrapper around dive * to allow access to dive data from QML and grantlee. It doesn't have to be a full-fledged QObject with support for signals, etc. Therefore, turn it into a Q_GADGET based object. This allows us passing the object around as object, not as pointer to DiveObjectHelper. This makes memory-management distinctly easier. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-11Add the ability to export print template as htmlGravatar Anton Lundin
This way we can view the html generated from a print template, for debugging, validation or printing via your favorite browser. Signed-off-by: Anton Lundin <glance@acc.umu.se>
2019-09-11Show correct notes entry when switching on stopsGravatar Robert C. Helling
When gas switching only on stops is selected, the notes showed an extra line at the not realized stop depth. This eliminates it. It also makes sure there are no 0 second spurious entries. And gas switching takes more than zero time (otherwise we would have to print a line of zero duration for at the gas switch depth). Reported-by: tormento <turment@gmail.com> Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-09-10Plan: introduce function that returns disclaimerGravatar Berthold Stoeger
The setting of the disclaimer variable was removed inadvertently some time ago, which removed the disclaimer from the printed plan. Instead, introduce a function that returns the disclaimer with the current deco mode. Use that function to generate the dive notes and for printing. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-07Dive site: close dive site edit widget when dive site is deletedGravatar Berthold Stoeger
The application could be crashed by 1) Create dive site 2) Edit dive site 3) Undo until dive site is removed 4) Continue editing now non-existing dive site Therefore, hook into the dive-site-deleted signal and if the currently edited dive site is deleted, close the widget. When closing the widget, make sure that the potentially dangling pointer is reset to zero so that there is no other potential use-after-free bug. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-06Cleanup: remove unused MapWidget::repopulateLabels() functionGravatar Berthold Stoeger
There is the alternative MapWidget::reload() function, which centers on the selected dive-site. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-06Map: remove MapWidget::repopulateLabels() callGravatar Berthold Stoeger
For historic reasons MapWidget::repopulateLabels() was called in LocationInformationWidget::acceptChanges(). This should not be necessary anymore, as this is done when entering/exiting dive-site-mode. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-06Map: remove unnecessary MapLocationModel::repopulateLabels() callsGravatar Berthold Stoeger
The LocationInformationWidget repopulated the map labels if the name or location of a site changed. This is unnecessary because the MapLocationModel catches these signals itself. Remove these calls. As an added bonus, calling repopulateLabels() in QML context leads to crashes later on. Therefore this should fix at least one crash condition when dragging a flag on the map while the dive-site-edit-tab is shown. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-06Dive site: don't emit divesChanged signals when editing dive siteGravatar Berthold Stoeger
When editing the dive site, for certain fields a divesChanged signal was emitted so that the dive-list can be updated. Arguably it is wrong to decide which fields are relevant to the dive list in the undo-command code. Therefore, let the list catch the dive-site-edited signal and decide itself. But the actual reason for this commit is that if the dive-site field of a dive changes, we might have to reload the dive-location-model because suddenly a new dive site appears. Now if this is done in QML context on some Qt version (notably 5.9) we get crashes later on. But that can happen if the user moves a flag. So in that case only send a diveSiteChanged signal. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-06Map: highlight correct dive sites in dive site modeGravatar Berthold Stoeger
Since changing the highlighting to use the selected dive, dive sites with no dive were never highlighted in dive site mode. Obviously, because there was no dive to be selected. Therefore special-case all dive-site selection code to recognize when we are in dive site mode. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-06Cleanup: remove TabDiveSite::updateFilter() functionGravatar Berthold Stoeger
This one-liner was called in only one place from the same class. Just fold it into the caller. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-06Selection: properly update selection flag of map locationGravatar Berthold Stoeger
Owing to the recent changes, when the selection flag in the MapLocationModel was not updated correctly when the user manually selected the dive. Do that before raising the divesSelected signal in DiveListView::selectionChanged() because that will cause the MainWindow to repaint the flags. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-06Desktop: show all selected dive sites on clickGravatar Berthold Stoeger
When clicking a dive site on the map, the QML code would set the selected dive site, but then all dives of dive sites in the vicinity were set. But still only the clicked-on dive site was shown. Therefore, don't set the list of selected dive sites in QML, but later in DiveListView::selectDives(), where we know all the dives that were selected. This, again, gives nasty entanglement of diverse widgets and models. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-06Map: don't fully reset model on selection changeGravatar Berthold Stoeger
When changing the selection the MapLocationModel was reset. This lead to crashes on Qt-5.9 which are due to QML accessing data that was freed during model reset. This putative Qt bug doesn't happen on newer Qt versions. At least Qt-5.12 is known to work. Instead of fighting the bug, let's simply not reset the model but send a dataChanged() for every element of the MapLocationModel. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-06Desktop: reload map after refreshing the listGravatar Berthold Stoeger
In MainWindow::refreshDisplay() with doRecreateDiveList=true the map was reset before the dive list was recreated. This makes no sense and only worked because the map was reloaded again when a dive in the list was selected. Reload the map after recreating the dive list. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-06Map: generate pixmap name in modelGravatar Berthold Stoeger
Experimentation has shown that the image of a flag will only be changed after dataChanged() if it is a simple property. The old code had a complex QML expression and then - for some reason - it didn't work. To give us better control over the flags and avoid full reloads of the map therefore introduce a model-property pixmap name. The name depends on whether the site is selected and if not, whether we are in divesite-edit mode. This makes the code rather convoluted. Firstly, we have to save whether the site is selected in the map-item. Secondly we have to access the global map-widget, which in turn has to go to the map-widget helper (layering violation!). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>