Hi
I am implementing a Item Delegate for my tree based model.
I need to create a different editor depending upon the item being edited.
At the moment I am using switch statements to decide which editor to supply, but as my model grows so do the switch statements.

Qt Code:
  1. QWidget* editor;
  2.  
  3. QModelIndex parentIndex = index.model()->parent(index);
  4.  
  5. switch (index.model()->parent(index).row())
  6. {
  7. case 0:
  8. {
  9. switch (index.row())
  10. {
  11. case 0:
  12. case 1:
  13. {
  14. editor = new QLineEdit(parent);
  15. }
  16. break;
  17.  
  18. case 2:
  19. {
  20. Common::Enumerations::surveyUnits().getDisplayStrings(list);
  21. editor = new QComboBox(parent);
  22. ((QComboBox*)editor)->addItems(list);
  23. }
  24. break;
  25. }
  26. }
  27. break;
  28.  
  29. case 1:
  30. {
  31. editor = new QLineEdit(parent);
  32. ((QLineEdit*)editor)->setValidator(new QIntValidator());
  33. }
  34. break;
  35. }
  36. return editor;
To copy to clipboard, switch view to plain text mode 


Is there a better way to achieve this?

TIA