Commit graph

388 commits

Author SHA1 Message Date
Dirk Hohndel
5edcf2aea2 cmake: move maplocationmodel to generic models
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-03-22 07:33:41 -07:00
Berthold Stoeger
d1572a8d95 Cleanup: introduce copy_qstring() function
strdup(qPrintable(s)) and copy_string(qPrintable(s)) were such common
occurrences that they seem worthy of a short helper-function.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-14 13:55:36 +02:00
Berthold Stoeger
b72cc1f317 Cleanup: consistently use qPrintable()
Replace constructs of the kind
  s.toUtf8().data(),
  s.toUtf8().constData(),
  s.toLocal8Bit().data(),
  s.toLocal8Bit.constData() or
  qUtf8Printable(s)
by
  qPrintable(s).

This is concise, consistent and - in principle - more performant than
the .data() versions.

Sadly, owing to a suboptimal implementation, qPrintable(s) currently
is a pessimization compared to s.toUtf8().data(). A fix is scheduled for
new Qt versions: https://codereview.qt-project.org/#/c/221331/

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-14 13:55:36 +02:00
Lubomir I. Ivanov
9a6cd451e2 cmake: update CMake to build the map components on mobile
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2018-03-11 11:40:12 -07:00
Stefan Fuchs
93ddcce6fa Cleanup: Remove superfluous QString constructions in divetripmodel.cpp
Remove superfluous QString constructions in a couple of simple functions
in divetripmodel.cpp

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-03-05 16:28:18 +01:00
Stefan Fuchs
aacc688670 Use correct numeric format based on selected locale (Qt domain part)
This changes the numeric format of many values printed to the UI to
reflect the correct numeric format of the selected locale:
- dot or comma as decimal separator
- comma or dot as thousands separator

In the Qt domain the `L` flag is used case specific mostly
in qthelper.cpp.
Then the helper functions get_xxx_string() are used more consistently.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-03-05 16:28:18 +01:00
Stefan Fuchs
4cbf8b87a3 Updated strategy for removing cylinders
Change the strategy when to allow cylinder removal from a dive:
- Not remove when cylinder has gas switch events, in any other cases
  allow removal
- Remove this whole "cylinder with same gas" thing being a criteria
  for cylinder removal

When removing a cylinder which has corresponding pressure info in
samples, also remove this pressure info from the samples.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-02-27 09:17:57 +01:00
Stefan Fuchs
95a23cf470 Use temperature_t for temperatures in struct stats_t
Use struct temperature_t for temperatures in struct stats_t and
use get_temperature_string() when printing these temperatures for
statistics and HTML export.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-02-24 11:45:17 -08:00
Berthold Stoeger
5c248d91cd Coding-style: remove superfluous parentheses
Mostly replace "return (expression);" by "return expression;" and one
case of "function((parameter))" by "function(parameter)".

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-02-17 19:38:52 -08:00
Oliver Schwaneberg
218ea94831 Bugfix in plannermodel for very short dive durations
When adding a dive manually, you might clear the "duration" field and fill
in your value by hand. Unfortunately, commit #1052 produced a bug that
practically limited the dive duration to 6 minutes once the field was cleared.

Signed-off-by: Oliver Schwaneberg <oliver.schwaneberg@gmail.com>
2018-02-07 09:22:15 +01:00
Jan Mulder
494ad26540 mobile cleanup: restyle construction of locationlist
See also e6e1473e6. The construction of the locationlist
was not the same as the 3 previous lists, and it needs
the inclusion of a new model file (divelocationmodel.cpp)
in the mobile app. In addition, as the mobile app is mainly
interested in a simple stringList (model) to populate a HintsText
field (or maybe later a combobox), this stringlist is added
to the model, to easy interfacing with QML.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-01-31 14:48:14 +01:00
Jan Mulder
fed2c5b6a1 mobile cleanup: unduplicate code and do not loop over dives (1)
This is the first of a set of commits that are (very) similar.
It appeared that a number of more or less static lists, which are
constructed by a loop over all dives in the logbook, were executed
when changing focus to a next dive. For example, the in this
commit addressed list of used dive suits.

What was wrong was that the suitList was linked to a dive. There
is only a need to construct the list of used suits when data is
changed (and obviously, once on startup of the app). Further, it
appeared that a lot of code was duplicated and that we can use
(in this case) the same code from the desktop completionmodels.cpp.

Basically, this commit involves the following changes:
- include completionmodels.cpp in mobile and desktop (so move
it from the desktop only category to the generic category).
- remove double code from DiveObjectHelper.cpp
- Do not differentiate in the init phase and the normal refresh
of the list
- the per dive logic is now only the getting of a previously
constructed list (in init or update of the divelist).

There are no visible changes in the UI, other than a better
performance when scrolling over dive details.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-01-31 14:48:14 +01:00
Robert C. Helling
6d3c2327bd Initialise cylinder start pressure with working pressure
In the planner, this is the natural assumption.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-01-26 07:04:45 +01:00
Willem Ferguson
9a8bab21c9 Improve profile display in planner
This patch allows the planner to save the last manually-entered
dive planner point of a dive plan. When the plan has been saved
and re-opened for edit, the time of the last-entered dive planner
point is used to ensure that dive planning continues from the same
point in the profile as was when the original dive plan was saved.
Mechanism:

1) In dive.h, create a new dc attribute dc->last_manual_time
   with data type of duration_t.
2) In diveplanner.c, ensure that the last manually-entered
   dive planner point is saved in dc->last_manual_time.
3) In save-xml.c, create a new XML attribute for the <divecomputer>
   element, named last-manual-time. For dive plans, the element would
   now look like:
   <divecomputer model='planned dive' last-manual-time='31:17 min'>
4) In parse-xml.c, insert code that recognises the last-manual-time
   XML attribute, reads the time value and assigns this time to
   dc->last_manual_time.
5) In diveplannermodel.cpp, method DiveplannerPointModel::loadfromdive,
   insert code that sets the appropriate boolean value to dp->entered
   by comparing newtime (i.e. time of dp) with dc->last_manual_time.
6) Diveplannermodel.cpp also accepts profile data from normal dives in
   the dive log, whether hand-entered or loaded from dive computer. It
   looks like the reduction of dive points for dives with >100 points
   continues to work ok.
The result is that when a dive plan is saved with manually entered
points up to e.g. 10 minutes into the dive, it can be re-opened for edit
in the dive planner and the planner re-creates the plan with manually
entered points up to 10 minutes. The rest of the points are "soft"
points, shaped by the deco calculations of the planner.

Improvements: Improve code for profile display in dive planner

This responds to #1052.
Change load-git.c and save-git.c so that the last-manual-time is
also saved in the git-format dive log.

Several stylistic changes in text for consistent C source code.

Improvement of dive planner profile display:

Do some simplification of my alterations to diveplannermodel.cpp

Two small style changes in planner.c and diveplannermodel.cpp
as requested ny @neolit123

Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-01-19 12:38:11 +02:00
Berthold Stoeger
6a07ccbad2 Use helper function empty_string() instead of manual checks
For code consistency, substitute boolean expressions:
 s && *s     -> !empty_string(s)
 s && s[0]   -> !empty_string(s)
 !s || !*s   ->  empty_string(s)
 !s || !s[0] ->  empty_string(s)

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-11 06:07:13 +01:00
Berthold Stoeger
e85ecdd925 Introduce helper function empty_string()
There are ca. 50 constructs of the kind
  same_string(s, "")
to test for empty or null strings. Replace them by the new helper
function empty_string().

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-11 06:07:13 +01:00
Jan Mulder
34bc4fc0af Pictures tied to profile are not supported on mobile
Move divepicturemodel.cpp to the desktop only category and deal
with the (limited) fallout. We, currently, do not support dive
pictures tied to the profile on mobile, so there is no use
including this code.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-01-10 21:28:02 +01:00
Jan Mulder
9c01315d31 Un-tie plannner model from profile on mobile
Do not pull in the DivePlannerPointsModel::instance as this is not
used in the called function. We (currently) do not support deco
computations on mobile, so trying to pull in any deco state from
the planner is futile anyway.

With this uncoupling, 6 more model files are not needed in mobile
any more.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-01-10 21:28:02 +01:00
Berthold Stoeger
85ac3106e6 Typo: indice -> index
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-10 21:25:02 +01:00
Jan Mulder
6193aef9ac mobile: fix crash on delete dive from divelist
This is a somewhat hacky commit. For a very long time, the delete
from the divelist on mobile crashed. That is, not always for anyone,
but for me almost consistently. This commit tries to solve it.

I found that trying to save the delete immediately after removing
data from the underlying model seemed to cause the crash. Hacking
around, I found that a simple beginResetModel/endResetModel between
the delete of the underlying model data and actual save is
sufficient to solve the crash.

The big question is, why does this all work? I suspect some of race
condition between deleting model data, and giving the QML engine
the opportunity to do its thing.

This is also related to issue #311, but that is not implemented
here.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-01-10 20:34:16 +01:00
Jan Mulder
53221ffd8e Unused code: GpsListModel::addGpsFix()
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-01-10 16:45:42 +01:00
Jan Mulder
1d7fc93017 Unused code: remove CCRMax() and used macro
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-01-10 16:45:42 +01:00
Jan Mulder
c8e9b93404 build system: split qt-models into parts
For a long time, I did not realize that a lot of qt-models are only
used in the mobile app, or only used in the desktop application.

This commit splits the qt-models in 3 parts. Used in both mobile and
desktop, used in desktop only, used in mobile only.

There is no other code change in here, other than cmake changes.

To me, this gives at least developers more insight where code is
actually used, and there is a small benefit in footpoint.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-01-10 16:44:15 +01:00
Jan Mulder
8928e54dfc Move function to proper place
Instead of writing TODO comment blocks, just do the work, and move the
function to the proper class. Further, after review from Berthold, cleanup
the function. There is no reason that getGasList() is member of
any class. It is just a non-class helper, and as it is only used
here, a static helper.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-01-10 11:04:24 +01:00
Jan Mulder
04626b0891 Fix small memory leak
When deleting a dive from the divelist model, also free the
pointed to DiveObjectHelper data. There seems no harm done
(other than a memory leak) by this missing free.

Found while (again) investigating the infamous crash occuring
when deleting a dive from the mobile app when deleting a dive
from the dive list.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-01-07 13:02:27 +01:00
Jan Mulder
75142b0a63 cleanup: less than operators shall not use equal
See also commit c032006d91. Compare functions passed
to sort functions need to compare for less-than and not
less-or-equal.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-29 13:16:58 -08:00
Jan Mulder
57e701f10e cleanup: Uninitialized scalar field
CID 45184

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-28 17:30:25 +01:00
Jan Mulder
803759efea cleanup: Uninitialized scalar field
CID 208317
CID 208325

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-28 17:30:25 +01:00
Jan Mulder
1ce9b5bb9a cleanup: Logically dead code
CID 208318

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-28 17:30:25 +01:00
Jan Mulder
6fa23f74f7 cleanup: Argument cannot be negative
CID 208296. IndexOf can return -1 when not found, which will
not happen in this context, so just to silence Coverity.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-28 17:30:25 +01:00
Jan Mulder
2a58be6649 filter: fix trip header bug
With commit 5962f00679, a well known problem was introduced.
Incorrect width setting for the spanning trip lines. And as there
is even a specific functon for that, just call this.

The reason the mentioned commit introduces this, is that
invalidate() causes layoutChanged signals, and invalidateFilter()
does not.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-28 17:30:13 +01:00
Jan Mulder
522b922d2a filter: setStringList() at end of every change
This is mainly code maintenance. Instead of emitting explicit
dataChanged signals, we can make sure that setStringList()
is called after all model data manipulation is ready. Accoording
to the Qt docs: "The model will notify any attached views
that its underlying data has changed".

In itself, this does not solve the tripped assert mentioned in
commit 5962f00679, but this calling at the end just feels
better.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-28 17:30:13 +01:00
Jan Mulder
97d564e920 filter: prevent assert trap on exit filters
This "bug" is found using Qt 5.10 compiled in developer mode. Access
the filers, click a little around here, close the filters. Almost every
time the following assert is triggered:

ASSERT failure in QPersistentModelIndex::~QPersistentModelIndex:
"persistent model indexes corrupted", file itemmodels/qabstractitemmodel.cpp, line 643

This is relatively deep down in Qt, and it is triggered by clearing the
filters. Trying to force a crash when using the same scenario in Qt 5.10
compiled for production (so no active asserts) did not result in a crash.
So, upto this time, it is unclear if the Qt assert points out a real problem,
or it is some false alarm (for whatever reason).

Further investigation shows that the assert can be solved by changing the
invalidate() to an invalidateFilter(). Indeed, the last variant is a little
more lightweigt, and does seem to do the same job from a functional point
of view (in this case).

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-28 17:30:13 +01:00
Berthold Stoeger
c3b1c64183 Remove unnecessary dynamic_cast<>s in filter code
FilterModelBase is a direct subclass of QAbstractItemModel. Therefore,
dynamic_cast<>ing the former to the latter is unnecessary. Probably
an artifact of previous code.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-28 09:11:12 +01:00
Dirk Hohndel
652e382e68 Cleanup: avoid a few memory leaks
Coverity CID 215199
Coverity CID 215195
Coverity CID 215196
Coverity CID 215198

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-26 13:41:58 -08:00
Berthold Stoeger
b6bf57a13b Introduce negate-toggle buttons to filter lists
Introduce toggle buttons which mean "filter all dives except
those fulfilling the selected criteria".

The old code used to check for rowCount() == 0. This should never happen,
because there is always a row "empty field". This check was moved into
the preamble of the functions to seperate it from the actual logic.

Fixes #435

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-26 13:08:49 -08:00
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