aboutsummaryrefslogtreecommitdiffstats
path: root/qt-models/diveimportedmodel.cpp
AgeCommit message (Collapse)Author
2018-12-17Import: unglobalize downloadTableGravatar Berthold Stoeger
To make data flow more clear, unglobalize the downloadTable object. Make it a subobject of DownloadThread. The difficult part was making this compatible with QML, because somehow the pointer to the download-table has to be passed to the DiveImportedModel. Desktop would simply pass it to the constructor. But with objects generated in QML this is not possible. Instead, pass the table in the repopulate() function. This seems to make sense, but for this to work, we have to declare pointer-to-dive-table as a Q_METATYPE. And this only works if we use a typedef, because MOC removes the "struct" from "struct dive_table". This leads to compilation errors, because dive_table is the symbol-name of the global dive table! Sigh. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-12-17Cleanup: make DiveImportedModel::checkStates a std::vectorGravatar Berthold Stoeger
To not have to bother with memory-management. Moreover, the old code was in principle wrong, since it assumed that sizeof(bool) == 1. Of course, this is true for all supported platforms, but let's not depend on such implementation-defined behavior anyway. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-12-17Cleanup: remove DiveImportedModel::setImportedDivesIndexes()Gravatar Berthold Stoeger
This function resets the DiveImportedModel. It takes two arguments: first and last index. All callers passed in 0 and number-of dives anyway, so remove the arguments. Since this now does the same as repopulate(), merge the two functions. Moreover, implement Qt-model semantics by using a beginResetModel()/endResetModel() pair. This simplifies the code. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-14Autogroup only when selectedGravatar Jan Mulder
Comits f427226b3b and 43c3885249f of the undo series introduced 2 calls of autogroup_dives() without checking the autogroup global boolean. This is a bug. An import from DC (for example) then triggers an autogrouping, the divelist is autogrouped, and the UI button is off. This commit solves this. I've chosen for a guard in the autogroup_dives() that now is a no-op when called when the user did not select autogrouping. In additon, simplified the other calls to this function, as we do not need to check before calling any more. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-10-06Import: pass "downloaded" parameter to process_imported_dives()Gravatar Berthold Stoeger
process_imported_dives() is more efficient for downloaded than for imported (from a file) dives, because it checks only the divecomputer of the first dive. This condition is checked via the "downloaded" flag of the first dive. Instead, pass an argument to process_imported_dives(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-06Import: pass a dive table to process_imported_dives()Gravatar Berthold Stoeger
Dives were directly imported into the global dive table and then merged in process_imported_dives(). Make this interface more flexible, by passing an independent dive table. The dive table of the to-be-imported dives will be sorted and merged. Then each dive is inserted in a one-by-one manner to into the global dive table. This actually introduces (at least) two functional changes: 1) If a new dive spans two old dives, it will only be merged to the first dive. But this seems like a pathological case, which is of dubious value anyway. 2) Dives unrelated to the import will not be merged. The old code would happily merge dives that were not even close to the newly imported dives. A surprising behavior. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-09-23Core: split process_dives() in post-import and post-load versionsGravatar Berthold Stoeger
process_dives() is used to post-process the dive table after loading or importing. The first parameter states whether this was after load or import. Especially in the light of undo, load and import are fundamentally different things. Notably, that latter should be undo-able, whereas the former is not. Therefore, as a first step to make import undo-able, split the function in two versions and remove the first parameter. It turns out the the load-version is very light. It only sets the DC nicknames and sorts the dive-table. There seems to be no reason to merge dives. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-06-04Cleanup: fold core/helpers.h into core/qthelper.hGravatar Berthold Stoeger
helpers.h included qthelper.h and all functions declared in helpers.h were defined in qthelper.h. Therefore fold the former into the latter, since the split seems completely arbitrary. While doing so, change the return-type of get_dc_nichname from "const QString" to "QString". Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-05-21qt-models: Change Q_UNUSED to no parameter nameGravatar jan Iversen
C++ permits use of parameters without name, which signals unused Signed-off-by: Jan Iversen <jani@apache.org>
2017-11-25Only call autogroup when it's enabledGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-10-23Respect autogroup in Subsurface-mobileGravatar Dirk Hohndel
After we download new dives we need to try to autogroup them. In Subsurface this is done when we refresh the dive list. Here we might be better off doing it right after processing the new dives. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-09DiveImportedModel: be consistent with last = -1Gravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-29Don't crash trying to record zero divesGravatar Dirk Hohndel
If the user clicks "Accept" when no dives were downloaded we would otherwise dereference unitialized memory. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-24Avoid Q_ASSERT with debug build of QtGravatar Dirk Hohndel
I don't know why we are setting lastIndex to -1. That seems odd. But for now this workaround will have to do. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-12Download dialog showed time incorrectlyGravatar Miika Turkia
The used time format was h:mh: i.e. 1:16h: This patch gets rid of the colon after the hour indicator. Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-06-04QML UI: show selection box on the Download from DC listGravatar Tomaz Canabrava
QML and C++ model don't interact too much, a new Rule should be created and used on the QML Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-05-29QML UI: select / unselect dive by clicking on itGravatar Tomaz Canabrava
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-05-29Fix typoGravatar Dirk Hohndel
Don't manually edit diffs and then commit without compile test... Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-05-29QML UI: process freshly downloaded divesGravatar Dirk Hohndel
This way they get correctly prepared and derived data fields get populated. For example, the dive number gets updated if these are indeed the newest dives. Fixes #408 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-05-29Don't leak memory on downloaded dives not pickedGravatar Dirk Hohndel
I noticed this in the mobile download code when fixing an unrelated issue - and then realized that the same was true in the desktop app as well. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-05-29mobile: Prevent tripping assert on empty BT downloadGravatar Jan Mulder
When (with mobile on desktop) loading from DC is called and the dive computer to connect to is not in download mode, the repopulate() function is called with an empty dive table. This trips the assert (obviously, debug compile only) in DiveImportedModel::setImportedDivesIndexes(). This simple fix makes things just more robust. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-05-28QML UI: add downloaded dives to dive listGravatar Dirk Hohndel
This already takes into account which of those dives were selected. Right now all we have is select all or none - this needs actual support in the UI, but once that's there, it will just work (famous last words). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-05-27QML UI: add the Downloaded Dive ModelGravatar Tomaz Canabrava
Still to do: - select the dives to save - record the downloaded dives but download is already working. :) Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-05-27Separate the download thread from the widget logicGravatar Tomaz Canabrava
This is important to not duplicate code for the Qml view. Now the DownloadFromDiveComputer widget is mostly free from important code (that has been upgraded to the core folder), and I can start coding the QML interface. There are still a few functions on the desktop widget that will die so I can call them via the QML code later. I also touched the location of a few globals (please, let's stop using those) - because it was declared on the desktop code and being used in the core. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-05-27Move model code to modelsGravatar Tomaz Canabrava
This makes it easery to use it on Qml. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>