aboutsummaryrefslogtreecommitdiffstats
path: root/desktop-widgets
AgeCommit message (Collapse)Author
2019-11-14Undo: don't delete dive sites when pasting divesGravatar Berthold Stoeger
We used to only keep sites with dives around. This changed when implementing the dive site tab. The paste-dive code was written using the old semantics and thus, when overwriting dive sites, it deleted unused dive sites. To make things consistent, remove that code. It would be very weird when dive sites are deleted by pasting, but not by setting a different dive site manually. Bonus: no more dependencies on desktop-includes in the undo code. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-14Undo: remove unrelated include in command_divelist.cppGravatar Berthold Stoeger
This file included "desktop-widgets/divelistview.h" without needing it. If we want to use the undo commands on mobile we shouldn't include desktop headers. Therefore, remove the include. This has the unintended side-effect that the Qt debug headers are not included indirectly anymore. Thus, change a few "qWarning() << ..." instances to "qWarning(...)". Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-14Undo: remove superfluous dive replot in DiveComputerBase::redoit()Gravatar Berthold Stoeger
Removing / moving a dive computer needs a profile replot. This was done explicitly in DiveComputerBase::redoit(). This is unnecessary, as a profile replot is performed implicitly by the setSelection() call. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-14Undo: remove superfluous refreshDisplay() in AddDive::(un)doit()Gravatar Berthold Stoeger
Dives used to be added from a special dive-edit screen. Thus, the undo command had to close that screen. This is no longer the case. Remove the calls. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-14Cleanup: don't std::move() temporariesGravatar Berthold Stoeger
clang correctly warns about std::move()ing objects returned from functions. This is a pessimization, because the compiler can't copy elide the object. Remove. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-11Show altitude corresponding to surface pressureGravatar willemferguson
In the information tab, presenting atmospheric pressure is a bit unintuitive because the diver cannot easily relate that to altitude. For the Atm. Pressure widget in the Information tab this code does: If the atmospheric pressure for a dive exists and the user selects the 'm' or 'ft' option from the combobox, then the estimated altitude is shown in the text box. Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
2019-11-11Cleanup: introduce DiveTripModelBase::IS_TRIP_ROLEGravatar Berthold Stoeger
To test whether an entry is a trip, we passed a pointer to the trip through a QVariant and tested that for null-ity. Passing pointers through QVariants has given us myriads of problems in QML, therefore introduce a bool IS_TRIP_ROLE Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-11 Notes tab: Use top RH for depth and duretion fieldsGravatar willemferguson
Currently the top righthand part of the notes tab is used for showing and editing air teperature and water temperature. But these fields were moved over to the Information tab and are not required in the Notes tab any more. Rather use this space for the depth and duration data for manually-entered dives. Currently extra vertical space is created in the Notes tab for showing this field, resulting in inefficient use of screen space and inelegant layout. This code moves the Duration and Depth fields into the top righthand of the Notes tab. Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
2019-11-11Information tab: Make air and water tempertatures editableGravatar willemferguson
The undo stack is preserved. This is in preparation of removing temperatures from the Notes tab. Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
2019-11-10Reorganise the Information tab of the Info panelGravatar Willem Ferguson
1) Reorganise the existing widgets in the Information tab 2) Move divemode widget and visibility widget from Notes tab to Information tab 3) Translate water density to a word indicating water type 4) Reorganise the Notes tab to compensate for the moving the divemode and visibility widgets to the Information tab 5) Remove the problems in showing a QGroupBox in Qt Windows. I do this by removing the CSS specifying border characteristics Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-11-09Cylinders: access cylinders with get_cylinder()Gravatar Berthold Stoeger
Instead of accessing the cylinder table directly, use the get_cylinder() function. This gives less unwieldy expressions. But more importantly, the function does bound checking. This is crucial for now as the code hasn't be properly audited since the change to arbitrarily sized cylinder tables. Accesses of invalid cylinder indexes may lead to silent data-corruption that is sometimes not even noticed by valgrind. Returning NULL instead of an invalid pointer will make debugging much easier. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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>