How to best model data for Model/View
-
Hi,
First of all I'm sorry if this is not the correct place for this question.
I'm working on various widgets(views) that work on data that is dependent on each other.
For example; we have a list of people, and each person has a number of attributes and owns some files of different types.
One widget is in charge of displaying all people, while another one works only with the files belonging to one specific person.
How would you go about modeling the data?
Option1: One model encompassing all data. Probably a Tree structured data with leaves of different types?. Delegates of each view take care of selecting which data is to be used.
Option2: One model for the list of people (table), one model for the files of one person(tree/table), which must be updated when the person changes.
Option3: ?
Thanks a lot for your time.
I'd appreciate any inputBest, Valentin.
-
Hi,
First of all I'm sorry if this is not the correct place for this question.
I'm working on various widgets(views) that work on data that is dependent on each other.
For example; we have a list of people, and each person has a number of attributes and owns some files of different types.
One widget is in charge of displaying all people, while another one works only with the files belonging to one specific person.
How would you go about modeling the data?
Option1: One model encompassing all data. Probably a Tree structured data with leaves of different types?. Delegates of each view take care of selecting which data is to be used.
Option2: One model for the list of people (table), one model for the files of one person(tree/table), which must be updated when the person changes.
Option3: ?
Thanks a lot for your time.
I'd appreciate any inputBest, Valentin.
-
Hi,
Looks like structured data, did you consider putting them in a database such as SQLite ?
-
@valenrw
You want a simple correspondence for Qt's models and views. A model represents one table and should have one kind of data. Separate models, with separate views, for separate tables. You will want to go Option #2 rather than your Option 1. -
Hi,
Looks like structured data, did you consider putting them in a database such as SQLite ?
@SGaist I had considered the option but thought I could keep avoiding implementing the database, which I've never done. Now it seems like implementing the models as QSqlTableModel and QSqlRelationalTableModel accessing the database is indeed the most sensible option in the long term. Thanks for your suggestion!