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. Reordered table model

Reordered table model

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 1.6k 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.
  • S Offline
    S Offline
    sebolinho61
    wrote on last edited by sebolinho61
    #1

    Hello,

    I have to create a widget to administrate (read + write) a sqlite database with the following structure :

    idIngredient | idDessert | Quantity
    1 | 10 | 3
    2 | 11 | 8
    3 | 10 | 9
    1 | 11 | 7

    Here, idIngredient and idDessert are foreign Keys which reference other tables. Let say :
    Ingredient :
    1 : sugar
    2 : flour
    3 : water

    Dessert :
    10 : Pie
    11 : Cake

    I'm would like to display them in a crossed table :
    ...........|..Sugar... |..Flour.. | Water
    Pie.... |... 3......... |.............. |.... 9.....
    Cake..|... 7......... |....... 8... |............

    Can I do that simply using existing Qt sql model tools (relational ? Or others) ? (which would avoir me to write update queries...). If not, how can i do that ?
    I imagine I'm not the only one with this need.

    Thank you in advance for your help.

    Best regards,

    Sébastien

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

      Hi,

      What size should the cake be ? ;)

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

      S 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        What size should the cake be ? ;)

        S Offline
        S Offline
        sebolinho61
        wrote on last edited by sebolinho61
        #3

        @SGaist Hi ! Are you serious ? What do you mean by "size"?

        I think i could do it by writing 2 table models :

        • 1 Qsqlrelationaltablemodel which performs queries on the raw table
        • 1 simple QStandardItemModel which has the previous sql model as a member and the right number of row and cols (returned by sql model). I can overload setData method to invoke Qsqlrelationaltablemodel::setData on the right index.

        Isn't it a bit complicated ? Is there a simplest way to do that ?

        Thks

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

          I meant how big would the resulting cake be ;-)

          So you would like to have both header views matching the content of the ingredient and dessert table while the content itself would be the table of quantity of each ingredient by desert, right ?

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

          S 1 Reply Last reply
          0
          • SGaistS SGaist

            I meant how big would the resulting cake be ;-)

            So you would like to have both header views matching the content of the ingredient and dessert table while the content itself would be the table of quantity of each ingredient by desert, right ?

            S Offline
            S Offline
            sebolinho61
            wrote on last edited by sebolinho61
            #5

            @SGaist Yes, it's exactly that : both header views should match the number of entries of Ingredient and Dessert tables. Number of dessert and Ingredient should contain fewer than 5-6 different entries, so this would be more readable than displaying the original raw table.

            Thank you.

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

              You would likely need a proxy model on top of your QSqlRelationalTableModel in order to move your indexes around without doing special queries.

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

              S 1 Reply Last reply
              1
              • SGaistS SGaist

                You would likely need a proxy model on top of your QSqlRelationalTableModel in order to move your indexes around without doing special queries.

                S Offline
                S Offline
                sebolinho61
                wrote on last edited by
                #7

                @SGaist Hi !
                Sorry to wake up only now... QAbstractProxyModels are very powerful objects !
                Thank you for your answer, it was exactly what I needed.
                Bye

                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