Commit graph

160 commits

Author SHA1 Message Date
Berthold Stoeger
009f47c5dc Desktop: improve recognition of HTML-notes
To recognize HTML-notes the text was scanned for <div> tags. But
apparently the planner notes do not feature such a thing. Therefore
extend recognition of HTML to <table> tags.

Note we can't use the <html> or <span> tags, because these are
*always* produced by the QTextEdit::toHtml() function.

Fixes #2265

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-30 09:31:50 -07:00
Paul Buxton
3c4fd5d599 Fix broken windows build with latest MXE
Replaces some enums with names that do not clash with windows #defines.
Specifically:
ERROR -> ERRORED, PASCAL->PASCALS, IGNORE->IGNORED,FLOAT->FLOATVAL

Signed-off-by: Paul Buxton <paulbuxton.mail@googlemail.com>
2019-08-29 12:55:25 -07:00
Berthold Stoeger
5da09a21bb Cleanup: move error reporting function declarations to errorhelper.h
Move the declarations of the "report_error()" and "set_error_cb()"
functions and the "verbose" variable to errorhelper.h.
Thus, error-reporting translation units don't have to import the
big dive.h header file.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-08 16:26:30 -07:00
willemferguson
78f425de68 Move the Suit text box from the Notes tab to the Equipment tab
Sqash latest commit with previous one.

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
2019-08-08 09:12:09 -07:00
Berthold Stoeger
344c85f499 Desktop: display trip time on main-tab
On the main tab, the trip time was not shown when switching to
a trip. Implement showing of the trip date in a function, as the
undo-code will also have to update the trip date in certain
circumstances.

Fixes #2207

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-08 09:03:33 -07:00
Berthold Stoeger
999a63a5bb Desktop: fix index in weightsystems_equal()
The weightsystem_equal() function compares weightsystems of two dives
to decide whether the "commit changes" message should be shown and
to decide which dives are edited when changing multiple dives.

Due to an index mixup the function returned wrong results for
more than two weightsystems. Fix it.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-27 11:51:34 -07:00
Berthold Stoeger
a5e7f4253a Core: dynamically resize weight table
Replace the fixed-size weightsystem table by a dynamically
relocated table. Reuse the table-macros used in other parts
of the code.

The table stores weightsystem entries, not pointers to
weightsystems. Thus, ownership of the description string is
taken when adding a weightsystem. An extra function adds
a cloned weightsystem at the end of the table.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-18 06:01:07 -07:00
Berthold Stoeger
e3577ffd7e Cleanup: Remove unused function calls in main tab
per_cylinder_mean_depth() and selected_dives_gas_parts() are used
in the dive-information and statistics tab, respectively. Nevertheless,
these functions are called on the main tab as well and the result is
trashed. Therefore remove the calls. Must have been an artifact.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-18 05:47:27 -07:00
Berthold Stoeger
5886550434 Desktop: clear notes on empty dive
If no dive is set, all fields except the note field were cleared.
Also clear notes.

Fixes #2172

Reported-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-11 15:58:30 +02:00
Berthold Stoeger
02e94de062 Desktop: enable clearing of dive site
Clearing dive site did not work for two reasons:
1) We didn't get a signal when editing was finished.
2) When clearing the dive site, the "add new dive site" site was set.

Thus, connect to the editingFinished signal and in
DiveLocationLineEdit::currDiveSite() return a null pointer if
the string is empty.

This means that it is not possible to have a dive site with an
empty string, but that shouldn't be a problem, right?

Fixes #2148

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-04 10:41:09 +09:00
Dirk Hohndel
ca496c63ae Desktop: fix time editing
We were shifting in the wrong direction. Which caused the field to be marked as
'edited' again, which meant we shifted the wrong way and twice the distance.
This seems to fix the problem for both date and time editing.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-06-24 10:32:41 +02:00
Berthold Stoeger
27944a52b1 Undo: don't send signals batched by trip
Since the default view is batched by trips, signals were sent trip-wise.
This seemed like a good idea at first, but when more and more parts used
these signals, it became a burden. Therefore push the batching to the
part of the code where it is needed: the trip view.

The divesAdded and divesDeleted are not yet converted, because these
are combined with trip addition/deletion. This should also be detangled,
but not now.

Since the dive-lists were sorted in the processByTrip function, the
dive-list model now does its own sorting. This will have to be
audited.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-23 20:08:46 +02:00
Berthold Stoeger
54d6c3f004 Cleanup: remove unnecessary get_gas_used() call
The result was not used anywhere, so why bother?

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-19 13:11:10 -07:00
Berthold Stoeger
7f4d9db962 Cleanup: move trip-related functions into own translation unit
These functions were spread out over dive.c and divelist.c.
Move them into their own file to make all this a bit less monolithic.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-19 13:11:10 -07:00
Berthold Stoeger
e329a53aab Undo: add undo button to multi-dive-edited warning message
Simply connect the button the the undo-action and the hide-message
action.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-15 11:20:49 -07:00
Berthold Stoeger
a20c22d907 Undo: hide multi-dive-edit warning message on subsequent edit
When a different field is edited, hide any old multi-dive-edit
warning message. The reason is that we might want to add an "undo"
button to the message. But this will undo the wrong command if
we don't hide the message.

Sadly, this means that we can't use animated show / hide, because
an animatedHide() followed immediately by an animatedShow() does
not necessarily show the message. In other words, and animatedShow()
does not interupt a started animatedHide()!?

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-15 11:20:49 -07:00
Berthold Stoeger
944a9aed54 Undo: show warning message if more than one dive edited
On the MainTab, warn if more than one dive was edited. To this purpose,
add a new KMessageWidget with an "OK" button that closes the message.
Code is mostly a copy of the already existing "Editing dive" message.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-15 11:20:49 -07:00
Berthold Stoeger
99dc528a10 Cleanup: remove MainTab::addMessageAction() function
This is a pointless one-liner function. Let's remove it. The
message it shows will probably be moved to the profile in the
not-so-distant future anyway.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-15 11:20:49 -07:00
Berthold Stoeger
1641147e7b Undo: don't create spurious undo commands for temperature fields
When tabbing through the dive-info fields we get *EditingFinished
signals. This would create undo commands. The undo commands should
recognize if nothing changed. But for the temperature fields,
owing to rounding, an unchanged text could actually represent a
different value.

This would lead to very confusing situations:
1) Edit air temperature
2) Press tab to finish editing
3) Focus goes to water temperature
4) Try to undo change in menu
5) When opening the menu water temperature loses focus
6) Water temperature is edited
7) Undo undos the water temperature, not the air temperature
8) Goto 4

Fortunately, QLineEdit fields have the isModified() member function
that returns true if the field was changed by the user. Use
this to prevent this case. This is not a general method, i.e.
it has to applied to every field with that problem. But it is
less intrusive than subclassing the QLineEdit class.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-15 11:07:15 -07:00
Berthold Stoeger
0e1b07bd6f Desktop: don't show location-popup button in trip-edit mode
The location fields are hidden in trip mode. Only the location-popup
button was shown. Hide it as well.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-07 04:47:39 +03:00
Berthold Stoeger
32720a7c18 Dive site: Add button to display all dive sites
On the main dive tab, add a button that opens the dive-site selection
widget showing all dive sites. This is done by setting the "temporary
dive site name" to the empty string. Thus no dive sites are filtered
and the "add new dive site" entries are not shown. Moreover, the
text is selected. The user can therefore immediately start typing to
activate the filter or enter the name of a new dive site.

The idea is that after downloading dives with GPS information the
user can select one of the close dive sites.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-11 12:35:11 -07:00
Berthold Stoeger
c7e1c40b0e Dive site: sort by distance to current dive
When presenting the list of dive sites on the dive-info tab, sort
the dive sites by distance to the current dive. The idea is that
when the user wants to select a dive site, close dive sites should
be prioritized.

The location of the dive is determined with the dive_get_gps_location()
function introduced in the previous commit. This actual GPS data get
precedence over the currently set dive site for that dive.

On change of dive, the current location is updated in the
DiveLocationFilterProxyModel so that a potentially expensive search
for GPS data is not repeated for every comparison.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-11 12:35:11 -07:00
Berthold Stoeger
d4a91a52fa Map: reload on selection change directly
When changing the dive selection, we have to reload the map to show
the correctly highlighted flags. Do this directly by hooking into
the DiveListNotifier::divesChanged signal instead of indirectly
via the MainTab.

Moreover, on reload center on the highlighted dive sites.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-11 12:06:19 -07:00
Berthold Stoeger
ce140f2925 Desktop: fix crash on dive site tab
An interesting crash:

1) On the dive site tab select a dive site such that only one
   trip is shown.
2) Unselect all dives.
3) Press CTRL-A while the dive list has focus.
4) This will select a trip.
5) In MainTab::updateDiveInfo() this will switch to the previous
   tab active when in trip mode.
6) This will reset the filter.
7) This will reset the currentTrip field which we just set.
8) Since we just set the currentTrip field, we don't expect
   it to change and reference a null pointer.

To fix, don't switch tabs when on the dive site tab. This also
improves user experience as there seems to be no reason to switch
away from the dive site tab.

Currently the index of the dive site tab is hard-coded - this
should be changed!

Fixes #2077

Reported-by: Doug Junkins <junkins@foghead.com>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-05 08:53:19 -07:00
Berthold Stoeger
88fbcefd4f Desktop: set dive fields only when not in trip mode
On the main-tab, when looking at a trip, the fields were filled
out with dive-data and then either hidden or overwritten with
trip data. Move the update of the fields into the corresponding
if-branch that is only active if on dive-mode.

This means removing the UPDATE_* macros, which updated or cleared
dive-fields depending on whether a current dive was set. These
operations are now performed explicitly in the corresponding
if-branches.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-29 12:58:49 -07:00
Berthold Stoeger
822b88ab3d Cleanup: remove completers from MainTab object
This struct is used to store the completers during construction
of the object. But it is never accessed afterwards. Therefore,
remove it from the object and remove the structure definition
from the header file.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-15 10:30:04 +12:00
Berthold Stoeger
fe61f6b69e Cleanup: Move dive-equipment tab into own translation units
Most tabs in the dive-information widget have there own translation
units and ui-files. Only the equipment tab was married with the
main tab. Move it out to get more reasonably sized translation units
and some isolation.

Currently, this needs ugly hacks when entering / checking for edit
mode: Access to MainTab is via the MainWindow. And vice/versa, when
accessing the DiveEquipmentTab from the MainTab, the former is
hardcoded as the first item of an array.

These hacks will soon be removed though, when making equipment
editing undoable. The tabs will then be independent.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-15 10:30:04 +12:00
Berthold Stoeger
4bb002d137 Cleanup: Remove MainTab::getEditMode() function
The only caller of said function used to check whether MainTab is
in edit mode. For this case there is already a function - use that
instead.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-15 10:30:04 +12:00
Berthold Stoeger
3242fbdc45 Dive sites: dont't disable all tabs when creating new dive site
The dive tabs are disabled, when no dive is shown. The dive site tab
is implemented as a dive tab, which is of course conceptually wrong.
Moreover it has the nasty side effect that when adding an empty dive
site, no dives are shown and the tab is disabled, leading to a
UI dead lock.

Therefore, disable all tabs but the dive site tab. The proper fix
will be a refactoring of the UI.

Reported-by: Doug Junkins <junkins@foghead.com>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-13 09:06:34 +12:00
Berthold Stoeger
d5953318ca Cleanup: replace QString("") by QString()
That should be more effective.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
37c159aae1 Map: reload map when editing dive site of a dive
Editing the dive site of a dive may make a dive site appear
(first dive of that site) or disappear (the last dive of that
site was removed). Therefore, we have to reload the dive site
markers on editing the site of a dive.

This should be made smarter by only reloading the markers if
the dive site status actually changed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
8c6205fc0d Undo: on save remove focus from active fields
The editing of a dive field is only performed when focus
is removed from the field. On pressing CTRL-s, the changes
in the currently active field were therefore not saved.
Remove the focus from all fields to trigger an edit command
yand thus ensure that all changes are saved.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
837ab6c90b Desktop: read tab-items from current_dive, not displayed_dive
The whole edit logic moved from displayed_dive to current_dive
and it became more and more tedious to keep these in sync.
Therefore, simply always display current_dive. The only exceptions
are the equipment tab and the planner, as these are not yet
integrated in the undo system. Once this is done, displayed_dive
can be removed.

Moreover, remove the clear parameter from updateDiveInfo().
Instead simply clear of there is no current_dive set.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
bfb6a55707 Undo: inform maintab if dive site changed
If a dive site was edited, the location field should be updated.
Do this by hooking into the diveSiteChanged signal of DiveListNotifier.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
4a3ffeba05 Undo: remove ADD mode from main tab
Instead of letting the user edit the fields before adding a dive,
simply add an empty dive. Thus, the ADD mode of the main tab can
be removed.

Constructing a new dive with default-depth and making sure that
the dive is displayed correctly is very subtle. This all needs
to be detangled in due course.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
91c33b475c Undo: move temperature update from MainTab to EditWaterTemp
The code in maintab is not called anymore (unless cylinders
or weightsystems are changed). Move the code to the command
that edits water temperature.

This should be audited as it is unclear weather this is
necessary.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
c4ad477d07 Cleanup: remove field-coloring code in MainTab
Since all fields on the maintab are now directly edited,
there is no point in marking fields as changed. Remove
unused functions MainTab::markChangedWidget() and
MainTab::resetPalette().

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
d7d408a99e Undo: implement undo of dive trip editing
This is copying the dive editing code. It uses an OO design with
virtual functions for getting and setting the values. It doesn't
use templates though, as both fields of strig type. This feels
a bit over-engineered, but it is 1) consistent with the dive edit
code and 2) the number / types of dive trip fields might increase.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
9ed5cf16a4 Coding style: remove Java-style function definition
Remove a few cases of
	void fun() {
		...
	}

While touching these functions, fix a few other whitespace
coding style violations.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
73a230b6e6 Cleanup: remove EDIT_TEXT and EDIT_VALUE macros in maintab.cpp
These functions are now performed by the edit commands and the
macros have no users. Remove them.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
53b4d84a6e Undo: remove MainTab::*TaggedStrings() functions
Moving the tagged-string edit functions into the undo-system made
the MainTab::saveTaggedStrings() and MainTab::diffTaggedStrings()
functions unnecessary. Remove them.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
5436f9b859 Undo: move dive-list logic into edit commands
The edit-commands were called with a list of selected dives and
the original value. Move the creation of the list and extraction
of the original value into the edit-commmands.

This removes the "current is last" rule and allows for more
flexibility.

Since the depth- and duration editing applies only to the current
dive and not all selected dives, add a parameter to the edit-commands
controlling whether only the current or all selected dives are edited.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
cddd5942f8 Undo: update dive list after edit command
The dive list was not updated automatically when an edit command was
executed. There was already a signal to do that, viz. divesChanged().
But that signal worked by-trip and didn't have a dive-field specifier.

The edit-commands used the divesEdited() signal that isn't by-trip
but has a dive-field specifier.

Unify these two signals to be by-trip and with dive-field specifier.
This needs common code to generate the by-trip list that is moved to
a command_private.h header.

Since there might now be multiple signals (one per trip) actually
check in the main-tab whether the current trip is affected to
avoid multiple update of fields. This has the positive(?) effect
of not doing any update if the current dive isn't changed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
d5691cd7cb Cleanup: remove MainTab::acceptingEdit
The acceptingEdit field was used to ignore edit-signals in
MainTab::acceptEdit(). But an equivalent mechanism already
exists: setting editMode to IGNORE. For consistency, replace
the former by the latter. acceptEdit() resets the editMode
in all cases anyway.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
c82f4487f9 Undo: implement undo of depth and duration editing
This was a bit different from the other editing commands:
1) Only the current dive is edited not all selected dives.
   Therefore, create a function that turns the current dive
   into a one-element list.
2) The profile has to be replot. Here, likewise, create a
   function to do that.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
02d572226d Undo: implement undo of divemaster editing
This is mostly a trivial copy of the buddies code.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
a9bd0690fe Undo: implement undo of buddy editing
This was mostly trivial by reusing the code for tag-editing.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
8c89f6fe15 Undo: implement undo of tag editing
The code follows the other edit-commands, but uses its own base
class, because it is distinctly different. Editing the tag field
does not simply mean setting the tag for all dives, but rather
adding and removing individual tags.

This class will be reused for editing of dive buddies and masters.

Modify the tag widget thus that it sends an editingFinished()
signal when it goes out of focus. The editingFinished() signal
was prevented by hooking into the return, enter and tab key-events.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
1c854d580a Desktop: on ESC, remove focus when editing dive fields
Give the user a way to accept the changes made to a dive-field
by pressing ESC.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
6f574c53a3 Undo: implement undo of dive site editing
This one is a bit more tricky. There are two modes: set dive site
and set newly created dive site. This is realized using an OO model
with derived classed. Quite convoluted - but it seems to work.

Moreover, editing a dive site is not simply setting a value,
but the list of dives in a dive site has to be kept up to date.

Finally, we have to inform the dive site list of the changed
number of dives. Therefore add a new signal diveSiteDivesChanged.
To send only one signal per dive site, hook into the undo() and
redo() functions and call the functions of the base class there.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00