Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How should I use the model/view for my application

How should I use the model/view for my application

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 420 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hamza Umair
    wrote on last edited by Hamza Umair
    #1

    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?

    1 Reply Last reply
    0
    • SGaistS SGaist

      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 ?

      H Offline
      H Offline
      Hamza Umair
      wrote on last edited by
      #4

      @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.

      jeremy_kJ 1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        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 ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        H 1 Reply Last reply
        0
        • jeremy_kJ Offline
          jeremy_kJ Offline
          jeremy_k
          wrote on last edited by
          #3

          I would represent the data using a tree model. Molecules are the top level items. Atoms and bonds are children of molecules.

          Asking a question about code? http://eel.is/iso-c++/testcase/

          1 Reply Last reply
          0
          • SGaistS SGaist

            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 ?

            H Offline
            H Offline
            Hamza Umair
            wrote on last edited by
            #4

            @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.

            jeremy_kJ 1 Reply Last reply
            0
            • H Hamza Umair has marked this topic as solved on
            • H Hamza Umair

              @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.

              jeremy_kJ Offline
              jeremy_kJ Offline
              jeremy_k
              wrote on last edited by
              #5

              @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

              Asking a question about code? http://eel.is/iso-c++/testcase/

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved