PDA

View Full Version : set auto scaling without calling setRawSamples multiple times



Momergil
14th May 2014, 13:04
Hello!

Recently I was with a problem regarding doing scaling of a QwtPlot in a real-time plotting graph using setRawSamples called just once (discussion was done here¹). One thing I learned with Uwe on that thread was that, without calling the setData() method, I couldn't use auto scaling since the Qwt system wouldn't be aware that the curve's data had changed.

Well things have changed since then and now I don't have to do real time plotting anymore, but I still want to avoid calling setRawSamples() each second when the QwtPlot needs to be reploted (the reason is code "clarification" and efficiency), which would seem to mean that I'll have to reimplement QwtPlotCurve::boundingRect() as discussed on that topic.

The point I was thinking was: since I don't have to optimize the bounding rect calculation as previously discussed, I could very well use the same system setData() uses to do the axis recalculation, calling it each time I need to replot my graph (but again without calling setData/setRawData). I went, then, to the setData() method which is



if ( d_series != series )
{
delete d_series;
d_series = series;
dataChanged();
}


and figured out that probably the dataChanged() was the method I needed to call before doing the QwtPlot::replot(). I went after it and discovered that it is a pure virtual method from the QwtAbstractSeriesStore class that is defined in QwtPlotSeriesItem (and only here) as being



void QwtPlotSeriesItem::dataChanged()
{
itemChanged();
}


while itemChanged() is



void QwtPlotItem::itemChanged()
{
if ( d_data->plot )
d_data->plot->autoRefresh();
}


In other words, everything I needed to do, seems to me, was to do my reploting this way:



//update curve's data without calling setRawData again

myPlot->autoRefresh();
myPlot->replot();


or equivalent


foreach (QwtPlotCurve* const poCurve, curveList)
{
poCurve->itemChanged();
}

myPlot->replot();


Well, I did this and it didn't work :( the auto scaling is not working. What did I miss?


Thanks,

Momergil

¹: http://www.qtcentre.org/threads/59032-AutoScaling-not-working?p=262516

Momergil
6th November 2015, 15:57
Although some time passed and I somehow pass over this problem, I'm sill curious for an answer, so... moving up! :)

Cah
11th November 2015, 05:51
//update curve's data without calling setRawData again
Do you mean somehow assigning a new/updated series?


myPlot->autoRefresh();
myPlot->replot();
It is not usual to follow a call to autoRefresh() by a call to replot()... if autoReplot() is true, autoRefresh() calls replot().