Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QBarSeries performance when using QVBarModelMapper

QBarSeries performance when using QVBarModelMapper

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 1.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    wanghl
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      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();
      }
      

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      W 1 Reply Last reply
      0
      • VRoninV VRonin

        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();
        }
        
        W Offline
        W Offline
        wanghl
        wrote on last edited by
        #3

        @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!

        VRoninV 1 Reply Last reply
        0
        • W wanghl

          @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!

          VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by VRonin
          #4

          @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();
          }
          

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          W 2 Replies Last reply
          0
          • VRoninV VRonin

            @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();
            }
            
            W Offline
            W Offline
            wanghl
            wrote on last edited by
            #5

            @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!!

            1 Reply Last reply
            0
            • VRoninV VRonin

              @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();
              }
              
              W Offline
              W Offline
              wanghl
              wrote on last edited by
              #6

              @VRonin

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

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved