mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: use std::vector<> to store divecomputer samples
This is a hairy one, because the sample code is rather tricky. There was a pattern of looping through pairs of adjacent samples, for interpolation purposes. Add an range adapter to generalize such loops. Removes the finish_sample() function: The code would call prepare_sample() to start parsing of samples and then finish_sample() to actuall add it. I.e. a kind of commit(). Since, with one exception, all users of prepare_sample() called finish_sample() in all code paths, we might just add the sample in the first place. The exception was sample_end() in parse.cpp. This brings a small change: samples are now added, even if they could only be parsed partially. I doubt that this makes any difference, since it will only happen for broken divelogs anyway. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
bc761344d4
commit
f120fecccb
28 changed files with 588 additions and 715 deletions
|
@ -38,6 +38,7 @@
|
|||
#include "core/subsurface-string.h"
|
||||
#include "core/string-format.h"
|
||||
#include "core/pref.h"
|
||||
#include "core/sample.h"
|
||||
#include "core/selection.h"
|
||||
#include "core/save-profiledata.h"
|
||||
#include "core/settings/qPrefLog.h"
|
||||
|
@ -1135,7 +1136,7 @@ bool QMLManager::checkDuration(struct dive *d, QString duration)
|
|||
}
|
||||
d->dc.duration.seconds = d->duration.seconds = h * 3600 + m * 60 + s;
|
||||
if (is_dc_manually_added_dive(&d->dc))
|
||||
free_samples(&d->dc);
|
||||
d->dc.samples.clear();
|
||||
else
|
||||
appendTextToLog("Cannot change the duration on a dive that wasn't manually added");
|
||||
return true;
|
||||
|
@ -1154,7 +1155,7 @@ bool QMLManager::checkDepth(dive *d, QString depth)
|
|||
d->maxdepth.mm = depthValue;
|
||||
if (is_dc_manually_added_dive(&d->dc)) {
|
||||
d->dc.maxdepth.mm = d->maxdepth.mm;
|
||||
free_samples(&d->dc);
|
||||
d->dc.samples.clear();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -1358,7 +1359,7 @@ void QMLManager::commitChanges(QString diveId, QString number, QString date, QSt
|
|||
if (d->maxdepth.mm == d->dc.maxdepth.mm &&
|
||||
d->maxdepth.mm > 0 &&
|
||||
is_dc_manually_added_dive(&d->dc) &&
|
||||
d->dc.samples == 0) {
|
||||
d->dc.samples.empty()) {
|
||||
// so we have depth > 0, a manually added dive and no samples
|
||||
// let's create an actual profile so the desktop version can work it
|
||||
// first clear out the mean depth (or the fake_dc() function tries
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue