Hello,

I have been working on a simple data editor. Using a QComboBox, user selects an object id which in turn via QDataWidgetMapper and a custom Delegate selects appropriate data from QStandardItemView and displays them in their respective QLineEdit fields. This works perfectly in case every data element has the same number of data fields, i.e:

Qt Code:
  1. (1)
  2. +=================+
  3. | SimpleData |
  4. +=================+
  5. | int id |
  6. | int position[3] |
  7. | QString name |
  8. +-----------------+
To copy to clipboard, switch view to plain text mode 

Moving from simple to less-simple I was forced to change the data layout in a way that there are several types of elements containing few common and some different data fields, i.e:

Qt Code:
  1. (2)
  2. +====================+
  3. | GeometricPrimitive |
  4. +====================+
  5. | int id |
  6. | Type geom_type |
  7. +----------->| QColor color |<-----------+
  8. | | int position[3] | |
  9. | +--------------------+ |
  10. | ^ |
  11. | | |
  12. +====================+ +====================+ +====================+
  13. | Sphere | | Box | | Cylinder |
  14. +====================+ +====================+ +====================+
  15. | int radius | | int size_x | | int base_x |
  16. +--------------------+ | int size_y | | int base_y |
  17. | int size_z | | int base_z |
  18. +--------------------+ | int axis_x |
  19. | int axis_y |
  20. | int axis_z |
  21. | int radius |
  22. +--------------------+
To copy to clipboard, switch view to plain text mode 

Supposing GeometricPrimitive is abstract, now there are three different types of objects with different fields. Showing and hiding different QLineEdits and reorganizing the layout is easy (using QComboBox signals). However I assume it would be fairly inefficient to store such data in a single QStandardItemModel, since there would be too many empty cells.

An idea that comes to my mind is to create three separate QStandardItemModels, each for Sphere, Box and Cylinder, and then -- somehow -- bind them together and make them work towards single view.

What would be the best way to tackle this problem? What approach and type of model should I use?