Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QBarSeries performance when using QVBarModelMapper



  • I paint a barseries on my chart,then using QVBarModelMapper and QStandardItemModel to update data,see below

    QAbstractItemModel *m_model = new QStandardItemModel(this);
    m_TotalSeriesModel->insertColumns(0, 1);
    QVBarModelMapper *mapper = new QVBarModelMapper(this);
    mapper->setFirstBarSetColumn(0);
    mapper->setLastBarSetColumn(0);
    mapper->setFirstRow(0);
    mapper->setSeries(m_pBarseries);
    mapper->setModel(m_model);
    

    when data is arriving using setdata to update it,liking :
    m_model->insertRows(m_model->rowCount(), 1);
    m_model->setData(m_model->index(row, 0), value);
    if the data is frequently,the series paint is so slow.

    is I misstake anyting?



  • Unfortunately it's not a problem of your code but on QChart repainting everything every time you add a data point. What you could try is refreshing only every n number of data points. Let's say value in your code is a double, declare QVector<double> m_dataBuffer; and define the how many points should be painted at once, like enum{BufferSize=100} as a private member then change the receiver to:

    m_dataBuffer << value;
    if(m_dataBuffer.size()>=BufferSize){
    const int startRow= m_model->rowCount();
    m_model->insertRows(startRow, m_dataBuffer.size());
    for(int i=0;i<m_dataBuffer.size();++i)
    m_model->setData(m_model->index(startRow+i, 0), m_dataBuffer.at(i));
    m_dataBuffer.clear();
    }
    


  • @VRonin said in QBarSeries performance when using QVBarModelMapper:

    m_dataBuffer

    Thank you for your reply.

    I have done this,but still slow,It seems that setData is slow!



  • @wanghl said in QBarSeries performance when using QVBarModelMapper:

    It seems that setData is slow

    No, it's the slots QVBarModelMapper connects to dataChanged() that are slow.

    try this:

    m_dataBuffer << value;
    if(m_dataBuffer.size()>=BufferSize){
    const int startRow= m_model->rowCount();
    m_model->insertRows(startRow, m_dataBuffer.size());
    m_model->blockSignals(true);
    for(int i=0;i<m_dataBuffer.size();++i){
    if(i==m_dataBuffer.size()-1) m_model->blockSignals(false);
    m_model->setData(m_model->index(startRow+i, 0), m_dataBuffer.at(i));
    }
    m_dataBuffer.clear();
    }
    


  • @VRonin said in QBarSeries performance when using QVBarModelMapper:

    m_model->blockSignals(true);

    I will try it later!

    I test if append QList<qreal> valueList to a BarSeries,call pBarSeries->append(valueList),the speed is faster than use setData.

    so i read the source code,maybe the reason is append a data into barseries will emit restructuredBars signal
    the restructuredBars signal connect slot handleDataStructureChanged,this function will recreate everyting ,so is slow.

    so if setData supports add a QList data and emit DataChange once,the speed will faster!!



  • @VRonin

    I have test use blockSignal,if add this code,there is nothing to paint ....


Log in to reply