Previously, each dive-list modifying function would lead to a
full model reset. Instead, implement proper Qt-model semantics
using beginInsertRows()/endInsertRows(), beginRemoveRows()/
endRemoveRows(), dataChange().
To do so, a DiveListNotifer singleton is generatated, which
broadcasts all changes to the dive-list. Signals are sent by
the commands and received by the DiveTripModel. Signals are
batched by dive-trip. This seems to be an adequate compromise
for the two kinds of list-views (tree and list). In the common
usecase mostly dives of a single trip are affected.
Thus, batching of dives is performed in two positions:
- At command-level to batch by trip
- In DiveTripModel to feed batches of contiguous elements
to Qt's begin*/end*-functions.
This is conceptually simple, but rather complex code. To avoid
repetition of complex loops, the batching is implemented in
templated-functions, which are passed lambda-functions, which
are called for each batch.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
insert_trip() adds a trip to the backend, but merges trips if
there exists a trip with the same date. This is a disaster
for the MergeTrips command, because this command adds a new
trip and removes the previous two. Of course if the added trip
is merged, this cannot work.
Therefore, add an insert_trip_dont_merge() function, which
adds the trip, but doesn't merge.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This refactors the undo-commands (which are now only "commands").
- Move everything in namespace Command. This allows shortening of
names without polluting the global namespace. Moreover, the prefix
Command:: will immediately signal that the undo-machinery is
invoked. This is more terse than UndoCommands::instance()->...
- Remove the Undo in front of the class-names. Creating an "UndoX"
object to do "X" is paradoxical.
- Create a base class for all commands that defines the Qt-translation
functions. Thus all translations end up in the "Command" context.
- Add a workToBeDone() function, which signals whether this should be
added to the UndoStack. Thus the caller doesn't have to check itself
whether this any work will be done. Note: Qt5.9 introduces "setObsolete"
which does the same.
- Split into public and internal header files. In the public header
file only export the function calls, thus hiding all implementation
details from the caller.
- Split in different translation units: One for the stubs, one for
the base classes and one for groups of commands. Currently, there
is only one class of commands: divelist-commands.
- Move the undoStack from the MainWindow class into commands_base.cpp.
If we want to implement MDI, this can easily be moved into an
appropriate Document class.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
AddDivesToTrip, CreateTrip, AutogroupDives, RemoveAutogenTrips
and MergeTrips basically all did the same thing as RemoveDivesFromTrip,
which was already implemented. Thus, factor our the common functionality
and hook it up to make all these functions undo-able.
Don't do the autogroup-call everytime the dive-list is rebuilt
(that would create innumberable undo-actions), but only on dive-load /
import or if expressly asked by the user [by switching the autogroup
flag].
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The dive list is fed data by means of a sorted "DiveTripModel".
There are two modes: list and tree. This was implemented rather
elegantly with a general "TreeModel", which can represent trees
of arbitrary depths.
Nevertheless, we have at most two levels and on the second level
only dives can reside. Implementing proper model-semantics
(insert, delete, move) will be quite a challenge and implementing
it under the umbrella of a very general model will not make it
easier.
Therefore, for now, hardcode the model:
At the top-level there are items which may either be a trip
(can contain multiple dives) or a dive (contains exactly one dive).
Thus, we can completely de-virutalize the DiveItem and TripItem
classes, which are now trivial wrappers around dive * and dive_trip *.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The undo-system now guarantees that pointers to dives are stable
throughout their lifetime. Therefore, replace the unique index by
pointers. This is a small performance improvement, but much more
importantly, it will make it more natural to transport a pointer
to the dive inside QModelIndex's private pointer.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The whole undo system assumes that the indexes in the dive table
do not change under its feet. On desktop, there seems only one
exception left: editing of the dive time. To circumvent this,
hook editing of the dive-time to the already existing UndoShiftTime
command.
This introduces a temporary UI-inconsistency: this is the only
edit that is reflected in the undo-list. This will be fixed in
due course, when other edit actions are also made undoable.
UndoShiftTime is changed to take pointers to dives (which should
be stable by now) instead of uniq-ids.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
On dive editing, for every changed field the code looped through
the whole dive-list and modified the selected dives. Instead,
get the list of selected dives once and use that.
Whereas this may look like a gratuitous optimization, it will
make things easier for subsequent commits. Notably, we can
pass the list of selected dives to an "UndoObject".
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Keeping undo-history across load makes little sense. The user was
expressly reminded that they have unsaved work.
For import (from other logs or the dive-computer) an undo-functionality
would be desirable. Nevertheless, this is rather complex since
new and old dives are merged. Implementation would require a finer
backend<->undocommand interface. Thus, leave this for now until more
experience with the undo system is acquired.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
For this, an output-parameter was added to the backend merge_dives()
function. When non-zero, instead of adding the merged dive to
the preferred trip, the preferred trip is returned to the caller.
Since the new UndoObject, just like the delete-dives UndoObject,
needs to remove/readd a set of dives, the corresponding functionality
was split-off in a helper function.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
For this, the core functionality of the split_dive() and
split_dive_at_time() functions were split out into new
split_dive_dont_insert() and split_dive_at_time_dont_insert(),
which do not add the new dives to the log. Thus, the undo-command
can take ownership of these dives, without having to remove them
first.
The split-dive functionality is temporarily made desktop-only
until mobile also supports "UndoObjects".
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Play manual addition of dives via an UndoCommand. Since this does in
large parts the same thing as undo/redo of dive deletion (just the
other way round and only a single instead of multiple dive), factor
out the functions that add/delete dives and take care of trips.
The UI-interaction is just mindless copy&paste and will have to
be adapted.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Both callers have a dive * and transform that into an id,
the callee transforms it right back to the dive *. Simply pass
the dive directly. This will allow us to use the function for
dives that have not yet been added.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The original undo-code was fundamentally broken. Not only did it leak
resources (copied trips were never freed), it also kept references
to trips or dives that could be changed by other commands. Thus,
anything more than a single undo could lead to crashes.
Two ways of fixing this were considered
1) Don't store pointers, but unique dive-ids and trip-ids.
Whereas such unique ids exist for dives, they would have to be
implemented for trips.
2) Don't free objects in the backend.
Instead, take ownership of deleted objects in the undo-object.
Thus, all references in previous undo-objects are guaranteed to
still exist (unless the objects are deleted elsewhere).
After some contemplation, the second method was chosen, because
it is significantly less intrusive. While touching the undo-objects,
clearly separate backend from ui-code, such that they can ultimately
be reused for mobile.
Note that if other parts of the code delete dives, crashes can still
be provoked. Notable examples are split/merge dives. These will have
to be fixed later. Nevertheless, the new code is a significant
improvement over the old state.
While touching the code, implement proper translation string based
on Qt's plural-feature (using %n).
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Disable the Download button when one of the fields vendor, product,
connection is not filled in. The app will crash when trying.
In addition, make the underlying core code to actual download
more safe by checking this, and silently fail instead of crash.
And, yes, this is a double fix in this scenario, but the core code
is used in more places, so better safe than sorry.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
The code to disable a quick button has moved to the DC matching logic,
in order to inactivate the correct button also for USB DCs.
Signed-off-by: Joakim Bygdell <j.bygdell@gmail.com>
Since a known DC will have the name prepended to the BT/BLE addresss
we need to substring match the BT address.
Signed-off-by: Joakim Bygdell <j.bygdell@gmail.com>
By saving the device address together with the vendor and product we fix the
corner case where a user with two DCs would not get quick select buttons if they
where the same vendor and model.
Signed-off-by: Joakim Bygdell <j.bygdell@gmail.com>
For increased maintainability, use the same columns, roles and
the same accessor function for both dive-site models.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The LocationInformationModel added two dummy sites to the front
of the list (add new dive site). This was never used - desktop
uses its own model, mobile only extracts the list of dive site
names with a custom function. Remove this functionality.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Editing of dive sites does not work via this model and the function
was broken anyway (it didn't subtract 2 from the index).
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Under certain conditions the user was presented an ugly
"invalid dive site" message. The condition would arise because
the proxy-model which selects the list of dive sites and the code
which creates a proposed dive site name had different filter
conditions:
- The proxy would select any dive site containing the text
- The name-proposing code searched for dive sites *starting*
with the text.
If the user entered a text contained by a dive site name, but
no dive site would start with the second line was filled with
a dummy text. This text would be kept if it contained the text
entered by the user.
To avoid this problem, if no dive site is found, use an empty
string instead. This will be filtered out by the proxy because
it does not contain the user-entered string.
Yes, that's horribly subtle, therefore add a comment. But ultimately,
this should be solved in a less brittle way.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
On both Mac and Linux cmake 3.12 complained that there were "no sources given
to target" for the Subsurface-mobile target, which made no sense at all (easy
enough to add debug output to ensure there were, in fact, sources given in the
call to add_executable()). But splitting this across two lines like this seems
to make it work both for older and newer cmake versions.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
After the previous commits, we now have a preference that nicely
preserves the state of the UI, and we have the well known git_local_only
global, that is used to denote whether we want to use to local repo
only, or we want to interact with the online cloud as well.
This commit gets rid of the now superfluous syncToCloud logic. Instead
we simply set the git_local_only directly.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
Hook up the new preference to the UI. So now, an earlier choice
if automatic or manual download to the cloud is preserved in
between sessions. Strictly speaking this fixes issue 1725.
Notice that there is also a higly related syncToCloud thing
present. As factoring out that seemingly duplicate piece
of code is non-trivial, this will be done in a seperate
commit.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
With removal of the git_local_only from the preferences (see
ae653703a5), the users choice, in the mobile app, was not
stored any more in between sessions. This resulted in issue
1725.
So, in order to store that user preference, we need a new
preference. This is added here, but its not yet hooked up
in the app yet. This deals only with the preference handling.
And adapted tests are included.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
We disabled the drawer menu button to switch between auto/manual
sync when in no cloud mode. Unfortunately, disabeling does not
give a visual cue to the user (like greyed out). Instead, just
make this button invisable in no cloud mode.
In conjunction a question. The manual sync to cloud menu item
takes you to the Cloud Credetials page in case pressed in
no cloud mode. While valid, this seems strange. This is not
changed in this commit.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
This simple one-liner fixes an actual bug. On switching from
a no-cloud account to a actual cloud account, the dives from
the no-cloud are added to the actual cloud account. And indeed
the dives appear correctly. However, when exiting the app
right away, these added dives are not commited to the local
storage. Simply, the divelist needs to be marked dirty.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
Starting with Xcode 10, system headers are located inside the
macOS SDK.
Add this location to the check for command line tools.
Signed-off-by: Murillo Bernardes <mfbernardes@gmail.com>
The dive site list was connected to centerOnDiveSite(). Apparently,
the currently selected dive site should have been shown in the map.
Yet, this never worked, because the actual dive site of the selected
dive had precedence in centerOnDiveSite().
It seems that centerOnDiveSite() had actually to purposes:
1) center on the passed in dive site
2) center on the dive sites of the selected dives
Therefore, split this function in two separate functions for
each of these use-cases. This allows us to remove some pre-processor
magic (mobile vs. desktop) and to remove a parameter from the
MainTab::diveSiteChanged() signal.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
We bundle our version of libdivecomputer and don't expect Subsurface to work
with a different version, certainly not with something older than 0.5.
I kept the checks for SAMPLE_EVENT_STRING and DC_FIELD_STRING and DC_SAMPLE_TTS
because maybe there's a situation where being able to compile with a current
upstream version is useful.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
In commit bd0c99dfb7 (display pO2 and Setpoint for CCR dives)
the choice was made: when CCR than never a temperature graph.
While this seems reasonable, there is small group of mCCR
divers that do not log their po2 digitally, so the only po2
they can display is the setpoint that is reported by the used
DC. As this is a bit of a dull flat line, most of these
divers do not display this. And this leaves room on the
small mobile display for the temperature data.
So effectively: show temperature or po2 graphs.
Suggested-by: Peter Zaal <pzaal@xs4all.nl>
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
Commit 810903bdb9 ("Import: pass a dive table to process_imported_dives()")
introduced the variables
struct dive *old_dive, *merged;
into process_imported_dives(), but never used them. It seems to be an
artifact of having split the function to use the try_to_merge_into()
helper function (that has those same variable names and _does_ use
them), but forgetting the original variables from the pre-split case.
Gcc understandably warns about it:
core/divelist.c: In function ‘process_imported_dives’:
core/divelist.c:1351:26: warning: unused variable ‘merged’ [-Wunused-variable]
struct dive *old_dive, *merged;
^~~~~~
core/divelist.c:1351:15: warning: unused variable ‘old_dive’ [-Wunused-variable]
struct dive *old_dive, *merged;
^~~~~~~~
and the trivial fix is to just remove that line that declares the stale
and unused variables.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
bperrybap reported on github that the ftdi timeouts can be excessive:
"the timeout period while waiting for read data to be 10x or even 100x
longer than it should be when there are read issues on the data cable
particularly when using Android and USB OTG cables. i.e. a 5 second
read timeout for not receiving data can be as long as 7 minutes"
and the reason is that the code at one point tried to use the regular
"gettimeofday()" to handle timeouts, but that doesn't exist in Windows.
We already have Windows-specific code to sleep for a number of
milliseconds in "ftdi_serial_sleep()", let's just extend that same
concept and add a "ftdi_serial_get_msec()" that returns the number of
msec's since some arbitrary point in time.
On Windows, that's just "GetTickCount()", and in sane environments it's
just a trivial wrapper around gettimeofday() to turn sec/usec into msec.
NOTE! The actual msec value doesn't have any meaning. Only the
difference between two calls to ftdi_serial_get_msec() is meaningful.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Some divecomputer backends (ok, right now really only the Aqualung i770R
and i300C) want to know the bluetooth name of the dive computer they
connect to, because the name contains identifying information like the
serial number.
This just adds the support for that to our Qt BLE code.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
More specifically, don't upload them from the old Windows build - we
just keep that one around for the smtk2ssrf binaries. The Subsurface
binaries are now created in the container based Windows build.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This still doesn't seem to work as expected and needs more testing.
Also, it can be turned off via command line argument
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
I expect this to become the default way to test Windows builds and
create installers on Travis. The idea is that instead of downloading the
pre-built MXE binaries we might as well use a container that has all
this installed and can be used locally to test if things fail on Travis;
which will allow us to have the exact same environment for testing
locally as runs on Travis.
At this point the container used is way too big - more effort needs to
be spent on shrinking it.
Right now this only deals with Subsurface and not with smtk2ssrf.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
That qmake -query was added for debugging a long time ago.
Since the comment clearly indicate that the edit of the Makefile is only
for Travis, let's only do it when running on Travis.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
It wasn't documented in the first place (magic first argument, anyone?).
This used to be available for quite a few of the dependency and had
somehow kept around only for Grantlee and Googlemaps. Let's just kill
this and be consistent for all dependencies.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>