In DiveListModel::data() a DiveObjectHelper was created for any
data-access. Create it only when a DiveObjectHelper is actually
returned.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Since DiveListModel does not keep its own list of dives anymore,
insertDive() doesn't use the DiveObjectHelper argument. Remove it.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The clear()/addAllDives() pair was bogus as the former didn't
clear the model (this is not possible anymore - the model
represents the core dive list) and the latter readded all
dives again.
Replace this by a reload() function.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of keeping track of a list of DiveObjectHelpers, generate
them on-the-fly in DiveListModel. Thus, there is less danger of
model and core getting out of sync. On the flip-side, now the
DiveListModel and the DiveListSortModel might get out of sync.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
DiveObjectHelper is a tiny wrapper around dive * to allow access
to dive data from QML and grantlee. It doesn't have to be a
full-fledged QObject with support for signals, etc. Therefore,
turn it into a Q_GADGET based object. This allows us passing the
object around as object, not as pointer to DiveObjectHelper.
This makes memory-management distinctly easier.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
We don't want to generate a DiveObjectHelper numerous times for
every item in the dive list. Therefore, return this data directly
from the model. In this case, don't remove from DiveObjectHelper,
as these data might be used by grantlee templates.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
We don't want to generate a DiveObjectHelper numerous times for
every item in the dive list. Therefore, return this datum directly
from the model. In this case, don't remove from DiveObjectHelper,
as this datum might be used by grantlee templates.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
We don't want to generate a DiveObjectHelper numerous times for
every item in the dive list. Therefore, return this datum directly
from the model. In this case, don't remove from DiveObjectHelper,
as this datum might be used by grantlee templates.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
We don't want to generate a DiveObjectHelper numerous times for
every item in the dive list. Therefore, return this datum directly
from the model. In this case, don't remove from DiveObjectHelper,
as this datum might be used by grantlee templates.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
We don't want to generate a DiveObjectHelper numerous times for
every item in the dive list. Therefore, return this data directly
from the model. In this case, don't remove from DiveObjectHelper,
as these data might be used by grantlee templates.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
We don't want to generate a DiveObjectHelper numerous times for
every item in the dive list. Therefore, return this datum directly
from the model.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The canonical way of displaying lists in Qt is via models.
Thus, return the tripId directly from the DiveListModel instead
of going indirectly via a DiveObjectHelper. In the future, this
will allow us to make the DiveObjectHelper value-based, as it
is not generated numerous times for every list item.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
These properties are not needed anymore, because the full text search
was decoupled from the DiveObjectHelper.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
1) The full text search was looping over the DiveListModel when
it could simply loop over the core model. Do that instead.
2) Don't generate a DiveObjectHelper to do a full text search.
Currently this is harmless as the DiveObjectHelper is only
a disguised "dive *". But from a conceptual point of view,
it represents the full representation of a dive and we don't
want to generate that in a tight loop.
This will help in
1) Making the DiveObjectHelper a non-reference object.
2) Moving fulltext search to the core and thus making it available
to desktop and more performant.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
There used to be code to remove the old planner notes when replanning
a dive. It used a global variable and seemed rather brittle. Moreover,
the place that set the global variable was inadvertently removed.
Therefore has been effectively dead code.
Reimplement the functionality, but be more robust by considering
that the deco-type may have changed: Split the translated disclaimer
string in two parts, before and after the "%s" place-holder.
Search for these two parts. Remove the disclaimer and everything
after the disclaimer.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
"Roles" is a C-style enum (i.e. not C++-style enum class). Since that
means that the names spill into the outer namespace, the names
themselves are prefixed with "Role". Nevertheless the code qualified
the names with "Roles::". This is redundant and unnecessary.
Remove this redundancy to show that we understand how the language
works.
Note: we could also transform the enum into an enum class and remove
the "Role" prefix from the names. That would arguably be "cleaner",
but then the enum doesn't auto-convert to/from int, but Qt uses int
to pass the roles to functions. So let's go the simple way that
avoids casting.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Since this is no longer a Q_METATYPE, nobody will try to
default construct this object. Remove the default constructor
and guarantee that there will be no null divesite.
Of course, the lack of default constructor means that the
default argument to the "selected" member variable should
be removed.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Let's face it: this is a value type. No point in having Java-style
getters and setters. Replace by plain old and boring member variables.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Nobody was listening for that signal. Remove it. This, quite
obviously, makse the setCoordinateNoEmit() function redundant.
Merge with setCoordinateNoEmit().
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
We never dish out an object of this type to QML. It is unclear how
Q_PROPERTIEs could be of any use.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Recently we changed the MapLocationModel-items to store whether
they are selected. Thus, we can directly export an isSelected
flag instead of calling a function taking a dive-site argument.
1) This makes the QML easier to read.
2) This avoids passing pointers through QML which has caused
us lots of pain.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
To connect a model to QML, one is supposed to provide a
QHash<int, QByteArray> MapLocationModel::roleNames()
function that returns a role -> attribute-name hash.
That was realized by filling the hash in the constructor,
storing it as a member variable, using static strings that
were declared in the class-definition and defined in the
translation unit.
Adding a new role was a pain and the whole thing was totally
pointless as the attribute names were used nowhere else and
the roleNames() function is called only once.
Simply do, what we do everywhere else: initialize the hash
in the roleNames() function and use normal string literals.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When editing the dive site, for certain fields a divesChanged signal
was emitted so that the dive-list can be updated.
Arguably it is wrong to decide which fields are relevant to the
dive list in the undo-command code. Therefore, let the list
catch the dive-site-edited signal and decide itself.
But the actual reason for this commit is that if the dive-site
field of a dive changes, we might have to reload the dive-location-model
because suddenly a new dive site appears. Now if this is done
in QML context on some Qt version (notably 5.9) we get crashes
later on. But that can happen if the user moves a flag. So in that
case only send a diveSiteChanged signal.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Since changing the highlighting to use the selected dive, dive
sites with no dive were never highlighted in dive site mode.
Obviously, because there was no dive to be selected.
Therefore special-case all dive-site selection code to recognize
when we are in dive site mode.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Since selection change doesn't to a full map reload, we have to
reload the map on filter changes, since the shown dive sites change.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Since not fully reloading the map on selection change,
the selected sites were not moved to the top. Not calculating
the z-value in QML, but making it a simple model property
helps.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When clicking a dive site on the map, the QML code would set
the selected dive site, but then all dives of dive sites in
the vicinity were set. But still only the clicked-on dive site
was shown.
Therefore, don't set the list of selected dive sites in QML,
but later in DiveListView::selectDives(), where we know all
the dives that were selected.
This, again, gives nasty entanglement of diverse widgets and
models.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When changing the selection the MapLocationModel was reset.
This lead to crashes on Qt-5.9 which are due to QML accessing
data that was freed during model reset. This putative Qt bug
doesn't happen on newer Qt versions. At least Qt-5.12 is known
to work.
Instead of fighting the bug, let's simply not reset the model
but send a dataChanged() for every element of the MapLocationModel.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Experimentation has shown that the image of a flag will
only be changed after dataChanged() if it is a simple
property. The old code had a complex QML expression and
then - for some reason - it didn't work.
To give us better control over the flags and avoid full
reloads of the map therefore introduce a model-property
pixmap name. The name depends on whether the site is
selected and if not, whether we are in divesite-edit mode.
This makes the code rather convoluted. Firstly, we have
to save whether the site is selected in the map-item.
Secondly we have to access the global map-widget, which
in turn has to go to the map-widget helper (layering
violation!).
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When clicking on a flag
1) The QML would call MapLocationModel::setSelected() with
fromClick = true
2) MapLocationModel::setSelected() would emit a signal
selectedLocationChanged()
3) MapWidgetHelper would catch that signal and do the actual
processing.
Other functions would call MapLocationModel::setSelected() with
fromClick = false, which would not emit the selectedLocationChanged()
signal.
Detangle this a bit by calling the selectedLocationChanged() function
directly from QML and remove the fromClick parameter.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Just to be sure, refuse to add null divesites to the selection.
Moreover, refuse to call the setSelected function on a null-divesite.
I got an unfriendly Qt-Warning there:
"Passing incompatible arguments to C++ functions from JavaScript is
dangerous and deprecated."
"This will throw a JavaScript TypeError in future releases of Qt!"
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The create_plot_info_new() function releases old plot data. This
can only work if the plot_info structure was initialized previously.
The ProfileWidget2 did that by a memset, but other parts of the code
did not.
Therefore, introduce a init_plot_info() function and call that when
generating a plot_info struct. Constructors would make this so much
easier - but since this is called from C, we can't use them.
Fixes#2251
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Indexes go from 0 to count - 1. Thus, the comparison for invalid
indexes has to read ">= count", not "> count".
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
There have been crash reports in DiveSiteSortedModel::allSiteNames().
The only conceivable reason that this crashes is that the core knows
about more sites than the model and therefore on mapToSource() we
get an invalid index, which is translated to -1. Accessing the name
of that dive site will crash.
Handle such invalid indexes gracefully.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The fill_default_cylinder() function calculated the MOD based
on the currently displayed dive. This does not seem to make sense:
- When importing dives, why would we care about the altitude and
salinity of the currently displayed dive, possibly from a different
trip.
- The planner is supposed to be thread-safe and should not touch
global variables.
Of course this means that the importing-functions have to fill
out altitude and salinity before creating the default cylinder,
but this is their problem. For a freshly created dive they will
get the default values, which still seems less random than the
values from the displayed dive.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Commit 0c38754916 introduced a
bug in MapLocationModel::reload() by setting an entry in the
name-to-location map before the location was initialized.
Move the setting of the map entry back where it was before:
after the assignment of the location variable.
Moreover, define the location variable directly on allocation
of the location to avoid thus bugs in the future.
Why did we not get a "might be used unitialized" warning
anyway?
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When pressing F2 in the dive list, the number can be edited.
Make this action undoable by implementing a EditNumber command.
This command is differs from the other undo commands, as not the
currently selected dives are changed. This means that the EditCommand
needs an alternative constructor taking a single dive. This constructor
was implemented in the base class so that all edit commands can now
be called with a single dive.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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>
Another tiny step in making dive.h smaller: move function
declarations to deco.h if these functions are defined in deco.c
and don't directly concern dives.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
qt-models/models.h included dive.h and divelist.h. Remove these
unnecessary includes, to reduce interdependencies. A drop in the
bucket, for sure.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
For historic reasons, there where three distinct signals concerning
dive-selection from the undo-machinery:
1) divesSelected: sent newly selected dives
2) currentDiveChanged: sent if the current dive changed
3) selectionChanged: sent at the end of a command if either the selection
or the current dive changed
Since now the undo-commands do a full reset of the selection, merge these
three signals into a single signal.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>