How should I use the model/view for my application
-
I am building a 3d molecule editor. I am using qt3d and c++.
The following is my data structure for the molecule.
struct Atom { QString name; int atomicNumber; double mass; QVector3D position; }; struct Bond { int sourceAtomIndex; int targetAtomIndex; double bondLength; }; struct Molecule { QList<Atom> atoms; QList<Bond> bonds; QVector3D position; QQuaternion rotation; };I need to maintain this data structure while accepting changes from ui and the 3d scene. The UI will have a list view and table view. List for the molecules and two tables for the corresponding atoms and bonds.
I have currently implemented a QAbstractListModel. This will work fine for the list view. However, I am not sure how to manage the table view and the model.
Question:
Should I create a new table model for the table view once I get the atom and bonds details? Then how would make the changes in the original model?How should I connect the 3d scene to make changes to my model?
-
Hi,
For the table views, you can map the columns with each properties of your atom and bond objects.
As for propagating the changes, what kind of changes will you be doing ? Where will they come from ?
@SGaist @jeremy_k Thank you guys. I ended up using a new table model (AtomTableModel) which is connected to a table view. I have controller class which propogates any changes in the AtomTableModel to main MoleculeModel.
@jeremy_k I can not use an item view becuase the items are different? In my understanding of qt item model/view, you can not do that. I am probably wrong though.
-
Hi,
For the table views, you can map the columns with each properties of your atom and bond objects.
As for propagating the changes, what kind of changes will you be doing ? Where will they come from ?
-
Hi,
For the table views, you can map the columns with each properties of your atom and bond objects.
As for propagating the changes, what kind of changes will you be doing ? Where will they come from ?
@SGaist @jeremy_k Thank you guys. I ended up using a new table model (AtomTableModel) which is connected to a table view. I have controller class which propogates any changes in the AtomTableModel to main MoleculeModel.
@jeremy_k I can not use an item view becuase the items are different? In my understanding of qt item model/view, you can not do that. I am probably wrong though.
-
H Hamza Umair has marked this topic as solved on
-
@SGaist @jeremy_k Thank you guys. I ended up using a new table model (AtomTableModel) which is connected to a table view. I have controller class which propogates any changes in the AtomTableModel to main MoleculeModel.
@jeremy_k I can not use an item view becuase the items are different? In my understanding of qt item model/view, you can not do that. I am probably wrong though.
@Hamza-Umair said in How should I use the model/view for my application:
@jeremy_k I can not use an item view becuase the items are different? In my understanding of qt item model/view, you can not do that. I am probably wrong though.
You absolutely can have different types of data in a single view. Use a designated role in a designated column to indicate the type. A view delegate can use this role to alter the display for each type.
QStandardItem::type() is another way to represent this strategy.A view can also use a filter model to remove types that should be hidden. QAbstractItemView::setRootIndex() can be useful for limiting display to children of a particular node (i.e. the Bond list of a particular Molecule)
The address book demonstrates filtering and multiple views from a single model.
https://doc.qt.io/qt-6/qtwidgets-itemviews-addressbook-example.html