PDA

View Full Version : Centralised data - multiple QwtPlot



Maximus2
25th March 2014, 03:04
Hi,

Just a little bit of context:
I am using 3 distinct qwtPlot that use the same data, the data is stored in multiple QVector<QPointF> in each qwtPot, (used to reprensent realtime QwtPlotCurve for each qwtPlot)
To get a little bit what I mean, here is a video of the software in action :
https://www.youtube.com/watch?v=NSCTaG57ze4 (fast foward to the middle)

Now I want to change that, since using 3 times the same data uses a lot memory and is not efficient.
I am trying to change the code so that I have only one place where all the data is stored, and the graph feeds on this data to display new contents when it arrives (with signal/slots mechanism)

So my center class with the data is called "DataWorkout" and contains
- QVector<QPointF> cadenceSamples;
this Samples get filled every second with ~ 4 new QPointF
When I get a new QPoint, this class emit a signal to the qwtPlot class so that they replot the QwtPlotCurve.

Here is the current code used that works

connect(dataWorkout, SIGNAL(newCadenceDataAdded(QVector<QPointF>)), ui->widget_workoutPlot, SLOT(refreshCadenceCurve(QVector<QPointF>)) );

void WorkoutPlot::refreshCadenceCurve(QVector<QPointF> cadenceSample)
{
cadenceCurve->setSamples(cadenceSample);
cadenceCurve->attach(this);
}

My question is: is passing a QVector<QPointF> in a signal/slot going to use a lot of ressource? Will it copy the entire QVector or just pass the pointer/address? I'm not sure the way I used is good but I couldn't find a way without passing the QVector in the signal/slot, because to curve doesn't get display if I don't use .setSamples and .attach on each call.

Thanks in advance / Merci beaucoup!

Uwe
25th March 2014, 06:11
Derive from QwtSeriesData<QPointF> so that all instances return from the same storage. There is no need to copy anything.

Uwe

Maximus2
25th March 2014, 14:19
Thanks Uwe, guess if I'm thinking to do it, Qwt has already done it :)

I'm reading the example "oscilloscope" that is near to what I want. In this example there is only 1 CurveData and 1 SignalData.
Would you recommend to create 4 distinct class for my use case, one for each Data type (ie: HeartRateData, CadenceData, PowerData, SpeedData)
Or put it all together in one class like SignalData -- (method appendHeartRate(QPointF), appendCadence(QPointF)...)

From what I understand CurveData is where to access the data, and SignalData is where you write/modify the data.
I still need to figure what is the .lock about and if I really need it in my use-case, I'm not reploting manually but at fixed time interval in my case.
Wish I had your programming skills

[Edit : I used the same code from "oscilloscope" and it's working well

cadenceCurve->setData(new CurveData() );
cadenceCurve->attach(this);
Now just to see the code design but i'll probably code 4 classes to separate my signals data from each other
but with this way I need 4 classes for the curveData and 4 classes for the SignalData, lot of code to maintain will see if I can make all in 2 classes.. ]

Thank you