mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 21:20:19 +00:00
29b242c703
This data structure was quite fragile and made 'undo' when editing rather hard to implement. So instead I decided to turn this into a QMultiMap which seemed like the ideal data structure for it. This map holds all the dive computer related data indexed by the model. As QMultiMap it allows multiple entries per key (model string) and disambiguates between them with the deviceId. This commit turned out much larger than I wanted. But I didn't manage to find a clean way to break it up and make the pieces make sense. So this brings back the Ok / Cancel button for the dive computer edit dialog. And it makes those two buttons actually do the right thing (which is what started this whole process). For this to work we simply copy the map to a working copy and do all edits on that one - and then copy that over the 'real' map when we accept the changes. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
31 lines
886 B
C
31 lines
886 B
C
#include <string.h>
|
|
#include "dive.h"
|
|
#include "device.h"
|
|
|
|
struct divecomputer* fake_dc(struct divecomputer* dc)
|
|
{
|
|
static struct sample fake[4];
|
|
static struct divecomputer fakedc;
|
|
static bool initialized = 0;
|
|
if (!initialized){
|
|
fakedc = (*dc);
|
|
fakedc.sample = fake;
|
|
fakedc.samples = 4;
|
|
|
|
/* The dive has no samples, so create a few fake ones. This assumes an
|
|
ascent/descent rate of 9 m/min, which is just below the limit for FAST. */
|
|
int duration = dc->duration.seconds;
|
|
int maxdepth = dc->maxdepth.mm;
|
|
int asc_desc_time = dc->maxdepth.mm*60/9000;
|
|
if (asc_desc_time * 2 >= duration)
|
|
asc_desc_time = duration / 2;
|
|
fake[1].time.seconds = asc_desc_time;
|
|
fake[1].depth.mm = maxdepth;
|
|
fake[2].time.seconds = duration - asc_desc_time;
|
|
fake[2].depth.mm = maxdepth;
|
|
fake[3].time.seconds = duration * 1.00;
|
|
fakedc.events = dc->events;
|
|
}
|
|
return &fakedc;
|
|
}
|
|
|