Quote Originally Posted by anda_skoa View Post
The data() method of a list model needs to do two things:

1) Find the data structure instance for the row as given with index.row()
2) Return the data field as given by role

So if you have a list or vector of UeTypeOrders, a simple index access should take care of (1).
For (2) you specify roles for each of the data fields you'd like to have access to and let a switch() on the role argument handle the access to the respective field.

Cheers,
_
Here is my data[ method now:
Qt Code:
  1. QVariant UeOrdersModel::data(const QModelIndex &index,
  2. int role) const
  3. {
  4. switch(role)
  5. {
  6. case ueRoleUserId:
  7. {
  8. return this->ueOrders()->value(QPair<QString, QString>(this->ueUserName(),this->uePlaceName())).at(index.row())->ueUserId();
  9. } break;
  10.  
  11. case ueRolePlaceId:
  12. {
  13. return this->ueOrders()->value(QPair<QString, QString>(this->ueUserName(),this->uePlaceName())).at(index.row())->uePlaceId();
  14. } break;
  15.  
  16. case ueRoleProductId:
  17. {
  18. return this->ueOrders()->value(QPair<QString, QString>(this->ueUserName(),this->uePlaceName())).at(index.row())->ueProductId();
  19. } break;
  20.  
  21. case ueRoleProductName:
  22. {
  23. return this->ueOrders()->value(QPair<QString, QString>(this->ueUserName(),this->uePlaceName())).at(index.row())->ueProductName();
  24. } break;
  25.  
  26. case ueRoleProductPriceSell:
  27. {
  28. return this->ueOrders()->value(QPair<QString, QString>(this->ueUserName(),this->uePlaceName())).at(index.row())->ueProductPriceSell();
  29. } break;
  30.  
  31. case ueRoleProductQuantity:
  32. {
  33. return this->ueOrders()->value(QPair<QString, QString>(this->ueUserName(),this->uePlaceName())).at(index.row())->ueProductQuantity();
  34. } break;
  35.  
  36. case ueRoleOrderAmount:
  37. {
  38. return this->ueOrders()->value(QPair<QString, QString>(this->ueUserName(),this->uePlaceName())).at(index.row())->ueOrderAmount();
  39. } break;
  40.  
  41. default:
  42. {
  43. return QVariant();
  44. } break; // default
  45. } // switch
  46.  
  47. return QVariant();
  48. } // data
To copy to clipboard, switch view to plain text mode 
Am I getting close and my next question is if the data structure in the model is updated at runtime (i.e, internal data structure record record is added, changed or deleted), does this mean the model should be implemented as editable or still as read only? And if so (editable), I do not know what to put in, for exameple, method insertRow(s)?