Results 1 to 2 of 2

Thread: Model for non-uniform data?

  1. #1
    Join Date
    Feb 2015
    Posts
    4
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Question Model for non-uniform data?

    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?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Model for non-uniform data?

    The best way would be to create a custom model tailored for your data.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 4
    Last Post: 21st October 2013, 22:24
  2. Replies: 9
    Last Post: 14th February 2013, 20:39
  3. Replies: 0
    Last Post: 2nd November 2011, 12:13
  4. Replies: 1
    Last Post: 24th February 2011, 06:54
  5. Non-uniform cells
    By ttvo in forum Qt Programming
    Replies: 2
    Last Post: 22nd April 2009, 20:20

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.