summaryrefslogtreecommitdiffstats
path: root/qt-models/divetripmodel.h
AgeCommit message (Collapse)Author
2020-05-07cleanup: invert control-flow when resetting the core structuresGravatar Berthold Stoeger
To reset the core data structures, the mobile and desktop UIs were calling into the dive-list models, which then reset the core data structures, themselves and the unrelated locationinformation model. The UI code then reset various other things, such as the TankInformation model or the map. . This was unsatisfying from a control-flow perspective, as the models should display the core data, not act on it. Moreover, this meant lots of intricate intermodule-dependencies. Thus, straighten up the control flow: give the C core the possibility to send a "all data reset" event. And do that in those functions that reset the core data structures. Let each module react to this event by itself. This removes inter-module dependencies. For example, the MainWindow now doesn't have to reset the TankInfoModel or the MapWidget. Then, to reset the core data structures, let the UI code simply directly call the respective core functions. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06dive list: update dive list entry if pictures changedGravatar Berthold Stoeger
We show an icon whether there are pictures and whether they are before or after the dive. Thus, the list models must emit the proper signals when the pictures of a dive change. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06models: emit dive changed signal when cylinders editedGravatar Berthold Stoeger
To display changed SAC values it is necessary that the models emit changed signals when cylinders are edited. An alternative might be that the undo commands emit dive-changed signals themselves. Fixes #2814. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-24divelist: don't initialize invalidFont at startupGravatar Berthold Stoeger
To mark invalid dives, we use a struck-out font, which was a static variable at translation unit scope, i.e. initialized at application startup. Sadly, this crashes on iOS. It is unclear when we can initialize fonts. Try to move initialization to the constructore of DiveTripModelBase and make the font a member of that class. For consistency, also make the invalidBrush a member of this class. This now means that the diveData function cannot be static anymore, since it needs access to the font and brush. But OK. Reported-by: Dirk Hohndel <dirk@hohndel.org> Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-17divetripmodel: remove setData() functionGravatar Berthold Stoeger
The setData() function was used to edit the number of a dive. However, that doesn't appear to be functional. Therefore, remove the code. There is a context-menu entry "renumber dives" for that. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-12cleanup: remove current_dive parameter from divesSelected signalGravatar Berthold Stoeger
The diveListNotifier.divesSelected() signal is used to inform the models of a selection change. It sent the current dive as a second parameter. This is redundant, because the only sender of the signal sets current_dive just before sending the signal. Remove the parameter, which appears to be an artifact. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-11Grammar: replaces 'indexes' by 'indices'Gravatar Robert C. Helling
Grammar-nazi ran git grep -l 'indexes' | xargs sed -i '' -e 's/indexes/indices/g' to prevent future wincing when reading the source code. Unfortunatly, Qt itself is infected as in QModelIndexList QItemSelection::indexes() const Signed-off-by: Robert C. Helling <helling@atdotde.de>
2020-03-10dive models: add helper role to find trip above or below diveGravatar Dirk Hohndel
This is only used in the mobile UI where the sort direction is fixed and we refer to dives based on the tree model. So the terms used and the concepts that these rely on should be guaranteed to be valid. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-09mobile/divelist: implement trip title and short date for mobileGravatar Dirk Hohndel
We pass this through to the underlying data function. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-09mobile/divelist: add first version of new MobileListModel proxy modelGravatar Berthold Stoeger
Create a model which represents all top-level items and, potentially, one expanded trip as a flat list. Pass down roles to the source model and let the source model handle that. We'll have to do some ifdef-ery, but so be it. Additionally, compile the base model on mobile as well. This contains a couple of hacks to make things compile at all. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-07divetripmodel: mark derived classes as finalGravatar Berthold Stoeger
This is an idle "optimization": The compiler may now not need to access the vtable when calling virtual functions. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-06divetripmodel: use change of CURRENT_ROLE to propagate current diveGravatar Berthold Stoeger
If compiled on mobile, on change of the current dive, don't send a signal, but send changed-event with the CURRENT_ROLE for both dives that changed status (previously selected and newly selected). Mobile does not use this yet, but will do so with the new flattened models. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-06divetripmodel: add TRIP_HAS_CURRENT_ROLEGravatar Berthold Stoeger
This role returns true if the given trip contains the current dive. This will be needed by the mobile list model to decide if a newly added trip should be expanded right away. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-06divetripmodel: introduce CURRENT_ROLEGravatar Berthold Stoeger
Use this role to test whether a dive is the currently displayed dive. This will be needed to transport changes of the current dive to the mobile list models. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-02-22Cleanup: remove shown flag of DiveTripModelTree itemsGravatar Berthold Stoeger
Since we now filter at the model level, items are by definition shown. No need for a flag. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-02-22Cleanup: remove DiveTripModelBase::SHOWN_ROLEGravatar Berthold Stoeger
This role was used by the filter-proxy model as filter criterion. Since we don't use that model to filter anymore, we can remove the role. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-02-22Cleanup: remove DiveTripModelBase::sendShownChangedSignals()Gravatar Berthold Stoeger
This was used by the old filtering code. This is not necessary anymore. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-02-22Dive list: filter dives at DiveTripModel levelGravatar Berthold Stoeger
We use a QFilterProxyModel to filter out dives that are hidden according to the current filter-criterion. Instead, filter the dives already at the DiveTripModel level. Filter out hidden dives immediately when receiving them. The only difficult case is when dives are changed, because then visibility can change. This means that we have three cases to consider: 1) Visibility unchanged -> send change signal 2) Change from hidden to unhidden -> add dives to model 3) Change from unhidden to hidden -> remove dives from model Things get complicated by the fact that the tree-version of the model might have to add/remove full trips! Suggested-by: Dirk Hohndel <dirk@hohndel.org> Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-02-04Cleanup: lower-case filenames in core/subsurface-qt/Gravatar Berthold Stoeger
We tend to use lower-case filenames. Let's do it for these files as well. Simple search & replace. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-16Stop Compiler Warning: Change struct to classGravatar Robert C. Helling
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-12-11Dive list: implement DiveTripModelBase::reset()Gravatar Berthold Stoeger
On desktop, resetting the model is realized by generating a new model object. This is due to the fact that we have two different models (tree and list) and for switching between those, we have to create a new object. On mobile, currently there are no plans to support the list-mode. Therefore, there is no reason the recreate the object. Instead, implement a reset() function that reloads the core data. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-10Dive list: remove global pointer to DiveTrip modelGravatar Berthold Stoeger
This part of the code had that horrible pattern, where reseting the model would invalidate all pointers to the DiveTrip model. Internalize these complexities in the MultiFilterSortModel. All accesses are now performed via that proxy model. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-10Filter: send filterReset via signalGravatar Berthold Stoeger
The old code called directly into the DiveListModel. Instead, send a signal and hook into the signal from the model. This will allow us to remove the DiveListModel::instance() function. This, in turn, is a step towards supporting multiple models at the same time. However, currently the model manually sets the hidden_by_filter flag in the core and therefore only one active model is supported at a time. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-04Selection: move initialization of selection from view to modelGravatar Berthold Stoeger
The goal here is to unify desktop and mobile by moving selection code from the desktop-only view. Currently, initialization of the selection still has to be called from the view after connecting the appropriate signals. This is due to the weird way in which create completely new models when resetting them. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-04Cleanup: rename newCurrentDive signal to currentDiveChangedGravatar Berthold Stoeger
This is more consistent with the rest of the signals. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-04Dive trip model: send changed signals for top-level itemsGravatar Berthold Stoeger
Send signals if the shown-status of top level items changed. Do this in two passes to be able to use the previously created function. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-04Dive trip model: send changed signals if visibility changed in tripsGravatar Berthold Stoeger
To avoid having to do full filter reloads, send dive-changed signals for dives in trips when the shown-status changed. But only for trips where not all dives are hidden. Because for those, the plan is to hide the trip as a whole. Implement the signal sending in its own function so that it can be reused for top-level items and the list-view. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-19Dive list: clear internal data when clearing modelGravatar Berthold Stoeger
The DiveListModelBase::clear() implementation was flawed: It cleared the data in the core, but left the data in the model untouched. The code was relying on the fact that the caller would reset the model manually. Not a good idea. Therefore, clear the internal data to keep the model consistent at all times. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-19Filter: move recalculation of filter from FilterModel to TripModelGravatar Berthold Stoeger
The way this was accessed via Qt's model semantics was horrible. This gives arguably more readable code, since we don't have to shoehorn things through QVariants. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-16Cleanup: use DiveTripModelBase::clear() to reset the logGravatar Berthold Stoeger
Introduce a DiveTripModelBase::clear() function that cleanly clears all dive data inside a beginResetModel()/endResetModel() pair. Thus, the UI will be cleanly reset and we can remove explicit calls to - graphics->setEmptyState() - mainTab->clearTabs() - mainTab->clearTabs() - diveList->reload() from MainWindow::closeCurrentFile(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-11Cleanup: introduce DiveTripModelBase::IS_TRIP_ROLEGravatar Berthold Stoeger
To test whether an entry is a trip, we passed a pointer to the trip through a QVariant and tested that for null-ity. Passing pointers through QVariants has given us myriads of problems in QML, therefore introduce a bool IS_TRIP_ROLE Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-11Cleanup: fix typos in commentGravatar Berthold Stoeger
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-06Dive site: don't emit divesChanged signals when editing dive siteGravatar Berthold Stoeger
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>
2019-06-23Cleanup: unify selection signalsGravatar Berthold Stoeger
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>
2019-06-23Undo: unify selection behavior in dive-list commandsGravatar Berthold Stoeger
Some commands tried to retain the current selection on undo/redo, others set the selection to the modified dives. The latter was introduced because it was easier in some cases, but it is probably more user-friendly because the user gets feedback on the change. Therefore, unify to always select the affected dives on undo()/redo(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-23Undo: don't send signals batched by tripGravatar Berthold Stoeger
Since the default view is batched by trips, signals were sent trip-wise. This seemed like a good idea at first, but when more and more parts used these signals, it became a burden. Therefore push the batching to the part of the code where it is needed: the trip view. The divesAdded and divesDeleted are not yet converted, because these are combined with trip addition/deletion. This should also be detangled, but not now. Since the dive-lists were sorted in the processByTrip function, the dive-list model now does its own sorting. This will have to be audited. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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-04-12Undo: update dive list if trip changedGravatar Berthold Stoeger
In tree-mode, the trip locations are displayed. Update the corresponding entries if the trip changed, by hooking into the tripChanged() signal. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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>
2018-11-18Dive list: update position of trip if data changedGravatar Berthold Stoeger
If the date of a dive changed, it might be necessary to reorder the trips, as the date of the trip changed. Although this seems like an odd usecase, move the trip if necessary, for consistency's sake. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-11-18Core: remove "when" field of struct dive_tripGravatar Berthold Stoeger
The when field gives the time of the first dive. Instead of keeping this field in sync, replace it by a function that determines the time of the first dive. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-11-18Dive list: move sort-functionality into coreGravatar Berthold Stoeger
To make sorting more controlled, move all sorting functions into the core. For this, introduce a "dive_or_trip" structure, which represents a top-level item. Adapt the DiveTripModel accordingly. There are now three sorting functions: 1) dive_less_than 2) trip_less_than 3) dive_or_trip_less_than These should be used by all sorting code. By moving them to a single place, the mess can hopefully be cleaned up. 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-28Cleanup: remove DiveTripModel::layout() functionGravatar Berthold Stoeger
This accessor was never used. This is a small step in splitting the DiveTripModel in two (list & tree), which means that the layout is moved up to the view. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-21Dive list: update trip headers on filter-finishGravatar Berthold Stoeger
On change of the filter, the headers of non-extended trips were not updated. Therefore, on filter-finish-event loop over all trips in DiveTripModel and signal data-changed. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-14Cleanup: remove DiveItem and TripItem classesGravatar Berthold Stoeger
The DiveItem and TripItem classes were wrappers around dive * and dive_trip * used to extract tabular data. With the rework of DiveTripModel they lost all their state besides the pointer itself. The usage was: DiveItem item(d); item.data(...); This can now be simplified to the much more idiomatic diveData(d, ...); and analoguously for TripItem. While adapting the data() function to be part of DiveTripModel, change the QVariant ret switch(...) { ... case ...: ret = ...; break; ... } return ret; style to switch(...) { ... case ...: return ...; } Not only is this shorter and easier to reason about, it generally also improves the generated code. The compiler can directly construct the return value in the buffer provided by the caller. Though modern compilers start to be very good at avoiding unnecessary copies. In total this cleanup results in a net-reduction of 190 lines of code. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11Dive list: unify sorting in core and Qt-modelGravatar Berthold Stoeger
Ultimately, we want to use a single dive-list and not replicate it in the Qt-model code. To this goal, let's start with using the same sort function. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11Dive list: propagate current-item to frontendGravatar Berthold Stoeger
The command-objects select a current item, but this selection was not propagated to the front-end. The current item is the base for keyboard-navigation through the dive-list and therefore should be set correctly. It took some experimentation to get the flags right: QItemSelectionModel::Current Hopefully, these are the correct flags across all supported Qt versions! Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11Undo: select dives after add, remove, merge, split dive commandsGravatar Berthold Stoeger
Select the proper dives after the add, remove, split and merge dives commands on undo *and* redo. Generally, select the added dives. For undo of add, remember the pre-addition selection. For redo of remove, select the closest dive to the first removed dive. The biggest part of the commit is the signal-interface between the dive commands and the dive-list model and dive-list view. This is done in two steps: 1) To the DiveTripModel in batches of trips. The dive trip model transforms the dives into indices. 2) To the DiveListView. The DiveListView has to translate the DiveTripModel indexes to actual indexes via its QSortFilterProxy- model. For code-reuse, derive all divelist-changing commands from a new base-class, which has a flag that describes whether the divelist changed. The helper functions which add and remove dives are made members of the base class and set the flag is a selected dive is added or removed. To properly detect when the current dive was deleted it became necessary to turn the current dive from an index to a pointer, because indices are not stable. Unfortunately, in some cases an index was expected and these places now have to transform the dive into an index. These should be converted in due course. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>