In signals dives were sorted by date. This criterion is not be unique.
Therefore sort by the dive_less_than() function of the core to avoid
any inconsistencies between the Qt-models and the core data.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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>
Make dive.h a bit slimmer. It's only a drop in the bucket - but at
least when modifying tag functions not the *whole* application is
rebuilt anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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>
The multiple-dives-edited message was shown even if the value was
not changed. Notably, when tab-flipping through the dive fields.
Therefore, changed the execute_edit() function to return zero
when no command was executed. For this, return a boolean from
the execute() function indicating whether the command was really
executed or trashed.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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>
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>
To enable a "multiple dives edited" message, return the number
of edited dives from dive edit undo commands. Since there are
two kinds of these commands, viz. normal fields and tag fields,
and the former use templates, create a common base class that
can return the number of dives. Yes, the class hierarchy is
getting scarily deep! At least, this gives a tiny bit of
code-reuse.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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>
The PIMPL idiom is used by some frameworks (notably Qt) to
ensure binary compatibility. Objects consist only the general
object header (ref-count, connections, children, etc..) plus
a single pointer to private data.
MinMaxAvgWidget was implemented using this idiom. This seems
to make no sense, as we don't produce a general library with
the need of a stable ABI. Let's remove this unnecessary
indirection.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Owing to the recent undo-changes, the git id was not invalidated
when accepting changes to cylinders and weights.
Do this in the MODIFY_DIVES macro for now.
Reported-by: Jan Iversen <jani@apache.org>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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>
A regular expression was generated and then copied twice without
apparent reason. Remove these copies.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
preprocessTemplate() replaces variables of the kind "dive.weight0"
by "dive.weights.0". Replace the old code by regexps. This not
only makes the code significantly shorter, it also makes it independent
from the name of the dive variable (i.e. "dive").
Moreover, it removes a dependency on MAX_WEIGHTSYSTEMS and MAX_CYLINDERS,
which might help in removing these restrictions.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Some users understood "Configure dive computer" as the
menu entry where you configure which dive computer to
use. Reworded to make clear that this modifies the
settings on the dive computer.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
When deleting a dive computer, don't just show the first
dive computer, but the next one in the list (if it exists).
Moreover, on undo jump to the previously shown dive computer.
Do this by keeping track of the before and after dive computer
number in the undo command.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This function clones a dive and clear out the old dive. This
corresponds to move semantics. Name the function accordingly.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This is just minor fixes that are not user-visible:
Fix a few erroneous comments and a debug message. These are
copy & paste mistakes and mistakes introduced during code-
refactoring.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of the elegant solution that just modifies the dive,
keep two copies and add either the old or the new copy. This
is primitive, but it trivially keeps the dives in the right order.
The order might change on renumbering the dive computers.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Recently, the undo code was changed to consider dive sites.
The undo code uses a DiveToAdd structure, which was extended
by the dive site to which the dive should be added.
The split and merge commands were not adapted and therefore
the dive counts of the dive sites were wrong after split
and merge.
Fix this by properly setting the dive site field and removing
the reference in the dive structure (in the split case, the merge
case already cleared the reference).
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In 5729f93e1f, the dive addition /
deletion code was simplified in that indexes were calculated on
the fly. This made it, in principle, possible to pass in dives
in any order.
But there was a small oversight: the recipients of the dives-added
and dives-deleted signals expect the dives to be sorted as in
the core list. Only then will the lists be consistent.
Therefore, sort the lists before adding / deleting dives.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The units.h file has two functions to convert atm pressure to mbar
and also to convert mbar to atm pressure. Implement these two
functions in the planner.
Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
The Information tab shows the atmospheric pressure. Make this value editable
and also ensure that changes to it are undo-able.
Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
The way the application state would enable/disable widgets was very
"dynamic". A property-list would be generated and put in a set
of arrays. Very hard to figure out what is going on.
Replace these property-list by flags and explicit old-fashioned boolean
expressions.
Join the two arrays (widget- and property-lists) into an array of
a unified data structure.
Replace the macro that sets the widgets by a simple static function.
Factor out the four loops that added widgets to the quadrants into
a simple static function.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The application state was encoded in a QByteArray. Thus, there was
no compile-time checking. Typos would lead to silent failures.
Turn the application state into an enum. Use the enum-class construct,
so that the values don't polute the global namespace. Moreover,
this makes them strongly typed, i.e. they don't auto-convert to
integers.
A disadvantage is that the enums now have to be cast to int
explicitly when used to index an array.
Replace two hash-maps in MainWindow to arrays of fixed sizes.
Move the application-state details into their own files.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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>
DiveLocationLineEdit::showPopup() called the functions
- fixPopupPosition()
- proxy->invalidate()
- proxy->sort(LocationInformationModel::NAME)
- view->show()
All these calls are redundant, as they are already performed by
setTemporaryDiveSiteName(). Remove them.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Currently, in the dive-site selection widget the distance to
the dive site of the current dive is shown. Instead, use the
recently introduced dive_get_gps_location() function. Thus,
the actual GPS coordinates extracted by libdivecomputer are
used.
The function is only called when the current dive changes
and the location is stored in the item delegate.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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>
Some dive computers save GPS data. Currently, this is stored
by libdivecomputer in an "extra field". When generating a
new dive site for a dive try to use this data to place the
dive site.
To do so, create a "dive_get_gps_location()" function. This
function can be extended later to use e.g. event. When creating
a dive site, use the result of this function over a potential
pre-existing dive site.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Currently, dive site names are only updated on full reload.
Instead hook directly into the corresponding signal in the
MapLocationModel to set the name. Also to the coordinates
directly there instead of going via the MapWidgetHelper.
In the MapWidgetHelper, just center on the changed dive site.
Hook into the signal directly there and remove the slot
from the MapWidget. This makes the whole call-chain at least
one call shorter.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of looping over the dive table and extract dive sites,
loop over the dive site table.
This makes it possible to show dive sites that have no dive
associated with them.
But we have to create to functions that check whether a dive
site has any shown dives or has any selected dives.
Moreover, change the code to add near dive sites of the same
name if in edit mode. Other wise (erroneously added?) dive
sites with the same name cannot be moved on the map.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
There used to be a flag to avoid reloading of the map. Since this
is not used anymore, remove it.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The dive-site-edit and dive-site-table tabs both put the filter
into a special dive-site mode. When switching between both, it
could happen that the one got its show befor the other got
its hide event.
Thus, the first would start dive-site filtering and the second
stop it. Now the app was not in filter mode even though it should.
To solve this problem, add reference counting for the filter's
dive-site mode. In both tabs call the enter/exit functions
on show/hide. In the dive-site-table tab, when the selection
changes, use a set function that doesn't modify the reference count.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Since the dive-site-filter is active either on the dive-site-edit
page or the dive-site-list page, use that as the flag for dive-site-edit
mode. Moreover, when the filter is reset, the
MapWidgetHelper::reloadMapLocations() function is called, so we
can use that place to enter/exit edit mode.
This makes it easier to keep everything consistent.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
DiveListView::selectDives() would only select new dives but not clear
the old selection. Thus, callers would have to clear the selection
first. That would lead to two selection-changed signals.
Move the unselectDives() call into DiveListView::selectDives().
The DiveListView has an internal flag to prevent double signals.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This was only used locally and only a stub for calling
MapWidgetHelper::centerOnSelectedDiveSite. Call the latter directly
instead.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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>
This member variable was only used locally in functions.
Accordingly, make it a function-local variable.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
During edit mode, we could get spurious reload() requests owing
to tabs being hidden. This led to undefined behavior:
In some cases entering dive site edit mode would show all dive
sites, in some only the dive site of the currently edited dive.
Therefore, refuse to reload the map while in edit mode. The
corresponding flag already exists.
Partially fixes#2076
Reported-by: Doug Junkins <junkins@foghead.com>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
On reload of the map, the map exits edit mode. Sounds logical
at first, but the whole map-mode code is very unpredictable.
What happened was that when switching from the dive site table
to dive site edit mode, the code would enter map edit mode first.
Then, the dive site tab got its hide-signal, which would reset the
filter. This would reload the map and thus exit mode. Hence the user
can't drag the flag on the map.
Partially fixes#2076
Reported-by: Doug Junkins <junkins@foghead.com>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Creates the dialog box to select which sites to import from the file
selected in mainwindow.cpp. The DivesiteImportModel is created as a
table to display and select which sites are to be imported. Once the
sites are selected, the Command::importDiveSites command is called to
add the sites to the core dive site table with undo/redo functions.
Signed-off-by: Doug Junkins <junkins@foghead.com>
Adds "Import->Import dive sites" menu to mainwindow.cpp and adds the
on_actionImportDiveSites_triggered() method to prompt for the filename
to import from. The files are parsed and then any dive and trip data is
cleared before opening a dialog box to select which sites are to be
imported.
Signed-off-by: Doug Junkins <junkins@foghead.com>
ImportDiveSites adds the provided dive sites to the core dive site table
and stores the source data so it can be undone.
Signed-off-by: Doug Junkins <junkins@foghead.com>
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>
A number of objects in this file were global. Yet they weren't
used anywhere else. Don't export these symbols by making them of
static linkage.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
A copy of a C-string was assigned to a QString. The copy was never
freed. Instead, assign the C-string directly. This does the right
thing.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
- Use a beginResetModel()/endResetModel() pair instead of distinct
addRows / removeRows pairs.
- Reuse the update function in the constructor().
- Let "rows" be the number of rows, not the number of rows minus one.
- Remove updateInfo() function as it does the same as update().
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
YearInfo is a trivial wrapper around "stats_t *". All the
constructor / destructor rigmarole seems completely unnecessary.
Remove it. Probably the whole class could be removed, but for
that I'd need more insight into Grantlee, which is low on my
list of priorities for now.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
For printing, DiveObjectHelpers are allocated and pointers to these
are stored in a QVariantList. The objects are never freed. To fix
this leak, keep the objects in a std::list<>.
std::list<> was chosen because
1) Pointers to elements stay valid during its lifetime.
2) Objects can be constructed directly in the list with emplace_back()
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
We're quite inconsistent when it comes to variable naming.
The general usage is camelCase for Qt parts and snake_case
for core code. Virtually nowhere do we start variable names
with a capital letter. Therefore, turn this one weird case
into camelCase.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
TemplateLayout::m_engine is a Grantlee::Engine that is reallocated
for every function call. Instead of the archaic memory-management,
remove the member variable and make it a local variable of the
two functions that need it. There seems to be no point in keeping
the object alive beyond the function's scope.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The default QString constructor generates an empty string. No point
in assigning the empty string to such a thing.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Currently, the dive information tab was not updated when the user
edited fields. The fields were only updated when switching between
dives.
Therefore, hook into the "divesChanged" signal and update the fields
accordingly.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The information tab used displayed_dive to fill out its field.
For consistency with the main tab and in a bigger effort to remove
displayed_dive, use current_dive instead.
Only clear the fields if no current_dive is set. The code used to
clear the fields and overwrite them later.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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>
This commit adds an entry to the dive media context
menu which offers to write a subtitle file. This
creates an .ass file for the selected videos.
In an attempt to to clutter the screen too much, don't
show irrelevant entries (zero temperature or
NDL and show TTS only for dives with stops).
VLC is able to show these subtitles directly, they
can be integrated into the video file with ffmpeg.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
In the dive site selection widget there are two special entries
(add dive site with given name). Don't show this if the user didn't
enter a string.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The dive site selection widget implements a lessThan() function, but
that was never called. Apparently in a QListView one has to start
sorting by hand? Do just that.
In any case, the lessThan function was erroneous as it would happily
sort away the first two special entries. Fix it with a special case
for these to.
Finally use case insensitive string comparison.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
To reset the filter-model, LocationInformationWidget would extract
the model from the diveSiteListView and then downcasts it. Instead,
it can access it directly, because the filter-model is a subobject
of LocationInformationWidget.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
DiveLocationLineEdit stored a pointer to itself in a global variable
so that the DiveLocationModel can access it to access the filter text.
Instead, on change simply pass the filter text down from DiveLocationLineEdit
to DiveLocationModel.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The dive-site line edit box features two special entries for adding
new dive sites. These should display different texts depending on
whether the current dive has a dive site or not.
The current check is wrong, because it used displayed_dive, but
since the last set of undo-changes, this might not be filled out
correctly anymore. Instead the code should check the actual current
dive.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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>
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>
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>
When adding dives in an undo command, the index is saved in the
command. This seemed logical at first, because why calculate the
index more than once? But actually it made the code rather subtle
and brittle when multiple dives were added.
Moreover, this is a pointless optimization, as it doesn't optimize
the common case (only one execution).
Remove this for now and calculate the index on every execution. If
it ever turns out to be a bottle neck, it will be much more effective
to turn the linear search of the index into a binary search. A
further sensible optimization would be inserting in batches.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The tag-widget was only showing the completer if we were in edit mode.
The edit mode does not exist anymore - therefore remove the check.
Hopefully this has no unintended consequences, like the completer
not disappearing when it should.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Selecting "Selected dives" exports the dive sites for the selected
dives. Selecting "All dives" exports all dive sites.
XML format is the subsection of the divelog XML that describes the
sites headed with a <divesites> section like:
<divesites program='subsurface' version='3'>
</divesites>
Signed-off-by: Doug Junkins <junkins@foghead.com>
Apparently, in some Qt-versions the destructor of the base class
calls hide on child-objects (according to Qt's object hierarchy).
This is obviously called after the derived class has been destructed.
In a concrete case, the base class of the destructed MainWindow
would hide the TabDiveSite object. That would reset the filtering
if a dive site was selected, which would indirectly access the
MainWindow, which is already partially destroyed.
Therefore, destroy the MainTab before destroying the MainWindow.
Do this by keeping it as a std::unique_ptr subobject. Thus, it
will be destroyed before the MainWindow and remove itself from
Qt's object hierarchy.
Reported-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This feels more natural than selecting a single cell. Still,
the "delete" cell is not visibly selected, which give a
strange impression.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The model was not reset on file close, leading to weird effects.
New dive sites would be added at the end of a table full of empty
entries.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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>
When in dive site tab and some dive sites are selected, show only
dives at those sites. Simply read the selection and pass it to the
filter.
Start and stop filtering when switching to and from the tab,
respectively.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In the edit-dive-site tab the filter is switched to a particular
mode where only dives at that site are shown.
If we want to reuse this for the dive-site tab the mode has to
be extended to allow for multiple dive sites. This is trivially
done by replacing a pointer by a vector of pointers.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of sending a signal when counts change, catching them
in the filter widget and update the window title there,
directly update the window title in the model. This removes a
signal/slot pair.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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>
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>
Properly implement the unsaved-changes flag(s). Since we currently have
two kinds of changes, there are two flags:
1) dive_list_changed in divelist.c marks non-undoable changes. This flag
is only cleared on save or load.
2) QUndoStack::isClean() is used to determine the state of undoable
changes. Every time the user returns to the state where they saved,
this flag is cleared.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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>
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>
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>
Merging dive sites is currently only possible if dive sites are at
the exact same position.
Introduce a field where the user can enter a distance up to which all
dive sites should be listed. These can then be merged.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The filter code is strange: it actually only checks the
dive->hidden_by_filter flag. Thus, before propagating the dive
changed signal, this flag has to be updated. Do this in the
DiveTripModel. Ultimately, this should be refactored.
Moreover, if the filter-flag changed notify the frontend
of a changed trip so that the trip is hidden / unhidden.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
If fields in a trip are edited, select that trip, which will display
the trip in the notes-box.
This is realized by hooking into the tripChanged signal in the dive-list.
A layering-violation, perhaps?
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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>
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>
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>
When pasting (or undoing paste) the cylinders or weights may change.
Send the appropriate signals and update the models accordingly.
Currently, this means copying from current dive to displayed dive,
but hopefully we can get rid of "displayed_dive" in the not so
distant future.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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>
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>
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>
Save selected dives when generating an edit-command. Restore the
selection and current dive in undo()/redo().
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Undo of editing should probably also restore the old selection and
current dive. Therefore, move the functions that set and restore the
selection and the current dive from the command_divelist.cpp into the
command_private.cpp translation unit.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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>
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>
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>
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>
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>
Now that we have dive-changed signal, send it on merging
dive sites so that the notes tab can be updated accordingly.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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>
This is different from the other editing commands, because
date and time editing may change the order of the dive list.
Therefore, this uses an already implemented dive list command.
The command is extended to send a divesEdited() signal.
This signal and the divesChanged() signal, which is used by
the dive list, will be unified in a later commit.
Update of the graphics is now not done via signals, a direct
call is performed in MainTab::divesEdited(). This simplifies
things.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Mostly trivial. Since now on editing the field is re-set, the
validation function becomes unnecessary.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This was rather trivial and modeled after the previous edit
UndoCommands. Since this is the first time we're editing
integers a new constructor instantiation had to be added.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This one was trivially modelled after notes editing. Only difference:
the textChanged() signal was replaced by the editingFinished()
signal so that we're not generating undo-commands on every key-press.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Add a new UndoCommand for dive mode editing. This one is a bit
special, as the mode is associated with a dive computer (DC),
not a dive. Thus the edit command has an additional parameter,
viz. the index of the DC.
This does not fit properly to the EditBase class, as this class
isn't aware of additional parameters and therefore this parameter
is not sent via signals. At the moment this doesn't matter. In
any case, the semantics of editing are weird and therefore let's
do the simple thing (derive from EditBase) and let's see what
the future brings.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
To keep the UI in a consistent state, update the notes field if
it is changed by an undo command. To that purpose, add a new
signal to diveListNotifier with a list of dives and a field-id
as payload.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Implement a first rudimentary dive-editing command. The main code
resides in a base class Command::Edit, which calls virtual functions
to read / set the fields and extract the field name.
Implement an example: editing of dive notes.
This dose not yet update the UI on undo / redo.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Add a "purge unused dive sites" button to the dive site list.
Connect it to a new PurgeUnusedDiveSites command. Implementation
was trivial: simply copy the DeleteDiveSites command.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Stretch the name and description columns in the dive site table,
so that they don't start too small. This should only be a temporary
solution, as it disables the save column width to preferences
feature of TableView.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The edit dive site button was connected to a *signal* of MainWindow,
which was connected to a slot of MainWindow. Remove the unnecessary
intermediate signal.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Add an edit column that calls the new editDiveSite() function
of MainWindow. The calling code is in DiveSiteSortedModel.
Quite illogical, but that's how TableView works, for now.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
As long as a text field is active, CTRL-Z only affects this field.
Thus it is suprisingly hard to undo edits. There seems to be a
fundamental problem with CTRL-Z handling.
To make it somewhat easier, catch any ESC-key event and move the
focus to the MainWindow. This effectively removes the focus from
any text field.
This all appears very wrong, but so far I wasn't able to find the
root cause of the problem.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The signal was caught by the MainWindow to:
1) call setDefaultState()
2) call refreshDisplay()
3) call refreshDisplayedDiveSite()
1) Let's call that directly from the widget. The reason is that in
the future there might be multiple way to get into the widget and
therefore the widget needs finer control.
2) Remove this call as it produces an unsteady UI.
3) This should be done by undo commands, not only when finishing
dive site editing.
Thus, the signal becomes unnecessary and can be removed.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This one was rather trivial, as there is no actual merging
done. Quite simply, a number of dive sites are removed and
their dive added to a different dive site.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Simply copy code of the other edit dive site functions. Here though
introduce a destructor in the undo command to free the taxonomy data.
Remove the taxonomy member of the LocationInformationWidget class,
because it is not needed anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Since no dive site field editing enters edit mode anymore,
the whole edit mode state and code can be removed from the
widget.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Simply hook into the appropriate signal. Thus, the "update dive site
location" button can be removed.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Simply copy the code of note editing. It's a bit more complex,
since we have to parse the Gps coordinates. For consitency,
rename the COORD field to LOCATION (the field in the dive_site
struct is called LOCATION).
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Simply copy the code of notes editing, but use the taxonomy_* functions
to read and set the value. Moreover, replace the three TAXONOMY_n field
ids by a single TAXONOMY id. We will probably never show one column per
taxonomy field, but rather a single column with a string derived from all
taxonomy fields.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Currently, the notes field uses a QTextEdit, which doesn't
send a signal if it goes out of focus. But for undo of
dive-editing we don't want to create an undo object for
*every* text change.
Thus, create a custom TextEdit widget that derives from
QTextEdit and turns the focusOutEvent into a editingFinished
signal.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In the dive site widget, use the undo commands instead of editing
only on accept. This introduces an inconsistency betwee the
name and description and the other fields. This will be fixed
in follow-up commits.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
If the name of a dive site is edited, it might wander somewhere
else in the table and thus out of view. Hook into the "dive site
changed" signal and scroll there.
The code is rather subtle as it depends on signals being called
in a certain order: First the item is moved in the model, only
then can we scroll to the correct place.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When adding a dive site, enter the name field of the new dive site.
Thus, when adding a new dive site, the user can immediately edit the
name.
The code is rather subtle: It hooks into the dive site added signal
before executing the command and unhooks afterwards. This only works,
because signals are executed in order of connect - thus the model
adds the index first and only *then* is the field edited.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Implement a dive site addition undo command and connect it to
the add dive site button. The added dive site has a default
name ("new dive site").
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Simply duplicate the code of dive site name editing. Split out
the common functionality that swaps a C and a Qt string.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
There was a way of deleting dive sites by clearing all fields.
This is not necessary anymore, as now the user can delete a
dive site in the dive site list.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This feature will be replaced by.
1) An explicit purge empty dive sites feature.
2) Not allocating dummy dive sites for GPS coordinates.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Implement an undo command that edits the name of a dive site.
Connect it to the dive site table, so that names can be edited
directly in the table.
Send signals on undo / redo so that the dive site table and
the dive site edit widget can be updated.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Create a new undo-command for deleting dive sites. If there are dives
associated with that site, the dives will be removed. The frontend
is not yet updated in such a case, as that infrastructure is in a
different PR.
Connect the trashcan icon of the dive site table to the undo command.
Currently, this code is in the dive site model, which makes little
sense, but is how the TableView class works. We might want to change
that when cylinder and weight editing are made undoable.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The LocationInformationModel used to sort its entries and was completely
rebuilt after every change. This makes it rather complex to support
incremental changes.
Instead, keep LocationInformationModel sorted by UUID so that indexes
are consistent with indices in the core dive site table.
Implement sorting by other columns than name and enable sorting in the
dive site view.
Finally, don't cache the list of dive site names for the mobile app,
since that would also need some rather convoluted methods of keeping
the list up to date. Calculate it on the fly.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>