Re: Trying to understand how "explicit sharing" works with QwtPlotCurve::setSamples()
Brought to you by:
rathmann
From: K. F. <kfr...@gm...> - 2011-10-28 14:20:25
|
Hi Uwe! Thanks for your clarifications. On Tue, Oct 25, 2011 at 2:49 AM, Uwe Rathmann <Uwe...@ti...> wrote: > On 10/25/2011 01:48 AM, K. Frank wrote: >> I update the "explicitly shared" QVectors that contain the data for a >> QwtPlotCurve. Calling QwtPlot::replot() does not reliably update the >> plot. Calling QwtPlotCurve::setSamples() does. > When QwtPlot::autoReplot() is enabled QwtPlotCurve::setSamples() implicitely starts a replot - otherwise nothing is repainted. Thus your statement above doesn't make much sense. Yes. The behavior I saw didn't make sense to me either. Also, the behavior changed when I moved from 6.0.0 to 6.0.1. >> The way I understand this -- perhaps incorrectly -- is that the QwtPlotCurve >> is given references to xData and yData, and does not make a private copy >> of that data. So I expect that when I update xData and yData and call >> QwtPlot::replot() I should see the changed data in the plot. > No, Qwt doesn't have a reference - it has copies of the vectors, that are implicitely shared with the vectors in your application. But as soon as you append a point to your vectors you create deep copies. Okay, thanks. That clears things up. (Also, the behavior I see in 6.0.1 is consistent with this explanation.) I do have one follow-up question: The documentation for the QVector overload of QwtPlotCurve::setSamples(): void setSamples (const QVector< double > &xData, const QVector<double > &yData) uses the phrase "explicitly shared": Initialize data with x- and y-arrays (explicitly shared) This kind of confused me. Given that QVector makes copies of the QVectors, I might have said "copies and doesn't share." How should I understand the phrase "explicitly shared" in this context? >> ... >> I don't want QwtPlotCurve to have >> to re-copy all the data into its own private buffers every time I add a single >> point. So giving QwtPlotCurve a reference to a data structure that I can >> then add points to externally of QwtPlotCurve seems to be the way to go.) >> > See: http://qwt.sourceforge.net/class_qwt_series_data.html#_details. > > QwtPlotCurve is completely independent from how the application organizes its samples. All you have to do is to write a couple of lines, so that QwtPlotCurve is able to iterate. Well, what I did is I used the QwtPlotCurve::setRawSamples() member function. In this case, even thought the data vectors are growing, I know in advance an upper bound to their length. So I allocate some c-style arrays of doubles of that maximum length on the heap, and keep my own currentLength variable. As I add data to the arrays, I increment currentLength, and re-call setRawSamples with the same arrays (pointers to doubles) and the updated value of curentLength. This seems to work properly, and if I understand correctly, qwt is not copying the contents of the arrays under the hood. > Uwe Thanks for your help. K. Frank |