There was a tank info with an empty name. According to a comment,
this is needed for the "no cylinder" case. However, we now support
empty cylinder tables, so this is not needed anymore. Therefore,
remove it.
Make sure that the user can still enter the empty name, just in
case. But don't save the size and pressure in that case.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
There seems to be no point to saving data to the tank with
the empty name. Don't save tank-pressure and size to that
tank info.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
User request: when entering a cylinder type, do a substring
search. For example, when entering "100" also find "AL100".
Currently, a starts-with search was used.
This is simply done by setting the "filterMode" of the
ComboBoxDelegate to "Qt::MatchContains".
Suggested-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of getting the index and using that to access values, use
the taxonomy_get_value() helper function. Two places are affected:
1) reverse geo-lookup
2) location filter delegate
The behavior of reverse geo-lookup is changed slightly: now an
empty string is likewise recognized as missing "TC_ADMIN_L3".
Before, only a missing category was interpreted as such.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This was still using the archaic macro version, because Qt decided
to parameter-overload the signals (which turned out to be a horrible
idea). However, since we switched to fairly recent Qt this can be
solved using the qOverload template.
In this case things are a bit more complicated because we overload
the corresponding slots. Since we have control over that, let's
just disambiguate their names instead of using the cryptic qOverload.
While doing this, tighten the access specifiers of the slots. Turn
public into private and protected as appropriate.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
We put the pointer and reference modifier to the variable, not the
type. Some people don't like this, but
1) This is consistent with the rest of the code base.
2) This is how C and C++ parse, love it or hate it.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When creating a TankInfoDelegate editor, reploting of the profile
was disabled to avoid replotting when the user scrolls through
the tank-info list. Since the code was changed to only set the
tank-info when the editor is closed, this became unnecessary
(hopefully). Indeed the clearing of the flag was removed in a
previous commit. This means that we also have to remove the setting
of the flag. Since this is all the TankInfoDelegate::createEditor()
function was doing, we can remove the whole function.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The comment states that Qt treats TAB as cancel when in the combobox.
However, testing shows that this use-case works without this hack.
Since it caused weird behavior (the data was set *after* the editor
was closed, leading to inconsistent state), remove it.
Note: this overrides the previous commit, which is therefore redundant
from a history point of view. However, I'll leave the previous commit
in so that if something turns out to break, we can figure out which
of the two changes it was.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
fixTabBehavior() set the editor text *after* closing the editor.
This left us in an inconsistent state where we thought that the
editor is active. By reversing two connects, this problem is resolved.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
All combobox-delegates shared a number of static status fields.
In a quest to make the code more reentrant, move that to the
actual object. The fields have to be defined as mutable, since
they are set in const member functions.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Update of the profile is now done by the undo-commands. If the
planner needs this, it is probably better to connect directly
to the model, not the delegate.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
For reasons that I don't understand, we keep track of the
current combo-box text for our model-delegates. However,
that text was not initialized when the editor was generated,
leading to a UI bug in the cylinder and weight widgets:
Activate a field, click somewhere else -> either the empty
string or the previous string was set.
Reported-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This one is tricky, as when browsing through the types-combobox,
the user is presented with presets without actually changing the
dive. We do not want an undo-command for every change-event in
the combo-box.
Therefore, implement a scheme analoguous to the weight-editing:
A temporary row can be set / committed or reset. Sadly, the
code is more complex because we have to consider the planner,
which is not included in the undo system.
Firstly, the planner uses a different model, therefore all
interactions are channeled through setData() with special roles.
Secondly, in the planner we shouldn't place an undo command,
but simply overwrite the dive.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The weightsystem info for new weightsystem types is added by the
undo command. Remove this redundant code. Use the lookup only to
determine the weight and the canonical name (i.e. use the capitalization
according to the saved entry, in analogy to tanks).
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
In the wightsystem-type and cylinder-type delegates, when entering
data, when entering known weight- or cylinder-types, some ui fields
(notably weight, size and working-pressure) are automatically filled
out. The search was using the default flags provided by Qt: starts-with
and case-insensitive.
This had a few strange effects, when entering a string that is the
beginning of a known string (e.g. "AL6" when "AL63" already exists):
1) The wrong data was used if the new string didn't exist.
2) For cylinders it was impossible to create new cylinder types whose
name is the starting string of a different type.
3) For weights, the new type was not added to the list of known types.
This, however, is no problem, because it will be added by the undo
command anyway. A future commit will address that redundancy.
Therefore use only the case-insensitive flag (which has to be performed
by passing the MatchFixedString flag - very weird).
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The tank-info-delegate cast its model to CylindersModelFiltered,
since this is what the equipment-tab uses since implementing the
filtering of unused cylinders. However, the planner users the same
delegate and still uses the unfiltered CylindersModel. This means
that the (dynamic) cast returns a null pointer and crashes.
One possibility would be to derive CylindersModelFiltered and
CylindersModel from the same class that defines virtual functions
and cast to that class.
This is a different attempt: don't cast (i.e. stay with a
QAbstractItemModel and play it via Qt's model-view system. Firstly,
replace the passInData function by a role to setData(). Secondly,
read the working-pressure and size via new columns using data().
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When the show_unused_cylinders flag is not set, the cylinder tables
in the equipment tab and the planner should not show unused cylinders.
However, the code in CylindersModel is fundamentally broken if the
unused cylinders are not at the end of the list: The correct number
of cylinders is shown, but not the correct cylinders.
Therefore, add a higher-level CylindersModelFiltered model on top
of CylindersModel that does the actual filtering. Some calls are
routed through to the base model (notably those that take indexes,
as these have to be mapped), for some calls the caller has to get
access to the source model first. We might want to adjust this.
For filtering, reuse the already existing show_cylinder function
and export it via CylindersModel.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
It's not even clear if we need the setCaseSensitivity() call as it appears
that a case insensitive completer is the default.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The WSInfoDelegate (weight-system-info delegate) is used to display
a combo box of known weightsystem-types and auto-fills the weight if
the weightsystem-type is changed.
This would overwrite the weight data of the displayed dive when the
user hovers over the different entries. Moreover, it saves the original
weight in case the user cancels the editing action.
This is not viable when implementing undo of weightsystem changes,
because hovering over entries should not produce individual undo
commands. Instead, implement a special "temporary" row in the
weightsystem model. On canceling of the edit actions, simply reload
the weightsystem from the unmodified dive.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
There is only one caller of WeightModel::weightSystemAt() and that
certainly does not need a pointer into the weightsystem-table of
the current dive. Return a value type instead of a pointer.
This allows us to mark WeightModel::weightSystemAt() as const and
use it from WeightModel::data(). Slightly cleaner code.
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>
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>
1) The second parameter (selected_only) was always false. Therefore,
remove it.
2) Simplify the function by simply returning the reference count.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Add a dive site table to each dive site to keep track of dives
that have been added to a dive site. Add two functions to add
dives to / remove dives from dive sites.
Since dive sites now contain a dive table, the order of includes
had to be changed: "divesite.h" now includes "dive.h" and not
vice-versa. This caused some include churn.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
printGPSCoords() returned a newly allocated C-style string. Most
callers simply made a QString out of it and freed the C-style string.
This is paradoxical, as printGPSCoords internally works with QStrings
and converts them to C-style on return.
Therefore, let printGPSCoords() return a QString and create a
printGPSCoordsC() wrapper for the two C-callers.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The printGPSCoords() function returns a copied C-style string. Since
the owndership is transferred to the caller, the correct return type
is "char *" instead of "const char *".
Thus a number of casts when calling free can be removed.
Moreover a number of callers didn't free the string and thus were
leaking memory. Fix them. Ultimately we might want two versions
of the function: one for QString, one for C-style strings.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The DiveTripModel was used to represent both, trip and list views.
Thus many functions had conditionals checking for the current mode
and both modes had to be represented by the same data structure.
Instead, split the model in two and derive them from a base class,
which implements common functions and defines an interface.
The model can be switched by a call to resetModel(), which invalidates
any pointer obtained by instance(). This is quite surprising
behavior. To handle it, straighten out the control flow:
DiveListView --> MultiFilterSortModel --> DiveTripModelBase
Before, DiveListView accessed DiveTripModelBase directly.
A goal of this commit is to enable usage of the same model by mobile
and desktop.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
There was this ugly pattern of passing pointers-to-dive_site via
a QVariant of void * type. This is of course inherently unsafe.
Pass these pointers using their proper types instead. This makes
it necessary to register them in Qt's meta-type system. Doing so,
fixes a bug: QML couldn't call into updateDiveSiteCoordinates()
because it didn't know the type and thus the coordinates of
the moved flag were not reflected in the divesite-dialog.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Replace UUIDs from LocationInformationModel and fix the fallout.
Notably, replace the UUID "column" by a DIVESITE "column".
Getting pointers through Qt's QVariant is horrible, we'll have
to think about a better solution.
RECENTLY_ADDED_DIVESITE now defines to a special pointer to
struct dive_site (defined as ~0).
This fixes an interesting logic bug:
The old code checked the uuid of the LocationInformationModel (currUuid)
for the value "1", which corresponded to RECENTLY_ADDED_DIVESITE.
If equal, currType would be set to NEW_DIVE_SITE. Later, _currType_
was compared against _RECENTLY_ADDED_DIVESITE_. This would only work
because NEW_DIVE_SITE and RECENTLY_ADDED_DIVESITE both were defined
as 1.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of passing a uuid, pass a pointer to the dive site.
This is small step in an effort to remove uuids.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of having people treat latitude and longitude as separate
things, just add a 'location_t' data structure that contains both.
Almost all cases want to always act on them together.
This is really just prep-work for adding a few more locations that we
track: I want to add a entry/exit location to each dive (independent of
the dive site) because of how the Garmin Descent gives us the
information (and hopefully, some day, other dive computers too).
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
The keeps track of different sub widgets needed by other parts
of the code, notably:
MainTab
PlannerDetails
PlannerSettingsWidget
ProfileWidget2
DivePlannerWidget
DiveListView
Access to these widgets was provided with accessor functions.
Now these functions were very weird: instead of simply returning
pointers that were stored in the class, they accessed a data
structure which describes the different application states.
But this data structure was "duck-typed", so there was an
implicit agreement at which position the pointers to the
widgets were put inside. The widgets were then down-cast by
the accessor functions. This might make sense if the individual
widgets could for some reason be replaced by other widgets
[dynamic plugins?], but even then it would be strange, as one
would expect to get a pointer to some base class.
Therefore, directly store the properly typed pointers to the
widgets and simply remove the accessor functions. Why bother?
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When editing a dive, in the location box a list of dive sites is
shown containing the distance to the current dive site. This was
implemented via the global displayed_dive_site object, which is
set when switching between dives. This seems like an unnecessary
indirection. Instead, use the current_dive macro.
This is part of a series to refactor dive-site handling to use
pointers instead of UUIDs and a general push to reduce global state.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Include font metrics as part of the height in DiveListDelegate::sizeHint().
When 22px is hardcoded, this handles small fonts, but for larger
fonts it seem that the bottom of the dive list row text is cut
on Windows.
Keep 22px as the minimum size hint, but for larger fonts
use QFontMetric::height().
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
There were a handfull instances of the kind
1) gettextFromC::instance()->tr(...)
2) gettextFromC::instance()->trGettext(...)
1) is pointless, as tr is a static function.
All instances of 2) were likewise pointless, because trGettext()
returns a C-string, which was then immediately converted to a
QString.
Thus, replace both constructs by gettextFromC::tr(...).
After this change there was only one user of gettextFromC::instance()
left, viz. the C-interface funtion trGettext(). Therefore, remove
gettextFromC::instance() and do all the caching / translating
directly in the global trGettext().
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Replace constructs of the kind
s.toUtf8().data(),
s.toUtf8().constData(),
s.toLocal8Bit().data(),
s.toLocal8Bit.constData() or
qUtf8Printable(s)
by
qPrintable(s).
This is concise, consistent and - in principle - more performant than
the .data() versions.
Sadly, owing to a suboptimal implementation, qPrintable(s) currently
is a pessimization compared to s.toUtf8().data(). A fix is scheduled for
new Qt versions: https://codereview.qt-project.org/#/c/221331/
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In desktop-widgets, remove globe.cpp, globe.h and also remove
the NO_MARBLE macro usage.
At this point the MapWidget will always be created and there will
always be a map in the application.
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Issue #272 lead to the introduction of a new private property of the
ComboBoxDelegate class (editable). This new property was not correctly
set when creating the weight system delegate. This corrects the (trivial)
error, and now allows edit of the weight system name.
Fixes: #392
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>