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:
(1)
+=================+
| SimpleData |
+=================+
| int id |
| int position[3] |
+-----------------+
(1)
+=================+
| SimpleData |
+=================+
| int id |
| int position[3] |
| QString name |
+-----------------+
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:
(2)
+====================+
| GeometricPrimitive |
+====================+
| int id |
| Type geom_type |
+----------->|
QColor color |<
-----------+ | | int position[3] | |
| +--------------------+ |
| ^ |
| | |
+====================+ +====================+ +====================+
| Sphere | | Box | | Cylinder |
+====================+ +====================+ +====================+
| int radius | | int size_x | | int base_x |
+--------------------+ | int size_y | | int base_y |
| int size_z | | int base_z |
+--------------------+ | int axis_x |
| int axis_y |
| int axis_z |
| int radius |
+--------------------+
(2)
+====================+
| GeometricPrimitive |
+====================+
| int id |
| Type geom_type |
+----------->| QColor color |<-----------+
| | int position[3] | |
| +--------------------+ |
| ^ |
| | |
+====================+ +====================+ +====================+
| Sphere | | Box | | Cylinder |
+====================+ +====================+ +====================+
| int radius | | int size_x | | int base_x |
+--------------------+ | int size_y | | int base_y |
| int size_z | | int base_z |
+--------------------+ | int axis_x |
| int axis_y |
| int axis_z |
| int radius |
+--------------------+
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?
Bookmarks