//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();
//setup All Rules model
allRulesModel = new QSqlRelationalTableModel;
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->setEditStrategy(QSqlTableModel::OnManualSubmit);
allRulesModel->setRelation(2,QSqlRelation("ruleconditions","condition","condition"));
//allRulesModel->setRelation(3,QSqlRelation("ruletriggers","ruletrigger","ruletrigger"));
//allRulesModel->setRelation(8,QSqlRelation("requeststates","state","state"));
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.
// 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();
// setup All rules view
allRulesFilterModel = new QSortFilterProxyModel;
allRulesFilterModel->setSourceModel(allRulesModel);
//TODO: restore filter model when working properly
ruleSearchResults_tableView->setModel(allRulesFilterModel);
//ruleSearchResults_tableView->setModel(allRulesModel);
ruleSearchResults_tableView->setItemDelegate(new QSqlRelationalDelegate(ruleSearchResults_tableView));
ruleSearchResults_tableView->hideColumn(5);
ruleSearchResults_tableView->hideColumn(9);
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.
Bookmarks