Results 1 to 7 of 7

Thread: qt 4.4 Issue with too many QGraphicsItems

Hybrid View

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

    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

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

    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.

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

    spawn9997 (2nd September 2009)

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

    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
  •  
Qt is a trademark of The Qt Company.