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. QSortFilterProxyModel over QSqlRelationalTableModel : insertingColumn(s) snippet needed
Forum Updated to NodeBB v4.3 + New Features

QSortFilterProxyModel over QSqlRelationalTableModel : insertingColumn(s) snippet needed

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 3.4k Views 1 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.
  • P Offline
    P Offline
    pasomas
    wrote on last edited by
    #1

    Hi all!
    i have the issue on the title trying to insert 3 columns (only displayed) using QSortFilterProxyModel on a QTableView feeded by a QSqlRelationalTableModel.
    I'm looking for a snippet for subclassing and using the QSFPM correctly because i can't make it work in any situation : the columns never appear.

    @m_proxyModel = new DossierProxyModel(this);
    m_proxyModel->setSourceModel(m_mainModel);
    m_proxyModel->setDynamicSortFilter(true);

    bool ok = m_proxyModel->insertColumns(3, 3); // ok is always true

    ui->tvDList->setModel(m_proxyModel);@

    m_proxyModel is a (almost empty) subclassed QSortFilterProxyModel that (at the moment) doesn't alter the source model displayed content.

    m_mainModel (a QSqlRelationalTableModel) without the proxy works fine and i can display and edit data synchronizing with a MySQL db.

    Before implementing a correct proxy model, shouldn't i see the new 3 columns appearing on tableview ?

    Do i need to implement my own insertColumns method in the proxy?

    I searched everywhere on the web and i didn't find anything about a complete tutorial/example/snippet about subclassing a QSortFilterProxyModel for columns insertion and i don't know how to finish the work.

    I'm working with a 4.7 and i'm trying to improve my Qt usage.

    Thank you in advance for any hint

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      [quote author="pasomas" date="1333752749"]Hi all!
      Before implementing a correct proxy model, shouldn't i see the new 3 columns appearing on tableview?[/quote]
      No. the insertColumn method only works for models that actually support that operation. Your models do not, so the operation is basically void.

      [quote]
      Do i need to implement my own insertColumns method in the proxy?[/quote]
      Yes, that's what it comes down to.

      [quote]
      I searched everywhere on the web and i didn't find anything about a complete tutorial/example/snippet about subclassing a QSortFilterProxyModel for columns insertion and i don't know how to finish the work.

      I'm working with a 4.7 and i'm trying to improve my Qt usage.[/quote]

      I guess it all depends on what it is you really want to do. Do you just want to add a couple of columns that display some data derived from the information in the other colums, or do you really want to add columns to your source database? It seems you want to do the former, but could you try to explain your exact goal a bit better anyway please?

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pasomas
        wrote on last edited by
        #3

        Thank you Andre for your reply.
        I realized my question was not well exposed.
        The answer is near the former situation but taking data from another table, not from the other columns.
        My goal is to display 3 further read-only columns to the user without modifying the database.

        I have a table Dossier that the user manages completely through a QTableView, a QSqlRelationalTableModel and a QDataWidgetMapper.
        I have this :

        Dossier | Dossier Description | Customer Code | Dossier Type

        and i just want to achieve this

        Dossier | Dossier Description | Customer Code | Customer Business Name | Customer Name | Customer Surname | Dossier Type

        Customer related new fields should be read from the relational table "Customer" by the key "Customer Code".

        I would ask you what should be the correct approach and an example/snippet if possible.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          Sounds like you should solve that by simply modifying your SQL query...

          1 Reply Last reply
          0
          • P Offline
            P Offline
            pasomas
            wrote on last edited by
            #5

            Ok, so am i in the situation described by "this old thread":http://qt-project.org/forums/viewthread/2862 ?
            I'll try redefine the select statament or maybe better setting it through the setQuery in my subclassed QSqlRelationalModel.

            I thought there was an "higher level solution"...i have a main table and 4 relations to other tables and the statement is not small. :)

            Thank you Andre, if i'll make it work i'll mark the thread as resolved.

            1 Reply Last reply
            0
            • P Offline
              P Offline
              pasomas
              wrote on last edited by
              #6

              I changed all the code to work with QSqlQueryModel and i removed the QDataWidgetMapper.
              The code is pretty longer but now is more flexible and it works fine.

              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