Just as we did for pointer to struct dive_site, make pointers to
struct dive and struct dive_trip "Qt metatypes". This means that
they can be passed through QVariants without taking a detour via
void *.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The dives of each trip were kept in a list. Replace this by a
struct dive_table. This will make it significantly easier to
keep the dives of a trip in sorted state.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The dive list was sorted using the default-sorter of
QSortFilterProxy model. This is mighty inflexible as it
considers only one column. This has the funky effect that
for rows with identical elements, the sort order depends
on the previous sorting.
Implement a lessThan() function in the MultiFilterSortModel,
which simply hands the sorting down to the actual model.
This might be considered a layering violation, but it makes
things so much easier.
Sadly, it seems like the column-to-be-sorted is transported
in the provided indices. Therefore, the comparison is chosen
using a switch for *every* comparison. It would seem much
more logical to set a function pointer once and use that.
Further investigations are necessary.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The data-flow from C-core to list-view is as follows:
C-core --> DiveTripModel --> MultiSortFilterModel --> DiveListView
The control-flow, on the other hand, differs as DiveListView
accesses both MultiSortFilterModel and DiveTripModel, whereas
MultiSortFilterModel is mostly unaware of its source model.
This is in principle legitimate, as the MultiSortFilterModel might
be used for different sources. In our particular case, this is
not so. MultiSortFilterModel is written for a particular use case.
Therefore, model control-flow follow after data-flow: Let MultiSortFilterModel
set its own source model and DiveListView access the MultiSortFilterModel,
which then manages its source model.
This is not bike-shedding, but will enable a more flexible and
higher-performance sorting.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
To test whether to show a dive, the UUIDs of the filtered-by
location and the dive-site of a dive were compared. Since UUIDs
are unique (as the name implies), directly compare pointers.
Note: this code comes from a time when the filtered-by location
was not a pointer, but a copy.
Moreover, the if tested first for the same name, then (logical-or)
for the same uuid. This makes no sense, as the same dive-site
implies the same name. This code likewise can be explained by
historic reasons: the filtered-by location may have contained
a different name. Swap the order of the conditions: first test
for the same object and only of the objects differ, test for
the same same.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Replace the UUID reference of struct dive by a pointer to dive_site.
This commit is rather large in lines, but nevertheless quite simple
since most of the UUID->pointer work was done in previous commits.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This is another case of a weird pattern where an object would
connect it's own signal to the slot of a different object.
There seems to be no reason why the former couldn't simply
call the latter.
Remove the [start|stop]FilterDiveSite signals of LocationInformationWidget
and call the corresponding functions of MultiFilterSortModel directly.
While doing so, replace the UUID argument by a pointer-to-divesite.
It will be converted anyway right at the beginning of the function.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
After invalidating the filter, the dive-selection was modified to
ensure that at least one dive is selected. This was done in the
filter code, but it seems preferrable to do this in the dive-list
code, which has direct access to the selection-model.
Therefore, move the code from MultiFilterSortModel to DiveListView.
While doing so, split the code in DiveListView into more functions to:
1) Get the index of the first dive (if any).
2) Select the first dive (if any).
This allows a distinct size reduction of conditional compilation
in MultiFilterSortModel (accesses to MainWindow are not possible
in mobile code).
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of the weirdly named "information" and the inconsistent
"dive_list" use the logical "mainTab" and the camel-cased
"diveList", respectively.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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>
Currently, the filter is recalculated if a filter-entry is changed.
This also happens if the counts of a filter-entry changes. This
is to be avoided, as it causes unnecessary churn.
Therefore, send the proper role with the dataChanged() signal
and add a new slot, which invalidates only if a field with the
Qt::CheckStateRole is changed.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of reloading all the filter, only increment / decrement the
count of the entries of added / removed dives.
Originally, this was planned to be done via the signals from the
divelist, but it turned out that this was suboptimal, because
if the filter decides that the new item is selected, this has to
be done *before* adding the dive. Otherwise, it wouldn't be shown.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
All callers of FilterModelBase::updateList() sorted the items
(except the last one). Thus we can do the sorting inside the
function.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Since FilterModelBase now contains complex data (counts and checked),
we might just as well make it a full model and keep track of
the name as well. I.e. do not derive from QStringListModel but from
QAbstractListModel and add the name to the item structure.
Implement proper reset / add / rename semantics. This is overkill at the
moment, as after all any modification the model will be reset, but
ultimately it will allow us to be smarter and only update rows when
needed.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Currently, in FilterModelBase::data() the number of dives is recalculated.
This happens for every mouse-over event!
Calculate the number of dives only on recalculation and store the count
in the items-struct.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In the future, we might be smarter about the dive-counts and calculate
them only once and incrementally (if e.g. new dives are added).
Prepare for more complex caching by turning the checked boolean into
a struct, which can then be extended by a count and other things
(e.g. the name).
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The filter code was an unholy intermixture of backend and frontend
logic, which made it hard to access it from outside of the UI.
Notably, it expected that Qt would call filterAcceptsRow on all rows.
For trip-view, apparently the filter functions were called twice
(once for filtering the trip, then for filtering the individual dives).
Make the filtering explicit, by calling showDive() for all dives in
MultiFilterSortModel::myInvalidate(), setting the hidden_by_filter
flags accordingly and ultimately invalidating the filter.
The UI code only accesses the hidden_by_filter flag set previously.
The "justCleared" flag can then be removed, since accessing the filter
does not have side effects. Moreover, there is no noticeable performance
gain by returning out early.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
To make dive-filtering accessible from other parts of the code,
break out the actual dive-filtering code into a function that
takes a pointer-to-dive instead of QModelIndex.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Conceptually, the doFilter() functions shouldn't modify the dive
they test. Therefore, make the argument const. To do this, constify
the parameter of get_dive_location(), which likewise seems to be
the right thing to do.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Change the signature from of the virtual doFilter() functions from
bool doFilter(struct dive *d, QModelIndex&, QAbstractItemModel*) const;
to
bool LocationFilterModel::doFilter(struct dive *d) const;
as the QModelIndex and QAbstractItemModel parameters were not used.
This makes this functions independent from Qt's model/view
framework. This is in preparation for making the undo-machinery
compatible with the filtering.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The function DiveListView::fixMessyQtModelBehaviour() was used to
expand the first columns of dive-trips in the dive-list view.
This function was called everytime that the dive-list was modified.
It is kind of ludicrous that external callers would have to
tell the DiveListView, when it has to update its column headers.
Instead, place this functionality in the overriden reset() and
rowsInserted() functions, as these are the only ways that
rows can be added. Change the DiveTripModel to use the proper
beginResetModel()/endResetModel() pair instead of the previous
full deletion and full repopulation using the beginRemoveRows()/
endRemoveRows() and beginInsertRows()/endInsertRows().
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>
Mostly replace "return (expression);" by "return expression;" and one
case of "function((parameter))" by "function(parameter)".
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
CID 208296. IndexOf can return -1 when not found, which will
not happen in this context, so just to silence Coverity.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
With commit 5962f00679, a well known problem was introduced.
Incorrect width setting for the spanning trip lines. And as there
is even a specific functon for that, just call this.
The reason the mentioned commit introduces this, is that
invalidate() causes layoutChanged signals, and invalidateFilter()
does not.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
This is mainly code maintenance. Instead of emitting explicit
dataChanged signals, we can make sure that setStringList()
is called after all model data manipulation is ready. Accoording
to the Qt docs: "The model will notify any attached views
that its underlying data has changed".
In itself, this does not solve the tripped assert mentioned in
commit 5962f00679, but this calling at the end just feels
better.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
This "bug" is found using Qt 5.10 compiled in developer mode. Access
the filers, click a little around here, close the filters. Almost every
time the following assert is triggered:
ASSERT failure in QPersistentModelIndex::~QPersistentModelIndex:
"persistent model indexes corrupted", file itemmodels/qabstractitemmodel.cpp, line 643
This is relatively deep down in Qt, and it is triggered by clearing the
filters. Trying to force a crash when using the same scenario in Qt 5.10
compiled for production (so no active asserts) did not result in a crash.
So, upto this time, it is unclear if the Qt assert points out a real problem,
or it is some false alarm (for whatever reason).
Further investigation shows that the assert can be solved by changing the
invalidate() to an invalidateFilter(). Indeed, the last variant is a little
more lightweigt, and does seem to do the same job from a functional point
of view (in this case).
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
FilterModelBase is a direct subclass of QAbstractItemModel. Therefore,
dynamic_cast<>ing the former to the latter is unnecessary. Probably
an artifact of previous code.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Introduce toggle buttons which mean "filter all dives except
those fulfilling the selected criteria".
The old code used to check for rowCount() == 0. This should never happen,
because there is always a row "empty field". This check was moved into
the preamble of the functions to seperate it from the actual logic.
Fixes#435
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
We aren't really consistent. And I don't do this often enough. But based
on a few things that I saw in a recent commit, I wanted to at least fix
those. And then of course fixed everything in those two files.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
To every filter list add a menu button that allows selection of all,
selection of none or inversion of selection.
Implements #435.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The *FilterModels had a number of of virtual functions, which only
accessed members of the base class. Moreover, these functions were
identical and generated with macros. Therefore, move these functions
to the base class.
The one excption is data(), which uses different count functions
(passed as a macro parameter). Thus, introduce a virtual countDives()
function and likewise move data() to the base class. A function pointer
might be even more clear, but since the rest of the code/Qt relies
heavily on runtime polymorphism, let's do the same here.
The only macros left are those creating the singleton accessors.
This could be more clearly realized by templates, but let's
likewise keep it the way is.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
There were two classes, MultiFilterInterface and FiterModelBase.
The latter derives from the former and from QStringListModel.
The former was not used anywhere else. Moreover, in contradiction
to its name, MultiFilterInterface is not an interface (in the Java
sense), because it actually has (non-virtual) data members. All in
all, the data model is very weird.
Merge these two classes, since there seems to be no gain whatsoever
from keeping MultiFilterInterface separate.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Commit 6343515fed introduced equality
instead of substring comparison for filters. This broke the buddy
filter in the case of more than one buddy, because in such a case
the buddy list is a comma-separated string.
Fix this by splitting the buddy string, trimming the individual
strings and search in the list.
Fixes#969
Reported-by: <yrevawerd@gmail.com>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
If the user implicitly adds a dive site by editing a dive, and
a location filter is active, check the new dive site in the
location filter.
This is done by informing the LocationFilterModel of the new
dive site name prior to repopulation. The LocationFilterModel
then adds a corresponding entry and marks it as checked.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Since commit 01d961086c, the location filter
list is updated if a dive site is edited. The problem is that if the
name of a selected dive site is changed, the selection is lost.
Therefore, before repopulating, inform the location filter that a dive
site changed its name. The location filter then internally changes the
name and can properly transfer the old selection on repopulate. This is
performed via the new LocationInformationWidget::nameChanged signal,
which is connected to the new LocationFilterModel::changeName slot.
A special case to be handled is the following:
[ ] Site 1
[x] Site 2
and "Site 2" being renamed to "Site 1", i.e. both sites being merged.
Here, the merging is detected and "Site 1" will likewise be checked:
[x] Site 1
[x] Site 1
No merging is performed, as the list will be repopulated anyway.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is a continuation of commit 739b27427c,
in which a substring comparison was replaced by equality comparison to
avoid confusing UI behavior of the filter interface.
The suit and buddy filters were plagued by the same problem, so change
their code in analogy.
Fixes#551 (in conjunction with commit dd2466f518).
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Update the filters if the list of dives is updated by calling
MultiFilterSortModel::instance()->myInvalidate();
This had the side effect of clearing all selections. Thus, in
the repopulate() methods of the FilterModels, check those
entries that were checked previously. Since all the filter
models use the same code, introduce a base class FilterModelBase.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This replaces a dynamically allocated array of bool by std::vector<char>.
1) This makes the code shorter and less error prone, because memory
management has not to be done by hand.
2) It fixes a bug in the old code:
memset(checkState, false, list.count()) is wrong, because bool is
not guaranteed to be the same size as char!
Two notes:
1) QMap<>, QVector<>, etc. are used numerous times in the code, so
this doesn't introduce a new C++ concept. Here, the std:: version
is used, because there is no need for reference counting, COW
semantics, etc.
2) std::vector<char> is used instead of std::vector<bool>, because
the latter does a pessimization where a bitfield is used!
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The location filter used a substring comparison, which had
the side effect that dives with the location "Test 1" were
shown when filtering for "Test 12".
Moreover, avoid a deep copy of the location list. This is
done by looping over one item less than rowCount() instead
of removing the last item. While doing this, remove an
unnecessary if-statement.
This commit partially fixes#675.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Commit aa1446bed2 ("Make filters work again in master") makes filters
work again for the desktop app, but breaks building Subsurface-mobile.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Since 6cd711a1 filters don't work. This went unnoticed because the
commit wasn't applied on v4.5-branch.
Partially reverting it makes filters work again.
Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Having subsurface-core as a directory name really messes with
autocomplete and is obviously redundant. Simmilarly, qt-mobile caused an
autocomplete conflict and also was inconsistent with the desktop-widget
name for the directory containing the "other" UI.
And while cleaning up the resulting change in the path name for include
files, I decided to clean up those even more to make them consistent
overall.
This could have been handled in more commits, but since this requires a
make clean before the build, it seemed more sensible to do it all in one.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Since we have now destkop and mobile versions, 'qt-ui' was a very
poor name choice for a folder that contains only destkop-enabled
widgets.
Also, move the graphicsview-common.h/cpp to subsurface-core because
it doesn't depend on qgraphicsview, it merely implements all the
colors that we use throughout Subsurface, and we will use colors on both
desktop and mobile versions
Same thing applies for metrics.h/cpp
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>