summaryrefslogtreecommitdiffstats
path: root/qt-models/divetripmodel.cpp
AgeCommit message (Collapse)Author
2020-05-22cleanup: move timestampToDateTime() to qthelper.cppGravatar Berthold Stoeger
Move this function from maintab.cpp to qthelper.cpp. Since the functionality was used in numerous places, use the helper function there as well. This removes a number of inconsistencies. For example, sometime setTimeSpec(Qt::UTC) was called, even though the QDateTime object was already created with that time spec. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-14mobile/models: add access to tags stringGravatar Dirk Hohndel
We already allow filtering by tags, but don't even show them on mobile. That seems rather inconsistent. First step is to make the tags available to the QML layer. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
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-06media: use table instead of linked list for mediaGravatar Berthold Stoeger
For consistency with equipment, use our table macros for pictures. Generally tables (arrays) are preferred over linked lists, because they allow random access. This is mostly copy & paste of the equipment code. Sadly, our table macros are quite messy and need some revamping. Therefore, the resulting code is likewise somewhat messy. 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-04-13dive sites: properly reload dive site model on desktopGravatar Berthold Stoeger
In 9310d72943390f95d6742c2d5b40f025a40b4008, resetting of the dive sites was moved to DiveTripModelBase::reset(). This seemed like a good idea, because it means that the location list is reloaded every time the dive list is reset. Unfortunately that function is only used on mobile, thus on desktop the dive site model is not updated. Do that in MultiFilterSortModel::resetModel(), because this is always called when the dive list is reset. Desktop differs from mobile in that two different models are used depending on whether we are in list or in tree mode. Fixes #2749 Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-13mobile: remove fine-grained notificationGravatar Berthold Stoeger
When initializing the fulltext-cache and the dive-list, every 100 dives a notification was shown. I had a feeling that this made startup significantly slower, but that could have been purely psychological. Therefore I measured and indeed, removing the fine-grained notification, it becomes *significantly* faster. For a 3500 dives test log with mobile-on-desktop: Initialization of the fulltext: 1350 ms -> 730 ms (-46%) Initialization of the divelistmodel: 689 ms -> 113 ms (-83%) Let's remove the fine-grained notification. There *is* a visual indication of work-in-progress anyway. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-10media: move picture function from dive.c to picture.cGravatar Berthold Stoeger
Currently, move only those functions that do not access dive structures. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-04core/models: give progress update while populating modelsGravatar Dirk Hohndel
Especially with large dive logs this will prevent the user from thinking that the app is hung. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
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-21mobile/models: make dive invalid flag available to mobile UIGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-20Dive list: mark invalid dives with a struck out fontGravatar Berthold Stoeger
Mark invalid dives in the dive list by striking them out and rendering them with a grey color. The color-change is not sufficient, because the default model delegate ignores color hints if the item is selected. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-18models: update divesite-model when clearing/updating dive modelGravatar Berthold Stoeger
When the dive list is cleared or updated, the entries in the divesite-model become stale and therefore the divesite-model (with the actual name LocationInformationModel) also must be updated. This was done manually in some parts of the code and forgotten in others. Therefore, do it directly in the clear() and reset() function of the dive list-model. This might be a bit of a layering violation: why should one model call into another if they are not in parent/child relationship? However, this seems easier than introducing a global "reset dives" function that coordinates the models. Moreover, it does not appear 100% safe: if the clearing of the divesite model causes accesses to the divelist-model, they happen in the midst of a model reset and we had horrible bugs with that kind of things. However, I don't think that should happen. 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-12divetripmodel: change current dive if no dives are selectedGravatar Berthold Stoeger
The DiveTripModelTree::divesSelected() returned early if no dives were selected. Thus, the current dive was not updated. Remove the check for no dives. 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-10mobile models: add trip location and notesGravatar Dirk Hohndel
First step towards making those accessible and then editable. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
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-10core: add 'diveInTrip' role to underlying data modelGravatar Dirk Hohndel
This will allow us to offer differentiated options in the context menu. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-10undo: clear undo-stack when clearing dive dataGravatar Berthold Stoeger
When the dive data is cleared, all pointers in the undo-stack become stale. Desktop explicitly called Command::clear() in that case, but mobile doesn't. Thus, move the clear() call into DiveTripModelBase::clear() Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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: copy & paste the roles-code from DiveListModelGravatar Berthold Stoeger
To act as a drop-in replacement (at least as much as possible), move the roles from the old DiveListModel to the common base model of mobile and desktop. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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: send shown changed signal on resetGravatar Berthold Stoeger
Once the the mobile app uses the new models, this will be necessary to get the correct number of filtered dives after startup. 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-22Filter: move actual filtering loop to core/divefilter.cppGravatar Berthold Stoeger
The DiveFilter class defined the showDive() function to test whether a dive should be filtered or not. This was used in DiveTripModel to loop over all dives or all dives affected by an editing action. This restricts us in how we do filtering: We can't use indexes that give us directly the result. To make the filtering more flexible, move the actual loops that do the filtering to the DiveFilter class. The undo-commands likewise called directly the showDive() function to check whether newly added dives are shown. Use the new interface here as well. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-02-22Filter: update current dive if change hides current diveGravatar Berthold Stoeger
When changing the filter-criterion and the current dive is hidden, a new dive is made current. However, when a dive is hidden because it was edited, it is still shown. Make this consistent by also selecing a new current dive in the latter case. Do this by comparing the current_dive before and after calculating the filter. Since this is now done in multiple places move this code to the ShownChange class. 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-11Cleanup: remove filterSelectedDives function in divetripmodel.cppGravatar Berthold Stoeger
The last users of the returned vector were removed in commit e1abf9485cf59f1b8cb79d827fa386af48f095a4 Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-01-10code cleanup: introduce empty_cylinder constantGravatar Dirk Hohndel
This deals with the issue of initializing structs in C++. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-12-13Coding style: use std::equal_to instead of lambdaGravatar Berthold Stoeger
Use std::equal_to instead of lambdas that compare two dive pointers. One could argue over which version is more readable. For whatever it's worth, std::equal_to is more compact and expressive. This removes an old erroneous comment that stated that std::equal_to is only available since C++14. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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-10Filter: correctly send changed signals in list modeGravatar Berthold Stoeger
The DiveTripModelList forgot to collect the changed dives when resetting the filter. Fix that. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-10Filter: instruct UI of changed current diveGravatar Berthold Stoeger
Updating the filter can lead to changes of the current dive. Keep the UI in the know by re-initializing the selection. This is not optimal, because the whole selection is reset, but the pragmatic thing to do for now. 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 list model: send changed signals for top-level itemsGravatar Berthold Stoeger
In analogy to the tree-model send signals when dives change their shown status in the list-view. Do this in two passes (collect changes; send changes) to be able to reuse the already existing functions. 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-12-04Dive list model: move filtering of trip-items to own functionGravatar Berthold Stoeger
Implementing proper model semantics (only sending a changed signal for items that actually changed) will be somewhat complicated. Therefore, move the filtering of trip-items to its own function to make the nesting a little bit less deep. 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>