Results 1 to 7 of 7

Thread: QTableView, QSortFilterProxyModel and relational SQL model?

  1. #1
    Join Date
    Jan 2006
    Posts
    44
    Thanks
    9
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11

    Unhappy QTableView, QSortFilterProxyModel and relational SQL model?

    I've got a table view that I would like to allow filtering, editing and still use the relation sql table model I'm using.

    When I set the views model to the source model, I get the dropdown box for foreign keys as I should. Thus I know the underlying code regarding relation modeling works. But when I change it to the QSortFilterProxyModel instance, the dropdown boxes go away.

    Is it possible using standard Qt to achieve this? I'd prefer to keep it pretty standard.

    If not doable using standard stuff, what all would be involved in making it work?
    --
    The Real Bill

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTableView, QSortFilterProxyModel and relational SQL model?

    Could we see the code? What exactly does the proxy filter out?

  3. #3
    Join Date
    Jan 2006
    Posts
    44
    Thanks
    9
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11

    Default Re: QTableView, QSortFilterProxyModel and relational SQL model?

    Here is the source model setup:
    Qt Code:
    1. //setup All Rules model
    2. allRulesModel = new QSqlRelationalTableModel;
    3. allRulesModel->setTable("rules");
    4. allRulesModel->setHeaderData(0,Qt::Horizontal, tr("Rule ID"));
    5. allRulesModel->setHeaderData(1,Qt::Horizontal, tr("Request Id"));
    6. allRulesModel->setHeaderData(2,Qt::Horizontal, tr("Condition"));
    7. allRulesModel->setHeaderData(3,Qt::Horizontal, tr("Trigger"));
    8. allRulesModel->setHeaderData(4,Qt::Horizontal, tr("Action"));
    9. allRulesModel->setHeaderData(5,Qt::Horizontal, tr("Action Data"));
    10. allRulesModel->setHeaderData(6,Qt::Horizontal, tr("Start On"));
    11. allRulesModel->setHeaderData(7,Qt::Horizontal, tr("End on"));
    12. allRulesModel->setHeaderData(8,Qt::Horizontal, tr("State"));
    13. allRulesModel->setHeaderData(9,Qt::Horizontal, tr("Notes"));
    14. allRulesModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
    15. allRulesModel->setRelation(2,QSqlRelation("ruleconditions","condition","condition"));
    16. //allRulesModel->setRelation(3,QSqlRelation("ruletriggers","ruletrigger","ruletrigger"));
    17. //allRulesModel->setRelation(8,QSqlRelation("requeststates","state","state"));
    18. allRulesModel->select();
    To copy to clipboard, switch view to plain text mode 
    Lines 16 and 17 were commented out while trying to narrow down the problem. No difference if they are not commented out.

    and the filtermodel and view setup:
    Qt Code:
    1. // setup All rules view
    2. allRulesFilterModel = new QSortFilterProxyModel;
    3. allRulesFilterModel->setSourceModel(allRulesModel);
    4. //TODO: restore filter model when working properly
    5. ruleSearchResults_tableView->setModel(allRulesFilterModel);
    6. //ruleSearchResults_tableView->setModel(allRulesModel);
    7. ruleSearchResults_tableView->setItemDelegate(new QSqlRelationalDelegate(ruleSearchResults_tableView));
    8. ruleSearchResults_tableView->hideColumn(5);
    9. ruleSearchResults_tableView->hideColumn(9);
    10. ruleSearchResults_tableView->horizontalHeader()->stretchLastSection();
    To copy to clipboard, switch view to plain text mode 
    The filter (in one of the views) filters based on the requestid colum (clicking a row in a QTableView sets the filter text), and in the other I have a QComboBox and QLineEdit to allow the user to search in various columns, or none at all to show all of the rules. If I use line 6 instead of 5 in the second code block, it works fine. Other than not filtering of course.
    --
    The Real Bill

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTableView, QSortFilterProxyModel and relational SQL model?

    I just had a look at the source code. It looks like QSqlRelationalDelegate won't work with a proxy because it expect the model to be QSqlRelationalTableModel. So you need to implement a similar delegate yourself, for example by copying the code and injecting the pointer to the relational model with another method.

  5. #5
    Join Date
    Jan 2008
    Location
    Slovenia
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTableView, QSortFilterProxyModel and relational SQL model?

    Quote Originally Posted by wysota View Post
    I just had a look at the source code. It looks like QSqlRelationalDelegate won't work with a proxy because it expect the model to be QSqlRelationalTableModel. So you need to implement a similar delegate yourself, for example by copying the code and injecting the pointer to the relational model with another method.
    I know this is 1 year old theme, but can you post some more details about this delegate implementation.

    I came across the same problem. I'm using QDataWidgetMapper. It works great with QSqlRelationalTableModel, but now I'd like to set filter to the model and don't want to use setFilter(), becuase it would querry again my database. If I use QSortFilterProxyModel I can't use relations in mapper.

    Is therre any way to subclass QSortFilterProxyModel to use relations or something?

  6. #6
    Join Date
    Mar 2010
    Location
    Helsinki, Finland
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTableView, QSortFilterProxyModel and relational SQL model?

    Frido, what's your situation with this problem? I just ran into it myself and will probably start untangling it for myself in near future.

  7. #7
    Join Date
    Sep 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTableView, QSortFilterProxyModel and relational SQL model?

    Quote Originally Posted by frido View Post
    I know this is 1 year old theme, but can you post some more details about this delegate implementation.

    I came across the same problem. I'm using QDataWidgetMapper. It works great with QSqlRelationalTableModel, but now I'd like to set filter to the model and don't want to use setFilter(), becuase it would querry again my database. If I use QSortFilterProxyModel I can't use relations in mapper.

    Is therre any way to subclass QSortFilterProxyModel to use relations or something?
    I see this is very old thread. But maybe this will help somebody.
    There is a working subclass on this link that solves that problem
    http://developer.qt.nokia.com/wiki/Q...onalTableModel
    Last edited by sinanceylan; 22nd November 2011 at 04:11.

Similar Threads

  1. Relational table model Calulation
    By aekilic in forum Qt Programming
    Replies: 8
    Last Post: 7th February 2007, 23:40
  2. Relational Table Model Problem
    By aekilic in forum Qt Programming
    Replies: 2
    Last Post: 20th January 2007, 14:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.