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. Duplicate roles across models
Forum Updated to NodeBB v4.3 + New Features

Duplicate roles across models

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 171 Views 3 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.
  • E Offline
    E Offline
    ECEC
    wrote last edited by ECEC
    #1

    I have a list model for Interpolator, and a list model for Sequence. My Sequence objects can have an Interpolator assigned to them, and this is done via association of the Interpolator's ID.

    In my Sequence list view delegate, I'd like to resolve the assigned Interpolator's ID to its name. I currently do this by exposing a duplicate role "interpolator_name" in the Sequence list model which calls data() on the Interpolator model to retrieve the name. I also connect to dataChanged() so we're aware of any name changes.

    This all seems a bit fragile to me. Is there a better way?

    1 Reply Last reply
    0
    • jeremy_kJ Offline
      jeremy_kJ Offline
      jeremy_k
      wrote last edited by
      #2

      Is a duplicate role merely an additional role in the Sequence model?
      What does fragile mean?

      The described solution seems reasonable. An alternative is to copy the data, either relying on the Interpolator::dataChanged() signal, or a setter function that updates both models. Is efficient storage more or less important than efficient retrieval?

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

      1 Reply Last reply
      0
      • E Offline
        E Offline
        ECEC
        wrote last edited by
        #3

        Is a duplicate role merely an additional role in the Sequence model?

        Yes, but I suppose a role that points to the same data as the one in Interpolator model.

        What does fragile mean?

        By having the Interpolator name exposed in 2 models, we no longer have a single source of truth and have to maintain synchronisation between the 2 models. In this use case it's not a major problem so maybe I'm trying to find a solution to a non-existent problem...

        SGaistS 1 Reply Last reply
        0
        • E ECEC

          Is a duplicate role merely an additional role in the Sequence model?

          Yes, but I suppose a role that points to the same data as the one in Interpolator model.

          What does fragile mean?

          By having the Interpolator name exposed in 2 models, we no longer have a single source of truth and have to maintain synchronisation between the 2 models. In this use case it's not a major problem so maybe I'm trying to find a solution to a non-existent problem...

          SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote last edited by
          #4

          @ECEC hi,

          Did you already took a look at the QSqlRelationalTableModel ?
          It sounds like it should cover your use case.

          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
          • E Offline
            E Offline
            ECEC
            wrote last edited by
            #5

            @SGaist , Would it not be overkill to introduce a relational database for such a simple task?

            SGaistS 1 Reply Last reply
            0
            • E ECEC

              @SGaist , Would it not be overkill to introduce a relational database for such a simple task?

              SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote last edited by
              #6

              @ECEC it could be yes. Not knowing more in details what your data structure is, it sounded like some sort of two table database hence my suggestion.

              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

              • Login

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