Commit graph

352 commits

Author SHA1 Message Date
Berthold Stoeger
130f109442 Remove superfluous QScopedPointer<>s in singletons
There was a curious pattern of singletons being implemented based on
QScopedPointer<>s. This is an unnecessary level of indirection:
The lifetime of the smart pointer is the same as that of the
pointed-to object. Therefore, replace these pointers by the respective
objects.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-24 11:04:10 -08:00
Dirk Hohndel
eec69de7ab Small whitespace updates
We aren't really consistent. And I don't do this often enough. But based
on a few things that I saw in a recent commit, I wanted to at least fix
those. And then of course fixed everything in those two files.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-24 09:10:12 -08:00
Jan Mulder
dbcf044b93 beginInsertRows requires last >= first
Found while compiled against Qt 5.10 build from source. The assert
Q_ASSERT(last >= first) is trapped by this beginInsertRows in
case there are no pictures. Just do not call this when there are
no pictures.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-24 08:25:21 -08:00
Berthold Stoeger
7451517e4a Add select-all, deselect-all and invert-selection options to filters
To every filter list add a menu button that allows selection of all,
selection of none or inversion of selection.

Implements #435.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-24 08:24:11 -08:00
Berthold Stoeger
668635e98e Move *FilterModel functions into base class
The *FilterModels had a number of of virtual functions, which only
accessed members of the base class. Moreover, these functions were
identical and generated with macros. Therefore, move these functions
to the base class.

The one excption is data(), which uses different count functions
(passed as a macro parameter). Thus, introduce a virtual countDives()
function and likewise move data() to the base class. A function pointer
might be even more clear, but since the rest of the code/Qt relies
heavily on runtime polymorphism, let's do the same here.

The only macros left are those creating the singleton accessors.
This could be more clearly realized by templates, but let's
likewise keep it the way is.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-24 08:24:11 -08:00
Berthold Stoeger
7eed752ba1 Fold MultiFilterInterface into FilterModelBase
There were two classes, MultiFilterInterface and FiterModelBase.
The latter derives from the former and from QStringListModel.
The former was not used anywhere else. Moreover, in contradiction
to its name, MultiFilterInterface is not an interface (in the Java
sense), because it actually has (non-virtual) data members. All in
all, the data model is very weird.

Merge these two classes, since there seems to be no gain whatsoever
from keeping MultiFilterInterface separate.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-24 08:24:11 -08:00
Stefan Fuchs
603e43f46e Use function emitDataChanged in diveplannermodel consistently
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-12-24 00:01:39 +01:00
Stefan Fuchs
d703ba99c1 Simplify update of gflow and gfhigh values in the code
The more complex handling is no longer needed because:
- Keyboard tracking for gfhigh/low UI fields was switched off here:
  030c094854
- GFhigh was limited to 40 here:
  53fffe0ce3

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-12-24 00:01:39 +01:00
Stefan Fuchs
4db9f5dbbd Correcty typo ghflow -> gflow in diveplannermodel.cpp
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-12-24 00:01:39 +01:00
Berthold Stoeger
935fb3c3df Fix BuddyFilterModel
Commit 6343515fed introduced equality
instead of substring comparison for filters. This broke the buddy
filter in the case of more than one buddy, because in such a case
the buddy list is a comma-separated string.

Fix this by splitting the buddy string, trimming the individual
strings and search in the list.

Fixes #969

Reported-by: <yrevawerd@gmail.com>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-21 21:09:35 +01:00
Berthold Stoeger
05a1626c7e Implement different zoom levels for dive photos tab
This implements different zoom levels for the dive photos tab as
suggested by Stefan Fuchs <sfuchs@gmx.de> in #898.
The zoom level can be changed using a slider or CTRL+mousewheel.
Zoom levels range from a third of the standard thumbnail size to
thrice the standard thumbnail size.

Thumbnails are cached in maximum resolution and scaled down on
the fly. Because the profile widget took its pictures from the
photo list model, an extra picture copy with a fixed size had
to be introduced.

The UI is still a bit crude.

Reported-by: Stefan Fuchs <sfuchs@gmx.de>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-18 12:07:10 -08:00
Berthold Stoeger
0d01c70f3a Make protected DivePictureModel members private
The constructor and the list of pictures was protected, but the
class neither had friends nor subclasses (a subclass was removed
in a recent commit).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-18 12:07:10 -08:00
Berthold Stoeger
2f5f1e036e Make scaleImages() a static function
It was only used by the DivePictureModel class, no need to export it.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-18 12:07:10 -08:00
Stefan Fuchs
2890be9256 divepicturemodel: Reset start and end row for displayed_dive correctly
Correct way of using indices for rowDDstart and rowDDend.
Reset rowDDstart and rowDDend at beginning of updating dive pictures.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-12-15 09:11:28 -08:00
Jan Mulder
dd87350cb7 mobile: stay on same dive after edit
See issue #875. In hindsight the reason for this bug is easy to
understand. When updating a dive, the dive was first removed
from the model, and added in its new state again. This does seems
resonable, but the delete in the model causes the internal (QML)
state to be changed, and the previous state (like the currentIndex
that was pointing to the just deleted row, so that one is changed to
something valid internally) is not restored at recreation of
the edited dive. The QML engine has no way to understand that
the remove and subsequent add are in fact one atomic operation.

This can be solved by simply updating the underlying data in
place, and notifying the change using a dataChanged emitted
signal. The dataChanged signal takes care of the repaint of
the screen, and there is no need for removeRow/insertRow pairs.

Fixes: #875

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-14 08:53:06 -08:00
Stefan Fuchs
82170579ad Enable removal of pictures from different dives at the same moment
Suggested-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-12-13 05:48:20 -08:00
Stefan Fuchs
5b7e4c57f7 Dive pictures show pictures of all selected dives
In the dive picture tab show pictures of all selected dive.
But at the same moment take care that in the profile only
pictures from displayed_dive are displayed.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-12-13 05:48:20 -08:00
Stefan Fuchs
a11622623a Remove unused divesitepicturemodel from qt-models
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-12-13 05:48:20 -08:00
Berthold Stoeger
c3c5256dc4 Remove outdated comment
The removed comment in qt-models/divepicturemodel.h described
todo items which were already implemented.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-10 15:00:53 +01:00
Berthold Stoeger
92ad7865d0 Make thumbnail code threadsafe
The thumbnailing in qt-models/divepicturemodel.cpp was performed
concurrently, but the thumbnailCache was not protected from races.
Resolve this by guarding the thumbnalCache accesses with mutexes.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-10 15:00:53 +01:00
Berthold Stoeger
c73828d605 Simplify DivePictureModel
The code of DivePictureModel used a QHash to keep track of thumbnails.
Not only was the code rather complex - it also had the consequence that
pictures are sorted according to the hash function, i.e. seemingly
random.

This commit replaces the QHash by a simple QList which keeps track
of thumbnails and some meta-data.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-10 15:00:53 +01:00
Berthold Stoeger
a07d3b7bfe Whitespace fixes in qt-models/divepicturemodel.cpp
Note that constructs like QList<QFuture<void>> is incompatible with
pre-C++11 compilers. But the code base is so full of C++11isms that
we may just as well remove asymmetric eye-sores of the kind
"QList<QFuture<void> >".

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-10 15:00:53 +01:00
Dirk Hohndel
03b02c9352 Cleanup: mark parameter as potentially unused
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-08 16:29:49 +01:00
Stefan Fuchs
de26a50ba3 In planner variations use variables for delta values
Plus a small layout change: Add a colon behind "Stop time".

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-12-02 20:48:02 +01:00
Stefan Fuchs
1bd2f3fe3e Planner variations stop time calculation cover all stops
Simplify the sum up of the deco stop times for analysis of
the planner variations.

Plus rename define for deco stop variations debug output

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-12-02 20:48:02 +01:00
Robert C. Helling
c38e0f225f Remove unnecessary #include and correct whitespace
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-12-01 15:47:51 -08:00
Robert C. Helling
511ee9ddeb Change #include line to make Linux builds happy
Let's see if this helps the Linux build on TravisCI.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-12-01 15:47:51 -08:00
Robert C. Helling
d8350ef238 Document background computation of variations
Update changelog, update user manual, clarify
meaning in dive notes.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-12-01 15:47:51 -08:00
Robert C. Helling
4d605ce51f Prevent redundant replanning
Planning dives is heavy on CPU, so better be sure we only
do it when needed. In particular, when moving around dive
points, we only want a new plan once per move and not three
times (triggered at various points in the chain of events).

This should significantly improve planner snappiness.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-12-01 15:47:51 -08:00
Rick Walsh
1985bcb29e Disable plan variation in recreational mode
Calculating variations when in recreational mode doesn't make sense, and can
prevent variations from being calculated when switching back to Buhlmann or
VPM-B modes.

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
2017-12-01 15:47:51 -08:00
Robert C. Helling
41b4e4a19a Add imperial units to variations computation
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-12-01 15:47:51 -08:00
Robert C. Helling
0839342d33 Don't block profile updates in variations computation
We needed to prevent updates when we messed with the
diveplannerpointsmodel as those would trigger
starting planning from scratch causing infinite loops.

Now, the variations calculation operates on a copy of
the diveplan, so the model is no longer involved and
we should not block recalculations (as those might be
triggered by the UI).

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-12-01 15:47:51 -08:00
Robert C. Helling
1e678d52b2 Make background calculation optional
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-12-01 15:47:51 -08:00
Robert C. Helling
a9703628c4 Actually compute variations in background
This reenables the computation of plan variations but now in a separate
thread. Once finieshed, a signal is sent to update the notes.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-12-01 15:47:51 -08:00
Martin Měřinský
8ef87e618a Use better aliases for icons.
Icon aliases were complete mess.
Some icons had alias some didn't.
Named with underscores vs. hyphens vs. camelCase.
Lower vs. upper case.
"ICON" prefix vs. suffix vs. nothing.
With vs. without filename suffix.
Some didn't make sence. Eg. mapwidget-marker-gray
(I can see, it's grey, but what does it represent?)
Some were duplicated, eg warning vs. warning-icon.
Some were name after widget, which is wrong.

Do not reinvent wheel. Use widely used naming scheme
close to Freedesktop Icon Naming Specification. This
will enable usage of common icons from current set in
the future. Thus Subsurface will fit nicely to GUI.

This changes icon aliases to one, easy grep-able style.

Signed-off-by: Martin Měřinský <mermar@centrum.cz>
2017-11-30 23:14:46 -08:00
Dirk Hohndel
2747056889 Revert "Use consistent aliases for all icons."
This reverts commit 92e9c6606f.
2017-11-29 14:05:07 -08:00
Martin Měřinský
92e9c6606f Use consistent aliases for all icons.
Icon aliases were inconsistent mess. Underscores vs. hyphens vs. camelCase.
With vs. without filename suffix. Lower vs. upper case. "icon" suffix vs.
prefix vs. nothing. Some were duplicated, eg warning vs. warning-icon. Some
icons didn't have alias at all.

This changes all icon aliases to one, easy grep-able style which complies
to Freedesktop Icon Naming Specification (Guidelines).

Signed-off-by: Martin Měřinský <mermar@centrum.cz>
2017-11-29 11:46:35 +01:00
Stefan Fuchs
8a92484b0c Add debug function dump_cylinders
This function can be used to dump print all cylinder data.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-11-27 22:40:16 +01:00
Berthold Stoeger
24c72cb359 Inform LocationFilterModel of added dive site name
If the user implicitly adds a dive site by editing a dive, and
a location filter is active, check the new dive site in the
location filter.

This is done by informing the LocationFilterModel of the new
dive site name prior to repopulation. The LocationFilterModel
then adds a corresponding entry and marks it as checked.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-11-26 18:50:40 -08:00
Berthold Stoeger
f4bcdf46aa Inform LocationFilterModel of changed dive site name
Since commit 01d961086c, the location filter
list is updated if a dive site is edited. The problem is that if the
name of a selected dive site is changed, the selection is lost.

Therefore, before repopulating, inform the location filter that a dive
site changed its name. The location filter then internally changes the
name and can properly transfer the old selection on repopulate. This is
performed via the new LocationInformationWidget::nameChanged signal,
which is connected to the new LocationFilterModel::changeName slot.

A special case to be handled is the following:
 [ ] Site 1
 [x] Site 2
and "Site 2" being renamed to "Site 1", i.e. both sites being merged.
Here, the merging is detected and "Site 1" will likewise be checked:
 [x] Site 1
 [x] Site 1
No merging is performed, as the list will be repopulated anyway.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-11-26 18:50:40 -08:00
Berthold Stoeger
bf65f1e507 Fix comparison function in qt-models/divelocationmodel.cpp
The function dive_site_less_than() in qt-models/divelocationmodel.cpp
does not what it promises: it uses less-or-equal instead of less-than
comparison.

Note that, even though this may sound pedantic, this is an actual bug.
Usually, sorting functions suppose that they are provided with
strict weak ordering, which <= does *not* provide.

This is the actual reason for the crash mentioned in commit
f8a3a85210.

While touching this function, make it of static linkage, since
its usage is local to this translation unit.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-11-26 18:49:05 -08:00
Berthold Stoeger
d1545b27b4 Remove unused method LocationInformationModel::addDiveSite()
The call to this method was removed in commit f4c31f110f

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-11-26 23:37:01 +01:00
Berthold Stoeger
6343515fed Use equality instead of substring comparison in suits and buddy filter
This commit is a continuation of commit 739b27427c,
in which a substring comparison was replaced by equality comparison to
avoid confusing UI behavior of the filter interface.

The suit and buddy filters were plagued by the same problem, so change
their code in analogy.

Fixes #551 (in conjunction with commit dd2466f518).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-11-25 15:41:55 -08:00
Robert C. Helling
088db5e12b Hand planner variables to profile
Pass the planner state struct to the profile computation so it can use
deco_time and first ceiling to display VPM-B ceiling.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-11-25 20:13:01 +01:00
Robert C. Helling
8e21a65653 Localize global planner state
For UI responsiveness, we need to be able to run the planner in the background. This needs the
planner state to be localized (and we need to pass a pointer around).

In order to not let too many lines overrun (and to save typing in the future)
I have renamed instances of struct deco_state to ds. Yes this should have gone
to a separate commit but I accidentally commit --amend'ed it.

Computing of planner variations is temporarily disabled.

Unlock the planner when returning early

So we don't deadlock in add dive and recreational mode (which
use the planner without actually planning).

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-11-25 20:13:01 +01:00
Robert C. Helling
a9ceecc2e3 Run variations calculation in background
but there are still side effects and thus it crashes.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-11-25 20:13:01 +01:00
Berthold Stoeger
dd2466f518 Update filters on refreshDisplay and remember old selecttions
Update the filters if the list of dives is updated by calling
MultiFilterSortModel::instance()->myInvalidate();
This had the side effect of clearing all selections. Thus, in
the repopulate() methods of the FilterModels, check those
entries that were checked previously. Since all the filter
models use the same code, introduce a base class FilterModelBase.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-11-25 08:24:36 -08:00
Berthold Stoeger
4da6a0a732 Replace bool * array by std::vector<char> in MultiFilterInterface
This replaces a dynamically allocated array of bool by std::vector<char>.
1) This makes the code shorter and less error prone, because memory
   management has not to be done by hand.
2) It fixes a bug in the old code:
   memset(checkState, false, list.count()) is wrong, because bool is
   not guaranteed to be the same size as char!

Two notes:
1) QMap<>, QVector<>, etc. are used numerous times in the code, so
   this doesn't introduce a new C++ concept. Here, the std:: version
   is used, because there is no need for reference counting, COW
   semantics, etc.
2) std::vector<char> is used instead of std::vector<bool>, because
   the latter does a pessimization where a bitfield is used!

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-11-25 08:24:36 -08:00
Berthold Stoeger
739b27427c LocationFilter: use equality instead of substring comparison
The location filter used a substring comparison, which had
the side effect that dives with the location "Test 1" were
shown when filtering for "Test 12".

Moreover, avoid a deep copy of the location list. This is
done by looping over one item less than rowCount() instead
of removing the last item. While doing this, remove an
unnecessary if-statement.

This commit partially fixes #675.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-11-25 08:24:36 -08:00
Dirk Hohndel
ba773c811f Only call autogroup when it's enabled
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-11-25 08:12:28 -08:00