Hi and thank you for your answer,

In fact reset is called only 3 times for this table:
1-when the table is initialized and empty
2-when the table is refreshed to display only 20 lines
3-when the table is refreshed to display all lines (this is the case with bad performances.

All other calls are for other tables containing around 10 lines.

So, I can't reduce the number of call to reset.

Here is the code:
Qt Code:
  1. QVariant SKGObjectModelBase::data(const QModelIndex &index, int role) const
  2. {
  3. if (!index.isValid()) return QVariant();
  4. _SKGTRACEIN(10, "SKGObjectModelBase::data");
  5.  
  6. SKGObjectBase* obj = (SKGObjectBase*) index.internalPointer();
  7.  
  8. switch ( role ) {
  9. case Qt::DisplayRole:
  10. case Qt::EditRole:
  11. case Qt::UserRole: {
  12. QString att=listAttibutes[index.column()];
  13. QString val=obj->getAttribute(att);
  14.  
  15. if (att.startsWith("f_")) {
  16. double dval=SKGServices::stringToDouble(val);
  17. return dval;
  18. } else if (att.startsWith("i_")) {
  19. return SKGServices::stringToInt(val);
  20. } else if (att.startsWith("d_")) {
  21. QDate dval=SKGServices::stringToTime(val).date();
  22. if (role == Qt::DisplayRole) {
  23. return KGlobal::locale()->formatDate (dval, KLocale::FancyShortDate);
  24. } else {
  25. return dval;
  26. }
  27. } else if (getRealTable()=="doctransaction" && att=="t_savestep") return "";
  28. return val;
  29. }
  30.  
  31. case Qt::TextColorRole: {
  32. //Text color
  33. QString att=listAttibutes[index.column()];
  34. if (att.startsWith("f_")) {
  35. QVariant value_displayed = SKGObjectModelBase::data(index, Qt::UserRole);
  36. bool ok=false;
  37. double value_double=value_displayed.toDouble(&ok);
  38. if (ok && value_double<0) return qVariantFromValue(QColor(Qt::red));
  39. }
  40. break;
  41. }
  42. case Qt::TextAlignmentRole: {
  43. //Text alignment
  44. QString att=listAttibutes[index.column()];
  45. return (int)(Qt::AlignVCenter|(att.startsWith("f_") || att.startsWith("i_") ? Qt::AlignRight : Qt::AlignLeft));
  46. }
  47. case Qt::DecorationRole: {
  48. //Decoration
  49. if (index.column() == 0 && getRealTable()=="node") {
  50. SKGNodeObject node =*obj;
  51. QStringList data=SKGServices::splitCSVLine(node.getData());
  52. if (data.count()>2) return qVariantFromValue((QIcon) KIcon(data.at(2)));
  53. else {
  54. return qVariantFromValue((QIcon) KIcon(node.getName()==i18n("autostart") ? "folder-bookmarks" : "folder"));
  55. }
  56. } else if (index.column() == 0 && getRealTable()=="doctransaction") {
  57. return qVariantFromValue((QIcon) KIcon(obj->getAttribute("t_mode")=="U" ? "edit-undo" :"edit-redo"));
  58. } else if (getRealTable()=="doctransaction" && listAttibutes[index.column()]=="t_savestep") {
  59. if (obj->getAttribute("t_savestep")=="Y") return qVariantFromValue((QIcon) KIcon("document-save"));
  60. }
  61. break;
  62. }
  63. case Qt::ToolTipRole: {
  64. //Tooltip
  65. if (getRealTable()=="doctransaction") {
  66. document->getMessages(obj->getID(), msg);
  67. int nbMessages=msg.count();
  68. if (nbMessages) {
  69. QString message;
  70. for (int i=0; i<nbMessages; ++i) {
  71. if (i!=0) message+='\n';
  72. message+=msg.at(i);
  73. }
  74.  
  75. return message;
  76. }
  77. }
  78. break;
  79. }
  80. default : {
  81. }
  82. }
  83.  
  84. return QVariant();
  85. }
To copy to clipboard, switch view to plain text mode