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. Model View with nested lists
QtWS25 Last Chance

Model View with nested lists

Scheduled Pinned Locked Moved Solved General and Desktop
modelviewarchitectureqlistview
6 Posts 2 Posters 3.9k Views
  • 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.
  • F Offline
    F Offline
    flimberger
    wrote on 21 Oct 2016, 10:30 last edited by
    #1

    Hi,

    I have some rather simple data available as nested std::vectors, which I want to show in two list views. Although this could be represented as a tree, it strikes me as overkill, as Parent and Child do not share a common base class. So my question is, how would this structure best implemented in the Model View framework provided by Qt? Two nested list models are rather hard to synchronize, imposing a common base class on the data feels unnatural to me.

    The rough structure in code is as follows:

    class Child {
         // Some boring data with accessors and stuff
    };
    
    class Parent {
    public:
        Foo(QString name);
    
        QString name() const;
        const std::vector<std::shared_ptr<Bar>> &entries();
       // some accessors and stuff
    
    private:
        QString m_name;
        std::vector<std::shared_ptr<Bar>> m_entries;
    };
    
    std::vector<std::shared_ptr<Parent>> getData() {
        // returns a vector of ``Parent`` pointers, which in turn contain vectors of ``Child`` pointers
    }
    

    and a simple UI mockup:
    uimockup.png

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 21 Oct 2016, 22:11 last edited by
      #2

      Hi and welcome to devnet,

      What are you going to show from Child in your view ?

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

      1 Reply Last reply
      0
      • F Offline
        F Offline
        flimberger
        wrote on 24 Oct 2016, 16:28 last edited by
        #3

        What are you going to show from Child in your view ?

        The data contained in Child class, which consists mostly of QString.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 24 Oct 2016, 16:51 last edited by
          #4

          So you are going to show in the second list view the child content from the parent select in the first view ?

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

          F 1 Reply Last reply 24 Oct 2016, 17:12
          0
          • S SGaist
            24 Oct 2016, 16:51

            So you are going to show in the second list view the child content from the parent select in the first view ?

            F Offline
            F Offline
            flimberger
            wrote on 24 Oct 2016, 17:12 last edited by
            #5

            So you are going to show in the second list view the child content from the parent select in the first view ?

            Yes, I thought about the following structure:

            ├ Parent0 (selected in List View 1)
            │ ├ Child (shown in List View 2)
            │ ├ Child (selected in List View 2)
            │ │ └ Contents of Child shown in the lower area
            │ └ Child (shown in List View 2)
            ├ Parent (shown in List View 1)
            │ ├ Child
            │ └ Child
            └ Parent (shown in List View 1)
              └ Child
            

            It looks like a tree, but the question is how would I impose this tree structure onto the model classes. The simple tree model example uses an actual tree to store the data, which is not the case in my situation.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 24 Oct 2016, 18:49 last edited by
              #6

              Technically you have a two-level tree.

              You can still use that example as a base. In place of their custom TreeViewItem you have your Parent and Child.

              Those the abstract model would be a wrapper around your Parent/Child combo.

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

              1 Reply Last reply
              0

              1/6

              21 Oct 2016, 10:30

              • Login

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