The latter was the only caller of the former and there seems
to be no clear separation between the two. By making a single
function out of this the code is easier to follow and duplicate
code can be more easily detected. Matter of fact, the profile
was cleared twice.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In the future we might want to use undo-commands for mobile as
well (even if not implementing undo).
Therefore, move the undo-command source from desktop-widgets
to their own commands top-level folder.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>