Trying to understand the profile.c, please be nice to me. :)

Dirk Hohndel dirk at hohndel.org
Thu Jan 9 11:34:07 UTC 2014


On Thu, 2014-01-09 at 14:10 -0200, Tomaz Canabrava wrote:
> So, On the my tryto make the world better and separate the logic of
> the profiles I'v come to this:
> 
> 
> The DiveProfilePlot method will be changed to something similar to
> this:
> 
> void DiveDepthTimeModel::setDive(dive* d,const plot_info& pInfo)
> {
>     // We need a way to find out if the dive setted is the same old
> dive, but pointers change,
>     // and there's no UUID, for now, just repopulate everything.

??? we have a diveId now. So you can know whether the dive changed.

>     clear();
>     struct divecomputer *dc = NULL;
> 
>     if (d)
>         dc = select_dc(&d->dc);
>     populate_plot_entries(dive, dc, pInfo);
>     sampleCount = pInfo.nr;
>     dcSamples = pInfo.entry;
>     beginInsertRows(QModelIndex(), 0, sampleCount-1);
>     endInsertRows();
> }
> 
> 
> The last two lines are magic-lines to tell Qt "Hey, data's ready, show
> it."
> 
> But on the create_plot_data method, there's a     return
> analyze_plot_info(pi);
> 
> call that I didn't really understood.

This does the data analysis to create smoothed values for the plot of
vertical speed. If you don't do this, the jitter in the data will hide
all the real relative velocity information.

> So, Linus, Dirk, Anyone that understand the internals of the profile.c
> code:
> 
> 
> Can I separate the calls like that? 

Like what? You lost me.

> There was a call to 
> 
>     /* Create the new plot data */
>     if (last_pi_entry)
>         free((void *)last_pi_entry);
>     last_pi_entry = populate_plot_entries(dive, dc, pInfo);

populate_plot_entries() returns a pointer to the last used data
structure that holds all the info we need to display on things.
Think of it as the model in your model-view. And if the dive changes,
you throw away the old one and create a new one.

> but that seems a bit wrong ( why should I keep a pointer to the
> last_pi_entry?

Because that's where all this data is stored that you later want to
display on the screen.

/D




More information about the subsurface mailing list