aboutsummaryrefslogtreecommitdiffstats
path: root/qt-models/filtermodels.cpp
AgeCommit message (Collapse)Author
2019-06-23Dive list: cache shown flag in model (quick-fix for undo-crash)Gravatar Berthold Stoeger
We have a very fundamental problem with data-duplication in core and qt-models. In a particular case, this led to an easily reproducible crash: 1) An undo command moved the last dive of a trip to another. 2) When an undo-command removed the last dive of a trip to a different trip, the dive was removed from the trip in the core. Then, the model was updated. 3) That lead at first to a rearrangement of the trips, because the trip with the added dive is moved before the trip with the removed dive. 4) In such a case, the filter-model checks the visibility of the trip. 5) Since the trip with the removed dive has no dives in the core, visibility was determined as false. 6) From this point on the mappings of the QSortFilterProxyModel were messed up. Accesses led to crashes. It is unclear whether this is a Qt bug or only a QOI issue. As a quick-fix, cache the visibility flag of trips directly in the Qt-models. Don't set the visibility directly in the core, but go via the Qt-models. Thus, a more clear layering is achieved. In the long run, we can hopefully get rid of the data-duplication in the models. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-19Cleanup: move trip-related functions into own translation unitGravatar Berthold Stoeger
These functions were spread out over dive.c and divelist.c. Move them into their own file to make all this a bit less monolithic. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-11Filter: prevent selection-change notifications in filter invalidationGravatar Berthold Stoeger
Invalidating the filter can cause numerous selection-change notifications. These cause a full UI reload. Therefore, go into "command" mode that was implemented for the undo commands. Then, all selection-changes are considered as "programmatical" and ignored. At the end of filter invalidation, a filter-finished signal causes a proper reload anyway. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-11Filter: don't reload when dive sites are set to the same valueGravatar Berthold Stoeger
When switching between the dive-site-table to the dive-site-edit tabs, the filter would be set to a dive site. Usually, this would be the same dive site as before. Nevertheless, this caused a full map-reload. Detect if the dive-sites to be filtered are the same and turn this operation into a no-op. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-11Filter: add reference counting for dive-site modeGravatar Berthold Stoeger
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>
2019-05-11Map: in dive-site-edit mode, select those maps we filter forGravatar Berthold Stoeger
When dive sites are edited, we shouldn't highlight the sites of the current dive, but the currently edited site(s). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-11Map: show all dive sites when in dive-site filter modeGravatar Berthold Stoeger
When on the dive site tab or editing a dive site, we want to show all dive sites so that the user can related different dive sites. Therefore export a "in dive site mode" flag from the filter model and don't filter in that case in MapWidgetHelper. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Filter: allow filtering multiple dive sitesGravatar Berthold Stoeger
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>
2019-04-12Filter: call update title directly in filter modelGravatar Berthold Stoeger
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>
2019-04-12Undo: update filter flag when dives changeGravatar Berthold Stoeger
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>
2019-04-12Dive sites: prepare for dive site ref-countingGravatar Berthold Stoeger
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>
2019-02-28Filter panel: add suit and notes search fieldsGravatar Willem Ferguson
All the field in the Notes Panel of the main window are now supported. This needs some testing especially for the Notes field that may contain markup. It appears ok to me for single term searches. One would like to think about the default search option for the Notes. There is a vertical spacer in the Filter panel that I moved downwards and whose function I am not quite sure of. [Dirk Hohndel: small adjustments] Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-02-28Append the dive mode as a tag that is seen by the filter tool.Gravatar willemferguson
This allows one to filter dives by divemode, e.g. by typing "CCR" or "Open circuit" in the tags textbox of the filter tool. Quite useful if one dives using more than one dive mode. For the purpose of the filter tool only the dive mode attribute is added to the list of tags for the specific dive being considered. The tag list for the same dive (in the XML dive log) is not affected in any way. Provide for translation in alternative languages (Response to bstoeger's suggestion). Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
2019-02-19Filter: implement any-of modeGravatar Berthold Stoeger
Add an additional mode to the tags, people and location filters: any_of. Replace the original invert-bool by an enum. Move the common code into a distinct function. Reported-by: Willem Ferguson <willemferguson@zoology.up.ac.za> Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-26Filter: quick implementation of negationGravatar Berthold Stoeger
Add negate buttons to the Tags, People, Location and Equipment filters. Currently, if nothing is entered the filter is ignored whether negate is on or off. One might think about filtering all dives without tags, etc. instead. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-26Filter: update counts if dives added / removedGravatar Berthold Stoeger
Update the filter counts if dives were added removed by the undo commands. The undo commands call into the filter model at the right time so that hidden_by_filter is already set. The filter model keeps track of the counts and emits a signal, which is caught by the widget. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-22Filter: support imperial unitsGravatar Berthold Stoeger
1) Choose the correct conversion function for comparison. 2) Add a unit suffix to the fields. 3) Update the suffixes on change of preferences. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-21Desktop, Filter UI: make date/time consistentGravatar Jan Mulder
On all (most?) places we use separate date/time fields for the time of a dive, and we follow the setting from the preferences to format those. Make the new filter widget consistent, with respect to the to and from interval. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2019-01-19Filter: make tags, people and location filter logically-andGravatar Berthold Stoeger
If the user provides multiple tags, they probably want to search for dive with *all* of these tags. Replace the convoluted loops by std::all_of(). This makes it trivial to change logically-and to logically-or: Replace std::all_of() by std::any_of(). Reported-by: Jan Mulder <jlmulder@xs4all.nl> Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-19Filter: reinstate dive-site filter functionalityGravatar Berthold Stoeger
Commit 201f0c8f89d6d7df96fd220ea2c0d0977c9b7f20 removed the dive-site filtering. This is needed for dive-site editing: The list should only show dives at the corresponding dive-site. As opposed to the original code, only compare for the actual dive-site, not for the name of the dive-site. The reason for comparing dive-site names is unknown. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-19Filter: ignore unset temperaturesGravatar Berthold Stoeger
The filter treated unset air and water temperatures as 0 K, leading to many dives not being shown. Don't filter on unset temperatures. Reported-by: Jan Mulder <jlmulder@xs4all.nl> Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-19Filter: update filterData directly without copyingGravatar Berthold Stoeger
In FilterWidget2::updateFilter() a new FilterData object is generated and then copied onto the filterData member variable. Instead, modify filterData directly. This seems also more logical from a semantic point of view: Do we want to reset fields that were not set by the user? Contains trivial whitespace fix. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-08Filter for logged/planned divesGravatar Robert C. Helling
Add filter for dives having a planned dive computer or a logged dive computer. Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-01-07Dive list: split DiveTripModel into distinct models (tree and list)Gravatar Berthold Stoeger
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>
2019-01-07Cleanup: Remove MultiFilterSortModel::modelGravatar Berthold Stoeger
The source-model was cached in MultiFilterSortModel. For simplicity, remove that and simply access via DiveTripModel::instance(). There is only one instance where the cached model was used: when comparing items for sorting. Thus, in indirection is added in a "hot" path. Nevertheless, this will dwarf against the cost of string comparison. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-12-14Hide unimplemented components from searchGravatar Tomaz Canabrava
Those fields are not ready yet, hide them. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2018-12-14Filter the dataGravatar Tomaz Canabrava
Wire up the needed code to filter the data in the myInvalidate call. The data comes from the Struct FilterData and if any of the test conditions on the filter function are false, the filter will assume that the specific dive shouldn't be shown Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2018-12-14Drop old filter codeGravatar Tomaz Canabrava
Drop tons of now-unused-code. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2018-12-14Struct FilterDataGravatar Tomaz Canabrava
The idea is that this struct will have all the needed data that will be passed to the filter model. Everything that happens on the filterwidget will fill out this struct, then forward it to the model, that in turn will activate the filter hiding some of the dives that matches on your divelist. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2018-11-23Cleanup: make "struct dive *" and "struct dive_trip *" Qt metatypesGravatar Berthold Stoeger
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>
2018-11-18Dive list: replace dive-list of trips by a tableGravatar Berthold Stoeger
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>
2018-11-01Dive list: implement custom lessThan functionGravatar Berthold Stoeger
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>
2018-11-01Dive list: make filter model aware of its sourceGravatar Berthold Stoeger
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>
2018-10-29Dive site: compare pointers in MultiFilterSortModel::showDive()Gravatar Berthold Stoeger
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>
2018-10-29Dive site: replace dive->dive_site_uuid by dive_siteGravatar Berthold Stoeger
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>
2018-10-29Dive site: remove [start|stop]FilterDiveSite signalsGravatar Berthold Stoeger
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>
2018-10-21Dive list: move dive-selection code from filter to listGravatar Berthold Stoeger
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>
2018-10-13Cleanup: rename MainWindow member variablesGravatar Berthold Stoeger
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>
2018-10-13Cleanup: Turn widget accessor-functions into simple pointersGravatar Berthold Stoeger
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>
2018-10-11Filter: reload only when checkstate changedGravatar Berthold Stoeger
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>
2018-10-11Filter: Make filters aware of added / removed divesGravatar Berthold Stoeger
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>
2018-08-31Filter: sort filter items in FilterModelBase::updateList()Gravatar Berthold Stoeger
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>
2018-08-31Filter: Make FilterModelBase a proper Qt model (mostly)Gravatar Berthold Stoeger
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>
2018-08-28Filter: cache number of dives fulfilling filter rulesGravatar Berthold Stoeger
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>
2018-08-28Whitespace: make range based for loops consistent in filtermodels.cppGravatar Berthold Stoeger
Consistently use "for(item: items)" instead if "for(item : items)". Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-28Filter: replace checked-state by structGravatar Berthold Stoeger
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>
2018-08-16Filter: separate backend from frontend logicGravatar Berthold Stoeger
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>
2018-08-14Filter: break out showDive() function from filterAcceptsRow()Gravatar Berthold Stoeger
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>
2018-08-14Filter: constify doFilter() argumentGravatar Berthold Stoeger
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>
2018-08-14Filter: remove unused parameters from doFilter functionsGravatar Berthold Stoeger
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>