void clsList::strModel()
{
strmodel->setTable("setCls_str");
strmodel->setFilter("setCls_str.actv1=1");
int clInd = strmodel->fieldIndex("classCode");
int strInd = strmodel->fieldIndex("streams");
int clTInd = strmodel->fieldIndex("clTeach");
strmodel
->setRelation
(clInd,
QSqlRelation("tblClass",
"clID",
"clCode"));
strmodel
->setRelation
(strInd,
QSqlRelation("tblStreams",
"strID",
"strName"));
strmodel
->setRelation
(clTInd,
QSqlRelation("allTeachers",
"trID",
"trName"));
strmodel->setHeaderData(strInd, Qt::Horizontal, tr("Stream"));
strmodel->setHeaderData(clInd, Qt::Horizontal, tr("Class"));
strmodel->setHeaderData(clTInd, Qt::Horizontal, tr("Teacher"));
strmodel->database().transaction();
if(strmodel->submitAll())
{
strmodel->database().commit();
}
else
{
strmodel->database().rollback();
}
if (!strmodel->select()) {
showError(strmodel->lastError());
return;}
strProxy = new SortFilterProxyModel(this);
strProxy->setSourceModel(strmodel);
strProxy->setFilterCaseSensitivity(Qt::CaseInsensitive);
ui->strmv->setModel(strProxy); // with this line all comboboxes disappear on my tableview
// ui->strmv->setModel(strModel); // This line works well....with comboboxes visible on the grid
//but I need to filter data according to some parameters
ui->strmv->setColumnWidth(clInd,50);
ui->strmv->setColumnWidth(strInd,100);
ui->strmv->setColumnWidth(clTInd,100);
}
void clsList::strModel()
{
strmodel = new QSqlRelationalTableModel(this);
strmodel->setEditStrategy(QSqlTableModel::OnRowChange);
strmodel->setTable("setCls_str");
strmodel->setFilter("setCls_str.actv1=1");
int clInd = strmodel->fieldIndex("classCode");
int strInd = strmodel->fieldIndex("streams");
int clTInd = strmodel->fieldIndex("clTeach");
strmodel->setRelation(clInd, QSqlRelation("tblClass", "clID", "clCode"));
strmodel->setRelation(strInd, QSqlRelation("tblStreams", "strID", "strName"));
strmodel->setRelation(clTInd, QSqlRelation("allTeachers", "trID", "trName"));
strmodel->setHeaderData(strInd, Qt::Horizontal, tr("Stream"));
strmodel->setHeaderData(clInd, Qt::Horizontal, tr("Class"));
strmodel->setHeaderData(clTInd, Qt::Horizontal, tr("Teacher"));
strmodel->database().transaction();
if(strmodel->submitAll())
{
strmodel->database().commit();
}
else
{
strmodel->database().rollback();
}
if (!strmodel->select()) {
showError(strmodel->lastError());
return;}
strProxy = new SortFilterProxyModel(this);
strProxy->setSourceModel(strmodel);
strProxy->setFilterCaseSensitivity(Qt::CaseInsensitive);
ui->strmv->setModel(strProxy); // with this line all comboboxes disappear on my tableview
// ui->strmv->setModel(strModel); // This line works well....with comboboxes visible on the grid
//but I need to filter data according to some parameters
ui->strmv->setItemDelegate(new QSqlRelationalDelegate(ui->strmv));
ui->strmv->setColumnWidth(clInd,50);
ui->strmv->setColumnWidth(strInd,100);
ui->strmv->setColumnWidth(clTInd,100);
}
To copy to clipboard, switch view to plain text mode
Bookmarks