Commit graph

213 commits

Author SHA1 Message Date
Berthold Stoeger
2d7be7a0e3 preferences: create global settingsChanged signal
So far, the PreferencesDialog emitted a settingsChanged signal.
This meant that models that listened to that signal had to
conditionally compile out the code for mobile or the connection
had to be made in MainWindow.

Instead, introduce a global signal that does this and move
the connects to the listeners to remove inter-dependencies.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-12 15:52:40 -08:00
Berthold Stoeger
71389cfa92 cleanup: remove empty function MainTab::reload()
This used to reload the completion models. Moreover, remove two
obsolete member-function declarations.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-11-14 10:01:50 -08:00
Berthold Stoeger
38a784f5af desktop: automatically reload completion-models
Instead of programatically reload the completion models, listen
to the relevant signals in the models. To that goal, derive all
the models from a base class.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-11-14 10:01:50 -08:00
Berthold Stoeger
b390fb368d desktop: update completion models if dive was edited
In the main-tab, when changing tag, buddy or divemaster,
update the corresponding completion model.
This is a quick-fix and the wrong thing to do. It works only
if the currently shown dive is changed, which is not a given.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-11-12 11:22:12 -08:00
Dirk Hohndel
be3190db8a revert preference settings for title color
Because of subsequent changes there is no clean way to just revert the changes
introduced in commit 8b36cf1051 ("desktop: offer different colors for info tab
titles"), so this manually removes the parts we don't need anymore.

This also restores a tooltip value that was inadvertantly removed in that
commit.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-11-04 14:51:55 -08:00
Dirk Hohndel
6201ac34b4 desktop: automatically pick a good theme title color
The preference setting seemed far too strange to do this. And not very user
friendly. So instead we figure out if this is a dark theme or not by looking at
text and background colors in the palette, and make sure we get notified if
that changes.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-11-04 14:47:10 -08:00
Dirk Hohndel
814cda7183 desktop: generalize the colorization of the tab widget
Instead of doing it just for the Information tab, do it for all of the tabs.
There's still room for improvement. But this certainly feels more consistent.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-11-03 23:08:39 -08:00
Dirk Hohndel
7d18a525f1 desktop: allow update of tab widget colors at run time
Adding a new virtual function to all of these classes may seem like overkill,
but of course the idea is that likely we'd allow similar changes to all of
them.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-11-03 23:08:39 -08:00
Berthold Stoeger
7c70459f6c cleanup: remove unnecessary includes from maintab
These are artifacts from when the maintab contained more stuff.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-28 11:27:58 +01:00
Berthold Stoeger
fa7dfa3710 desktop: add tab-widget for dive computer names
If we want to include dive computer names in the undo system,
there should be visual feedback on undo/redo.

This would mean opening the divecomputer dialog, which would
appear quite strange. Therefore, add a tab. This is not ideal,
but consistent with the dive site tab, which probably shouldn't
be there either. In the future, the UI needs some rethinking.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25 13:59:04 -07:00
Berthold Stoeger
8f80129bac cleanup: create common QDateTime -> timestamp conversion function
In analogy to the timestamp -> QDateTime conversion, create a
common function.
1) For symmetry with the opposite conversion.
2) To remove numerous inconsistencies.
3) To remove use of the deprecated QDateTime::toTime_t() function.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-22 12:31:06 -07:00
Berthold Stoeger
f63485b444 cleanup: move timestampToDateTime() to qthelper.cpp
Move this function from maintab.cpp to qthelper.cpp. Since the
functionality was used in numerous places, use the helper function
there as well. This removes a number of inconsistencies. For example,
sometime setTimeSpec(Qt::UTC) was called, even though the
QDateTime object was already created with that time spec.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-22 12:31:06 -07:00
Berthold Stoeger
00ff63f186 desktop: update date and time fields if user changes format
This was more painful than expected, because we get the "preferences"
changed signal too early when the user switches to system format.
The correct format is set by the preferences-widget, not the preferences
subsystem.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-22 10:00:43 -07:00
Berthold Stoeger
ce7cc79705 desktop: hide/unhide tags if dive site was edited
The tags of the dive site were shown/hidden when changing the
current dive.

Thus the following could happen:
1) User changes to dive with no tags. Tags are hidden.
2) User add image, which creates GPS tag
3) Tag is updated but not shown.

Fix this by showing/hiding tags when they are calculated not
when switching the dive.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-08 08:51:37 -07:00
Berthold Stoeger
1c590783e0 cleanup: free tab-widgets when exiting the application
This is completely irrelevant, however out of principle,
let's free the tab-widgets at the end of the application.
To do so, use Qt's object hierarchy. I'm not a fan of this
kind of memory management, but it is how it is.

Moreover, remove the explicit constructor of MainTab, since
it doesn't differ from the default constructor anyway.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-05-07 08:56:59 -07:00
Berthold Stoeger
c139c16c03 cleanup: remove clearing of displayed_dive in MainTab constructor
Clearing displayed_dive here makes no sense for two reasons:
1) This is only called on startup, when displayed_dive is not
   yet initialized.
2) The tab-widgets don't use displayed_dive anyway.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-05-07 08:56:59 -07:00
Berthold Stoeger
532449644e desktop: update tab info only if current_dive is set
If current_dive was not set, the code would clear the tabs
right after updating the data. We might just as well set the
data only if current_dive is set.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-05-07 08:56:57 -07:00
Berthold Stoeger
c50e58d761 desktop: avoid spurious undo commands for date/time editing
The date and time fields of the main tab posted undo events
for every date/timeChanged signal. Thus, when changing the
day of the month to e.g. 21, this would result in two date
change events: one to the 2nd and one to the 21st. This is
very irritating.

Instead listen to editingFinished() events, which thankfully
exist for these widgets.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06 13:19:57 -07:00
Berthold Stoeger
769915f3fe selection: create global single_selected_trip() function
The DiveListView had a singleSelectedTrip function that
returns the selected trip if exactly one trip is selected.
This could be very slow if numerous non-trip items were
selected, because all the selection indices were back-
translated by the proxy model.

This could make selection changes very slow, because the
MainTab used said function to determine whether it should
show trip or dive data.. Indeed, with a 3500 dive test log,
when selecting all dives in tree mode, the updating of the
TabWidgets is sped up from 130 ms to 5 ms this commit.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-03 15:02:21 -07:00
Berthold Stoeger
2829909376 profile: remove outside callers of ProfileWidget2::replot()
There was a mix of ProfileWidget2::replot() and
ProfileWidget2::plotDive(current_dive, true), which is equivalent.
Since there was more of the latter and it is more flexible, unify on
that.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-03 14:47:49 -07:00
Berthold Stoeger
a8130f0fa1 desktop: fix editing of trips
In 2021035cfc a bug was introduced:
currentTrip of MainTab was not set in trip mode. Thus, when editing
the trip notes, the notes of all selected dives were edited instead.

Set the member variable and not a local variable.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-02 14:52:51 +02:00
Berthold Stoeger
2021035cfc selection: replace selectedTrips() by singleSelectedTrip() function
To check wether the tab widgets should show the trip view, they called
the selectedTrips() function. The trip view was shown if that contained
only one trip. However, the selectedTrips() function was very slow,
because it has to query to core models.

Change the function to singleSelectedTrip(), which returns a trip
if there is exactly one trip selected. The function returns early
if there is more than one trip selected. This makes the select-all
case much faster.

There are two cases which are still very slow:
- List mode, because here all top-level items are queried.
- Dive log with many only top-level items.

Ultimately, we will have to cache the trip selection because
querying the model is too slow.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-26 13:54:59 -07:00
Berthold Stoeger
20e7064658 desktop/tabwidgets: replace editMode by boolean
There was only one editMode left (MANUALLY_ADDED_DIVE).
Therefore replace by a flag. This makes the code more consistent,
because the conditions "editMode != NONE" and "editMode ==
MANUALLY_ADDED_DIVE) actually meant the same thing.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
3b9913d828 desktop/tabwidgets: replace IGNORE_MODE by flag
The editMode was set to IGNORE_MODE when programatically setting
fields so that we can ignore changed-signals.

That seems to be orthogonal to whether we are in edit mode
and indeed when setting IGNORE_MODE the edit mode was
saved and restored.

Therefore, replace the IGNORE_MODE by an independent ignoreInput
flag.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
13d339451e cleanup: remove parameter to MainTab::enableEdition
All remaining callers were passing MANUALLY_ADDED_DIVE as a new
mode, so we may just as well remove the parameter and thus
simplify the logic.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
accf1fcc8f desktop: remove EDIT mode
The only way to enter edit mode is to edit the profile. However,
that means that the profile is already visible, so there is no
need to change the mode. Simply remove the EDIT mode.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
1aa25aad6d desktop: don't disable tabs in edit state
The edit state is now only used to edit the profile. There is no
reason to disable random tabs.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
42b423f02c cleanup: don't center map on rejecting edit
The editing of the dive site is controlled via an undo command.
No point in centering the map when cancelling a profile-edit.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
150bd9763e cleanup: remove lastMode variable in MainTab::rejectChanges()
This stored the old editMode. However, it was not read after
editMode was changed, so there is no point to it.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
5f858e137d edit: remove multi-dive version of edit information
The "dive is currently" edited is only shown when the profile is
edited. This affects only the current dive and therefore a
message saying that multiple dives are edited makes no sense.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
6288b2a619 cleanup: remove strange recursive code in MainTab::enableEdition
When enableEdition() was called with mode == NONE and the dive
was a manually added dive, it would call into MainWindow::
editCurrentDive(), which would in turn call enableEdition(),
however with another mode. Since the only caller of
enableEdition() is now editCurrentDive() anyway, we can
remove that weird code.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
ee64a85d2e cleanup: remove cylinders_equal check in MainTab::rejectChanges()
This check make no more sense since cylinder editing is now
treated by undo commands.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
0732bb2302 undo: remove TabDiveWidget::acceptChanges and rejectChanges
Since cylinders are now edited using the undo system, these
functions are not needed anymore.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
9310d72943 models: update divesite-model when clearing/updating dive model
When the dive list is cleared or updated, the entries in the
divesite-model become stale and therefore the divesite-model
(with the actual name LocationInformationModel) also must be
updated. This was done manually in some parts of the code and
forgotten in others. Therefore, do it directly in the clear()
and reset() function of the dive list-model.

This might be a bit of a layering violation: why should one
model call into another if they are not in parent/child
relationship? However, this seems easier than introducing
a global "reset dives" function that coordinates the models.

Moreover, it does not appear 100% safe: if the clearing of
the divesite model causes accesses to the divelist-model,
they happen in the midst of a model reset and we had horrible
bugs with that kind of things. However, I don't think that
should happen.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-18 13:27:16 -07:00
Berthold Stoeger
2a97934db4 Cleanup: Move stringToList to core/qthelper.cpp
The same code was used in desktop and undo commands. Let's unify.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-06 10:00:13 +01:00
Berthold Stoeger
c495a49b1b Cleanup: use getDiveSelection() for shifting time
There are two cases where dive-times are shifted: in an explicit
dialog and when editing the date/time of a dive.

In each of these cases, the selected dives were collected manually.
Instead use the getDiveSelection() function. Since this returns
a std::vector, change the argument of Command::ShiftTime() to
such a std::vector.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-06 10:00:13 +01:00
Berthold Stoeger
3e9b661c22 cleanup: remove setTabIcon() calls in MainTab
These were used to remove warning-icons to mark tabs with user
changes. However these icons haven't been set since commit
a86aca0378.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-02-28 08:16:41 -08:00
Berthold Stoeger
fb18bc0803 cleanup: don't update tabs twice in MainTab::rejectChanges
The updateDiveInfo() call updates all tabs. No need to do
it right afterwards.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-02-27 14:49:01 -08:00
Berthold Stoeger
e3950df864 cleanup: remove weightsystems_equal function
This was used to test whether the "really discard changes?"
message should be shown. However, we now edit weightsystems
directly with undo commands. Therefore, the check is unnecessary
and the whole function can be removed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-02-27 14:49:01 -08:00
Berthold Stoeger
0306109e95 cleanup: remove MainTab::modified
This field was not set to true since introducing undo of
dive fields.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-02-27 14:49:01 -08:00
Berthold Stoeger
55ffd5d1b5 Cleanup: remove unnecessary remember/restoreSelection() pair
When accepting changes, the main tab refreshes the display in
a remember/restoreSelection() pair. Since the display refresh
doesn't lose selection, these calls can be removed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-04 13:00:23 +01:00
Berthold Stoeger
4b1a3a1a6e Selection: move selection functions from divelist.c to selection.c
Since we now have a selection.c translation unit, put the selection-
related functions there.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-04 13:00:23 +01:00
Berthold Stoeger
569e532f5c Cleanup: Fix order of initialization in MainTab::MainTab()
For deterministic construction/destruction (i.e. objects are
destructed in reverse order of construction) it is crucial that
constructor initializer lists follow the order of the class
definition.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-04 08:37:14 +01:00
Berthold Stoeger
a6fa6cdb41 Undo: make profile-editing undoable
Recently, undo of dive-replanning was introduced. Therefore,
it appears logical to do the same thing for editing of the
profile of manually added dives.

For now, use the same undo-command, just change the displayed
text from "replan dive" to "edit profile". Move the fixup dive
call into the undo-command.

Eventually, every action on the profile should be made undoable.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-03 20:55:58 -08:00
Robert C. Helling
08cb521cf2 Initialize modified member
Fixes CID 350111

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-11-16 12:34:30 -08:00
Berthold Stoeger
5e29245e68 Refactoring: move undo commands to top level
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>
2019-11-14 21:02:07 +01:00
willemferguson
08db77333b Notes tab: Use top RH for depth and duretion fields
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-11 20:19:22 +01:00
Willem Ferguson
7a4abd7477 Reorganise the Information tab of the Info panel
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-10 13:10:03 -08:00
Berthold Stoeger
794066b236 Cylinders: access cylinders with get_cylinder()
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-09 19:19:04 +01:00
Berthold Stoeger
7c9f46acd2 Core: remove MAX_CYLINDERS restriction
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-09 19:19:04 +01:00