I am using the QAbstractItemModel and below is the implementation of the data function. I would like to keep my current data structure separate and intact so that is why I chose the abstract rather than the standard. The problem I am having is that I am not sure if I am re-inventing the wheel. Does this code seem unusual and unnecessary? Would I have an easier time using the QStandardItemModel along with a subclassed QStandardItem?

(BUS is a namespace where I defined the icon type ids. I also created a member in my BUSDataMover object that stores the icon type which can be obtained with getIconType())

Qt Code:
  1. QVariant TreeModel::data(const QModelIndex &index, int role) const {
  2. if(!index.isValid())
  3. return QVariant();
  4. BUSDataMover* item;
  5. switch(role) {
  6. case Qt::DisplayRole:
  7. item = static_cast<BUSDataMover*>(index.internalPointer());
  8. return item->data(index.column());
  9. break;
  10. case Qt::DecorationRole:
  11. item = static_cast<BUSDataMover*>(index.internalPointer());
  12. if(index.column() != 0)
  13. return QVariant();
  14. switch(item->getIconType()) {
  15. case BUS::NetworkIcon:
  16. return QIcon(":/images/network.png");
  17. break;
  18. case BUS::ClientIcon:
  19. return QIcon(":images/client.png");
  20. break;
  21. case BUS::ServerIcon:
  22. return QIcon(":images/server.png");
  23. break;
  24. case BUS::NICIcon:
  25. return QIcon(":images/nic.png");
  26. default:
  27. return QIcon(":/images/unknown.png");
  28. }
  29. break;
  30. default:
  31. return QVariant();
  32. }
  33. }
To copy to clipboard, switch view to plain text mode