Results 1 to 3 of 3

Thread: QAbstractProxyModel::mapToSource performance issues

  1. #1
    Join Date
    Sep 2007
    Posts
    29
    Thanks
    8

    Default QAbstractProxyModel::mapToSource performance issues

    hi,
    sorry for opening a second thread in one day, i'm really stumbling from one pitfall into another here

    the situation is like this:
    i got a QStandardItemModel subclass presenting a tree of data.
    this includes a list of EVENTs, who have about 4-5 sub-elements each.

    onto this model, i want to set a proxy model, subclassed from QAbstractProxyModel, to map the EVENTs into a table-like model.
    eg. an EVENT has an NOTE attribute (sub-item in the tree) with value 10, so some of it's information should be used in row 10 in the proxy.

    as you can imagine, danymic mapping in the mapToSource function is rather expensive because every time i have to search through all the EVENTs and try to find one that fits the current row.

    but i underastimated HOW expansive it really is.
    so, the proxy displays a 4 * 128 table, there is only one EVENT in the source model.
    but nevertheless it takes several seconds to build up the proxy (on an 5200 dual core!), making scrolling etc. just impossible. adding more scenes should have linear complexity, making it event more unusable.

    i really can't see the performance drain here. initially displaying the proxy results in ~800 calls of mapToSource - how can that take so long? are the model - functions like data(), index etc. such performance hogs?

    code:
    Qt Code:
    1. QModelIndex NewScriptModelEventTableProxy::mapToSource(
    2. const QModelIndex &i_ProxyIndex) const
    3. {
    4. // is lightning fast, so rest rest of the function is the cause
    5. //return QModelIndex();
    6.  
    7. static int p_iCalls = 0;
    8.  
    9. ++p_iCalls;
    10. // about 800 calls for initial display
    11. qDebug() << "calls : " << p_iCalls;
    12.  
    13. int p_iNote = i_ProxyIndex.row();
    14. int p_iColumn = i_ProxyIndex.column();
    15.  
    16. QString p_State;
    17.  
    18. if(p_iColumn == this->ColOnAction || p_iColumn == this->ColOnCondition)
    19. p_State = "on";
    20. else
    21. p_State = "off";
    22.  
    23. QModelIndex p_EventTable = this->sourceModel()->index(0, 0);
    24.  
    25. // will only be 1 in my test case
    26. int p_iNumEvents = this->sourceModel()->rowCount(p_EventTable);
    27.  
    28. for(
    29. int i = 0;
    30. i < p_iNumEvents;
    31. ++i)
    32. {
    33. QModelIndex p_Event = this->sourceModel()->index(i, 0, p_EventTable);
    34. // about 4
    35. int p_iNumAttributes = this->sourceModel()->rowCount(p_Event);
    36.  
    37. int p_EventNote;
    38. int p_EventTrack;
    39. QString p_EventState;
    40. QModelIndex p_Action;
    41. QModelIndex p_Condition;
    42.  
    43. for(
    44. int j = 0;
    45. j < p_iNumAttributes;
    46. ++j)
    47. {
    48. QModelIndex p_AttributeIndex = p_Event.child(j, 0);
    49. QModelIndex p_ValueIndex = p_Event.child(j, 1);
    50. QString p_AttributeName = p_AttributeIndex.data().toString();
    51.  
    52. if(p_AttributeName == "note")
    53. p_EventNote = p_ValueIndex.data().toString().toInt();
    54. else if(p_AttributeName == "track")
    55. p_EventTrack = p_ValueIndex.data().toString().toInt();
    56. else if(p_AttributeName == "state")
    57. p_EventState = p_ValueIndex.data().toString();
    58. else if(p_AttributeName == "action")
    59. p_Action = p_ValueIndex;
    60. else if(p_AttributeName == "condition")
    61. p_Condition = p_ValueIndex;
    62. }
    63.  
    64. if(
    65. p_EventNote == p_iNote &&
    66. p_EventTrack == this->m_iTrack &&
    67. p_EventState == p_State)
    68. {
    69. switch(p_iColumn)
    70. {
    71. case this->ColOnAction:
    72. case this->ColOffAction:
    73. return p_Action;
    74. default:
    75. return p_Condition;
    76. }
    77. }
    78. }
    79.  
    80. return QModelIndex();
    81. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QAbstractProxyModel::mapToSource performance issues

    800 calls takes few seconds? Have you tried using a profiler to obtain more specific data?

  3. #3
    Join Date
    Sep 2007
    Posts
    29
    Thanks
    8

    Default Re: QAbstractProxyModel::mapToSource performance issues

    oh well, the source models data-function was mostly the cause, because there was some really inefficient code hidden. but even getting rid of it, the solution turned out to be too slow, when using more than a few dozend EVENT elements. i finally got a solution running, that caches the data on every dataChanged etc. event

Similar Threads

  1. Performance problems with overlapping qgraphicsitems
    By brjames in forum Qt Programming
    Replies: 13
    Last Post: 4th May 2008, 22:42
  2. Tabbed widget performance suggestions
    By MrGarbage in forum Qt Programming
    Replies: 0
    Last Post: 8th December 2007, 17:02
  3. GraphicsView performance problems
    By Gopala Krishna in forum Qt Programming
    Replies: 79
    Last Post: 8th August 2007, 18:32
  4. Replies: 1
    Last Post: 4th October 2006, 17:05
  5. [QT 4] QTextEdit performance
    By fellobo in forum Qt Programming
    Replies: 8
    Last Post: 6th March 2006, 20:27

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.