Results 1 to 7 of 7

Thread: qt 4.4 Issue with too many QGraphicsItems

  1. #1
    Join Date
    Jun 2009
    Posts
    33
    Thanks
    5
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default qt 4.4 Issue with too many QGraphicsItems

    Hi all,

    I am using a QGraphicsView to display anywhere from 1000 to 100,000+ items and I have figured out how to use QGraphicsItem::paint() to draw or not draw the items. This is pretty good except in the case of viewing the entire scene.
    I have seen that even the chips example slows down when zoom is full. No problem, I have designed a pixmap that draws a simple representation of the items at a certain level.

    Issue: Still slower (load, zoom, and pan wise) than I would like.

    Setup: I have 2 QGraphicsItem's and they have children that are QGraphicsItems as well. These children are the ones being drawn. I have implemented that when the level of detail gets too low (zoomed out) the child items are not drawn but instead the parent items displays the aforementioned pixmap(s).

    possible Problem: Child items must each call paint() which exits immediately. Still 100,000+ calls takes time.

    Question: Is there anyway to, I don't know, maybe set the parent such that the child items paint() function is NOT called when it is not drawn?
    -or- is it quicker to just hide them? (although I'd rather not hide them)


    I have implemented cache of scene, item, pixmap, and view by which gave best performance.

    thanx n advance,

    JW
    sw developer

  2. #2
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: qt 4.4 Issue with too many QGraphicsItems

    Quote Originally Posted by spawn9997 View Post
    Hi all,

    I am using a QGraphicsView to display anywhere from 1000 to 100,000+ items and I have figured out how to use QGraphicsItem::paint() to draw or not draw the items. This is pretty good except in the case of viewing the entire scene.
    I have seen that even the chips example slows down when zoom is full. No problem, I have designed a pixmap that draws a simple representation of the items at a certain level.

    Issue: Still slower (load, zoom, and pan wise) than I would like.

    Setup: I have 2 QGraphicsItem's and they have children that are QGraphicsItems as well. These children are the ones being drawn. I have implemented that when the level of detail gets too low (zoomed out) the child items are not drawn but instead the parent items displays the aforementioned pixmap(s).

    possible Problem: Child items must each call paint() which exits immediately. Still 100,000+ calls takes time.

    Question: Is there anyway to, I don't know, maybe set the parent such that the child items paint() function is NOT called when it is not drawn?
    -or- is it quicker to just hide them? (although I'd rather not hide them)


    I have implemented cache of scene, item, pixmap, and view by which gave best performance.

    thanx n advance,

    JW
    sw developer
    You can also try setting QGraphicsView:ontSavePainterState on your view (of course you'll have to save/restore the painter state yourself in your paint() functions. But when you do not paint anything, you will save yourself some 100k calls to save/restore which should help.

  3. #3
    Join Date
    Jun 2009
    Posts
    33
    Thanks
    5
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: qt 4.4 Issue with too many QGraphicsItems

    pherthyl: I have that flag set already in the view and I did notice a boost in speed. Thanks!

    Since Last time I have reimplemented the QGraphicsScene::drawItems() function and this sped up redraw a bit (entirely skip drawing of child items when I only need to draw parent).
    After testing, I have found that my drawing routine is moving very fast compared to the loading of the said 100,000-400,000+ items from the QAbstractTableModel. The model data is saved in a SQL database (I'm not working on that part so I'm not sure of the specifics of that database.
    I guess now the question is how to get that data out in a fast way? For now, I just go through the list one at a time and create a QGraphicsItem and set the proper data. This process is taking 3.4 sec on avg. for 136331 items (tested!) For this same project it loads 2 types of data into objects; one is much larger than the other. The smaller set takes just 1.5 secs. and total time from click to the view being populated is around 7-8 secs.

    If this were the largest project I'd be done; but, the largest project takes 3x as long to load.

    is this good or not?
    Also, should I open a new thread for this?


    JW
    sw developer

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: qt 4.4 Issue with too many QGraphicsItems

    How do you populate the scene? Could we see the exact code?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jun 2009
    Posts
    33
    Thanks
    5
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: qt 4.4 Issue with too many QGraphicsItems

    Hello all,

    Sorry for the long wait but other work calls.

    This is one of the model functions I use to create items and populate the scene from. The other (I have 2 models loading for now) they all will most likely look exactly the same.
    Main issue is shear size. We load .5 million items in the largest of projects.

    Qt Code:
    1. void ShotGraphicsLayer::setShotModel(ShotModel * shotModel){
    2.  
    3. emit this->loadProgress(0);
    4. layerRect.setSize(QSize(1,1));
    5. int nlocs = 0, xColumn,yColumn,zColumn, lineCol;
    6. int swathCol;
    7. QString swathVal, lineVal;
    8. float x_min, x_max,y_min, y_max;
    9. float y_value, x_value;
    10. //float z_value,z_min, z_max;
    11.  
    12. nlocs = shotModel->rowCount(QModelIndex());
    13.  
    14. // get column numbers
    15. xColumn = shotModel->fieldIndex("x");
    16. yColumn = shotModel->fieldIndex("y");
    17. zColumn = shotModel->fieldIndex("z");
    18.  
    19. lineCol = shotModel->fieldIndex("line");
    20. swathCol = shotModel->fieldIndex("swname");
    21. // copy data
    22.  
    23. QModelIndex sgi_ndx, temp_y_ndx,row_ndx, line_ndx, swath_ndx;
    24.  
    25. int progress;
    26. for (int ndx=0; ndx < nlocs; ++ndx) {
    27.  
    28. progress = (ndx*100)/nlocs;
    29. if(progress%5==0){
    30. emit loadProgress(progress);
    31. }
    32.  
    33. row_ndx = shotModel->index(ndx,0,QModelIndex());
    34. sgi_ndx = shotModel->index(ndx,xColumn,QModelIndex());
    35. temp_y_ndx = shotModel->index(ndx,yColumn,QModelIndex());
    36. line_ndx = shotModel->index(ndx,lineCol,QModelIndex());
    37. swath_ndx = shotModel->index(ndx,swathCol,QModelIndex());
    38.  
    39. x_value = shotModel->data(sgi_ndx,Qt::DisplayRole).toDouble();
    40. y_value = shotModel->data(temp_y_ndx,Qt::DisplayRole).toDouble();
    41. lineVal = shotModel->data(line_ndx,Qt::DisplayRole).toString();
    42. swathVal = shotModel->data(swath_ndx,Qt::DisplayRole).toString();
    43.  
    44. //z_values[ndx] = shotModel->data(sgi_ndx,Qt::DisplayRole).toDouble();
    45. ShotGraphicsItem * sgi = new ShotGraphicsItem(this);
    46.  
    47. sgi->setIndex(row_ndx);
    48. sgi->setPos(x_value,y_value);
    49.  
    50. ShotGroup temp;
    51. temp.insert(lineVal,sgi);
    52.  
    53. lineGroup.insert(lineVal,sgi);
    54.  
    55. if (swathGroup.contains(swathVal)) // if old group, add new multimap to old one.
    56. swathGroup[swathVal] += temp;
    57. else
    58. swathGroup.insert(swathVal,temp);
    59.  
    60. this->setNumber(ndx+1);
    61. sgi->setToolTip(QString("Shot %1").arg(number));
    62.  
    63. if (ndx == 0) {
    64. x_max = x_value;
    65. x_min = x_value;
    66. y_max = y_value;
    67. y_min = y_value;
    68. } else {
    69. x_min = std::min(x_min,x_value);
    70. y_min = std::min(y_min,y_value);
    71. x_max = std::max(x_max,x_value);
    72. y_max = std::max(y_max,y_value);
    73. }
    74. QRectF rect(0,0,25,25);
    75. sgi->setRect(rect);
    76. if (ndx == 0)
    77. layerRect.setRect(rect.x(),rect.y(),rect.width(),rect.height());
    78.  
    79. }
    80.  
    81.  
    82. layerRect.setRect(x_min,y_min,fabs(x_max-x_min),fabs(y_max-y_min));
    83. emit this->loadProgress(100);
    84. }
    To copy to clipboard, switch view to plain text mode 

    Basically it is....
    0) for each row in model
    1) get data from model
    2) create graphicsitem
    3) load index (currently the model is not changing)
    3.5) add item to group (QMap) for easier access.
    4) set position and adjust boundingRect.

    - This function is from a QGraphicsItem that acts as the parent for all of these items so I add the items to the scene through this item and this item to the scene through its parent.
    So I have... singular item added to scene-> this item has 2 children -> and these two have many child items, each.

    Anyway, can anyone see how to load the data from the model quicker or make better use of the model, let me (us) know.


    spawn9997
    sw developer

  6. #6
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: qt 4.4 Issue with too many QGraphicsItems

    I would profile which part of that loading function is actually taking the most time..

    Nothing obvious jumps out at me.. If you don't need the sorting in your map you can use a QHash, should have much faster insertion times.

  7. The following user says thank you to pherthyl for this useful post:

    spawn9997 (2nd September 2009)

  8. #7
    Join Date
    Jun 2009
    Posts
    33
    Thanks
    5
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: qt 4.4 Issue with too many QGraphicsItems

    Sorry for the long get back... the function is just long because of the great number of items. I found that creating QGraphicsItem's takes a good amount of time and accessing the data from the model take time.
    We decided to let the load time stand as it is under half a minute for the largest projects including the drawing of the final scene to the QGraphicsView. We did add a progress bar for the user's sake!! Thanks again.

    JW
    sw developer
    Last edited by spawn9997; 2nd September 2009 at 15:57. Reason: spelling error

Similar Threads

  1. Replies: 8
    Last Post: 27th April 2009, 19:19
  2. How to put scaled QGraphicsItems next to eachother
    By profoX in forum Qt Programming
    Replies: 6
    Last Post: 3rd June 2008, 07:44
  3. Replies: 3
    Last Post: 11th April 2008, 12:25
  4. qt3 to qt4 - uic issue
    By hvengel in forum Qt Programming
    Replies: 10
    Last Post: 4th March 2007, 02:59
  5. Replies: 5
    Last Post: 22nd September 2006, 08:04

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.