PDA

View Full Version : QwtPlotDirectPainter not plotting correctly



Momergil
6th May 2014, 15:25
Hello!

I'm trying to use QwtPlotDirectPainter to improve the plotting of a embedded device-based Qt interface using Qwt. I used one of the Qwt example implementations of the QwtPlotDirectPainter class and the code I wrote was:



void fastReplot(const int updatePos)
{
if (updatePos == 0)
replot();
else //if (!canvas()->testAttribute(Qt::WA_PaintOnScreen))
{
foreach(QwtPlotCurveSpecial* poCurve, curveList)
{
if (!poCurve->isVisible())
continue;

const QwtScaleMap xMap = canvasMap(poCurve->xAxis());
const QwtScaleMap yMap = canvasMap(poCurve->yAxis());

QRegion clipRegion;
QRect rect(0,0,1.0,axisScaleDiv(poCurve->yAxis()).interval().width());

const QPointF center = QwtScaleMap::transform(xMap, yMap, QPointF(updatePos,axisScaleDiv(poCurve->yAxis()).interval().width()/2.0));
rect.moveCenter(center.toPoint());

clipRegion += rect;

directPainter->setClipRegion(clipRegion);

directPainter->drawSeries(poCurve, updatePos, updatePos);
}
}
}


To explain better: a data package is received by a socket connection with the Y coordinates which are put inside a static sized QVector<double>. A int value coordinates the position in the QVector where the new data should be placed. When this new data arrives, a signal connected to fastReplot(int) is emitted with the position in the vector where the new data was stored. My desire was to repaint only a small part of the plot which corresponds with the coordinate of the last updated data in the vector. The problem, though, is that the image is coming with some error:

10336

In the image above, the curve should all be like it is on the left.

How to solve this? What is wrong in my code?

Thanks,

Momergil




Note: QwtPlotCurveSpecial is a variant of QwtPlotCurve