解决方案是使用directPainter。按照 QWT 的实时示例,我执行了以下操作:
首先,我创建了辅助类 CurveData。
class CurveData: public QwtArraySeriesData<QPointF>
{
public:
CurveData()
{
}
virtual QRectF boundingRect() const
{
if ( d_boundingRect.width() < 0.0 )
d_boundingRect = qwtBoundingRect( *this );
return d_boundingRect;
}
inline void replace(double *x, double *y, int size)
{
if(d_samples.size() != size){
d_samples.resize(size);
}
for(int i = 0; i < size; i++){
d_samples.replace(i, QPointF(x[i], y[i]));
}
}
void clear()
{
d_samples.clear();
d_samples.squeeze();
d_boundingRect = QRectF( 0.0, 0.0, -1.0, -1.0 );
}
};
然后在我的绘图代码中:
void
PlottingClass::plotHoldOnPoints(int size)
{
CurveData *data = static_cast<CurveData *>( d_curve->data() );
data->replace(_realDataPoints, _imagDataPoints, size);
d_direct_painter->drawSeries(d_curve, 0, data->size() -1);
}
并且具有最小内存消耗的保持效果已准备就绪!