mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
core: add free_samples helper
And use it in the UI and planner code. See #1411 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
49f3da3bfd
commit
a5380bb741
4 changed files with 16 additions and 15 deletions
10
core/dive.c
10
core/dive.c
|
@ -754,6 +754,16 @@ void alloc_samples(struct divecomputer *dc, int num)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void free_samples(struct divecomputer *dc)
|
||||||
|
{
|
||||||
|
if (dc) {
|
||||||
|
free(dc->sample);
|
||||||
|
dc->sample = 0;
|
||||||
|
dc->samples = 0;
|
||||||
|
dc->alloc_samples = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct sample *prepare_sample(struct divecomputer *dc)
|
struct sample *prepare_sample(struct divecomputer *dc)
|
||||||
{
|
{
|
||||||
if (dc) {
|
if (dc) {
|
||||||
|
|
|
@ -747,6 +747,7 @@ extern struct dive *clone_dive(struct dive *s);
|
||||||
extern void clear_table(struct dive_table *table);
|
extern void clear_table(struct dive_table *table);
|
||||||
|
|
||||||
extern void alloc_samples(struct divecomputer *dc, int num);
|
extern void alloc_samples(struct divecomputer *dc, int num);
|
||||||
|
extern void free_samples(struct divecomputer *dc);
|
||||||
extern struct sample *prepare_sample(struct divecomputer *dc);
|
extern struct sample *prepare_sample(struct divecomputer *dc);
|
||||||
extern void finish_sample(struct divecomputer *dc);
|
extern void finish_sample(struct divecomputer *dc);
|
||||||
extern void add_sample_pressure(struct sample *sample, int sensor, int mbar);
|
extern void add_sample_pressure(struct sample *sample, int sensor, int mbar);
|
||||||
|
|
|
@ -284,10 +284,7 @@ static void create_dive_from_plan(struct diveplan *diveplan, struct dive *dive,
|
||||||
dc->when = dive->when = diveplan->when;
|
dc->when = dive->when = diveplan->when;
|
||||||
dc->surface_pressure.mbar = diveplan->surface_pressure;
|
dc->surface_pressure.mbar = diveplan->surface_pressure;
|
||||||
dc->salinity = diveplan->salinity;
|
dc->salinity = diveplan->salinity;
|
||||||
free(dc->sample);
|
free_samples(dc);
|
||||||
dc->sample = NULL;
|
|
||||||
dc->samples = 0;
|
|
||||||
dc->alloc_samples = 0;
|
|
||||||
while ((ev = dc->events)) {
|
while ((ev = dc->events)) {
|
||||||
dc->events = dc->events->next;
|
dc->events = dc->events->next;
|
||||||
free(ev);
|
free(ev);
|
||||||
|
|
|
@ -923,14 +923,10 @@ bool QMLManager::checkDuration(DiveObjectHelper *myDive, struct dive *d, QString
|
||||||
m = r6.cap(1).toInt();
|
m = r6.cap(1).toInt();
|
||||||
}
|
}
|
||||||
d->dc.duration.seconds = d->duration.seconds = h * 3600 + m * 60 + s;
|
d->dc.duration.seconds = d->duration.seconds = h * 3600 + m * 60 + s;
|
||||||
if (same_string(d->dc.model, "manually added dive")) {
|
if (same_string(d->dc.model, "manually added dive"))
|
||||||
free(d->dc.sample);
|
free_samples(&d->dc);
|
||||||
d->dc.sample = 0;
|
else
|
||||||
d->dc.samples = 0;
|
|
||||||
d->dc.alloc_samples = 0;
|
|
||||||
} else {
|
|
||||||
appendTextToLog("Cannot change the duration on a dive that wasn't manually added");
|
appendTextToLog("Cannot change the duration on a dive that wasn't manually added");
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -947,10 +943,7 @@ bool QMLManager::checkDepth(DiveObjectHelper *myDive, dive *d, QString depth)
|
||||||
d->maxdepth.mm = depthValue;
|
d->maxdepth.mm = depthValue;
|
||||||
if (same_string(d->dc.model, "manually added dive")) {
|
if (same_string(d->dc.model, "manually added dive")) {
|
||||||
d->dc.maxdepth.mm = d->maxdepth.mm;
|
d->dc.maxdepth.mm = d->maxdepth.mm;
|
||||||
free(d->dc.sample);
|
free_samples(&d->dc);
|
||||||
d->dc.sample = 0;
|
|
||||||
d->dc.samples = 0;
|
|
||||||
d->dc.alloc_samples = 0;
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue