PDA

View Full Version : Replot dinamic curve.



Zikoel
22nd October 2011, 11:49
Hi,

I have extended the class QwtPlot like the example "Oscilloscope". I must write a similar code but more simple. I have a thread "out of my control" that emit a signal each 100 msec. I have write in my custom class this slot:



void Plot::addSampledPoint(double time, double sample)
{
samples.append(QPointF(time, sample));
d_curve->setSamples(samples);

const QwtScaleMap xMap = canvasMap( d_curve->xAxis() );
const QwtScaleMap yMap = canvasMap( d_curve->yAxis() );
QwtSeriesData<QPointF> *data=d_curve->data();

QRectF br = qwtBoundingRect( *data, 0, data->size()-1 );
const QRect clipRect = QwtScaleMap::transform( xMap, yMap, br ).toRect();
d_directPainter->setClipRegion( clipRect );
d_directPainter->drawSeries(d_curve, 0, data->size()-1);
}


When the samples are a QVector compatible with setSamples. I have no error but when I start the sampling I don't see anything.

P.s. If I initialize the samples when I write d_curve->attach(this) I van see the point.

Any suggest? Sorry for my simple English. (Obviously thank you at all).

Zikoel
24th October 2011, 09:39
Hi, I have try with a code more simple code:



CurveData *data = static_cast<CurveData *>( d_curve->data() );
QPointF *point=new QPointF(1000, 100);
data->append(*point);

QPointF *point2=new QPointF(2000, 10);
data->append(*point2);

d_directPainter->drawSeries(d_curve, data->size() - 1, data->size()-1);
replot();


The graph is ever empty. There are some parameters of canvas() or QwtPlot that I have omitted?

P.s. What happens when we run "drawSeries" and "replot()" ??

Thank you all!

Uwe
24th October 2011, 09:50
2 problems in your code:


Memory leaks: no need for using new here
You need to draw the last 2 points, when you want to add a line

Uwe