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?
Re: QTableView, QSortFilterProxyModel and relational SQL model?
Could we see the code? What exactly does the proxy filter out?
Re: QTableView, QSortFilterProxyModel and relational SQL model?
Here is the source model setup:
Code:
//setup All Rules model
allRulesModel->setTable("rules");
allRulesModel->setHeaderData(0,Qt::Horizontal, tr("Rule ID"));
allRulesModel->setHeaderData(1,Qt::Horizontal, tr("Request Id"));
allRulesModel->setHeaderData(2,Qt::Horizontal, tr("Condition"));
allRulesModel->setHeaderData(3,Qt::Horizontal, tr("Trigger"));
allRulesModel->setHeaderData(4,Qt::Horizontal, tr("Action"));
allRulesModel->setHeaderData(5,Qt::Horizontal, tr("Action Data"));
allRulesModel->setHeaderData(6,Qt::Horizontal, tr("Start On"));
allRulesModel->setHeaderData(7,Qt::Horizontal, tr("End on"));
allRulesModel->setHeaderData(8,Qt::Horizontal, tr("State"));
allRulesModel->setHeaderData(9,Qt::Horizontal, tr("Notes"));
allRulesModel
->setRelation
(2,
QSqlRelation("ruleconditions",
"condition",
"condition"));
//allRulesModel->setRelation(3,QSqlRelation("ruletriggers","ruletrigger","ruletrigger"));
//allRulesModel->setRelation(8,QSqlRelation("requeststates","state","state"));
allRulesModel->select();
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:
Code:
// setup All rules view
allRulesFilterModel->setSourceModel(allRulesModel);
//TODO: restore filter model when working properly
ruleSearchResults_tableView->setModel(allRulesFilterModel);
//ruleSearchResults_tableView->setModel(allRulesModel);
ruleSearchResults_tableView->hideColumn(5);
ruleSearchResults_tableView->hideColumn(9);
ruleSearchResults_tableView->horizontalHeader()->stretchLastSection();
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.
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.
Re: QTableView, QSortFilterProxyModel and relational SQL model?
Quote:
Originally Posted by
wysota
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?
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.
Re: QTableView, QSortFilterProxyModel and relational SQL model?
Quote:
Originally Posted by
frido
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