天天看点

QCustomPlot 连续快速地调用replot()改善速度

qcustomplot库对replot()的解释:

void QCustomPlot::replot 
(
QCustomPlot::RefreshPriority 
refreshPriority = QCustomPlot::rpRefreshHint
)

Causes a complete replot into the internal paint buffer(s). 
Finally, the widget surface is refreshed with the new buffer contents. This is the method that must be called to make changes to the plot, e.g. on the axis ranges or data points of graphs, visible.
The parameter refreshPriority can be used to fine-tune the timing of the replot.
 For example if your application calls replot very quickly in succession 
(e.g. multiple independent functions change some aspects of the plot and each wants to make sure the change gets replotted),
 it is advisable to set refreshPriority to QCustomPlot::rpQueuedReplot. This way, the actual replotting is deferred to the next event loop iteration. 
Multiple successive calls of replot with this priority will only cause a single replot, avoiding redundant replots and improving performance.
Under a few circumstances, QCustomPlot causes a replot by itself. 
Those are resize events of the QCustomPlot widget and user interactions (object selection and range dragging/zooming).
Before the replot happens, the signal beforeReplot is emitted. After the replot, afterReplot is emitted. 
It is safe to mutually connect the replot slot with any of those two signals on two QCustomPlots to make them replot synchronously, it won't cause an infinite recursion.
If a layer is in mode QCPLayer::lmBuffered (QCPLayer::setMode), it is also possible to replot only that specific layer via QCPLayer::replot. See the documentation there for details. 
           

其中:

The parameter refreshPriority can be used to fine-tune the timing of the replot. For example if your application calls replot very quickly in succession (e.g. multiple independent functions change some aspects of the plot and each wants to make sure the change gets replotted), it is advisable to set refreshPriority to QCustomPlot::rpQueuedReplot. This way, the actual replotting is deferred to the next event loop iteration. Multiple successive calls of replot with this priority will only cause a single replot, avoiding redundant replots and improving performance.

意思是

通过调用QCustomPlot::rpQueuedReplot.可以避免重复的replot和提高性能!

所以当我使用线程进行刷新图表的时候我使用

ui->customplot->replot(QCustomPlot::rpQueuedReplot);

而不是使用ui->customplot->replot();