{
ui->setupUi(this);
//bla bla bla...
//bla bla bla...
myeditModel->setTable("myFirstTable");
myeditModel
->setRelation
(myeditModel
->fieldIndex
("myFirstForeignKeyID"/*1*/),
QSqlRelation("mySecondTable",
"id",
"name"));
myeditModel
->setRelation
(myeditModel
->fieldIndex
("mySecondForeignKeyID"/*2*/),
QSqlRelation("myThirdTable",
"id",
"name"));
myeditModel
->setRelation
(myeditModel
->fieldIndex
("myCodeID"/*3*/),
QSqlRelation("myFourthTable",
"id",
"myCode"));
myeditModel->select();
ui->myFirstComboBox->setModel(relationModel1);
ui->myFirstComboBox->setModelColumn(relationModel1->fieldIndex("name"));
ui->mySecondComboBox->setModel(relationModel2);
ui->mySecondComboBox->setModelColumn(relationModel2->fieldIndex("name"));
mapper->setModel(myeditModel);
mapper->addMapping(ui->myFirstComboBox, 1);
mapper->addMapping(ui->mySecondComboBox, 2);
mapper->addMapping(ui->codeEdit, 3);
mapper->addMapping(ui->dateEdit, 4);
//bla bla bla...
//bla bla bla...
mapper->setCurrentIndex(row);
QString filterValue
= ui
->codeEdit
->text
();
myproxy->setSourceModel(myeditModel);
myproxy->setFilterCaseSensitivity(Qt::CaseInsensitive);
myproxy
->setFilterRegExp
(QRegExp(filterValue, Qt
::CaseInsensitive,
QRegExp::FixedString));
myproxy->setFilterKeyColumn(/*-1*/3);
ui->EditView->setModel(myproxy);
ui->EditView->resizeRowsToContents();
ui->EditView->resizeColumnsToContents();
ui->EditView->setSortingEnabled(true);
ui->EditView->setColumnHidden(0, true);
}
myEditDialog::~myEditDialog()
{
delete ui;
}
void myEditDialog
::on_codeEdit_selictionChanged(const QString &arg1
) {
myproxy->setFilterFixedString(arg1);
}
{
ui->setupUi(this);
//bla bla bla...
//bla bla bla...
myeditModel = new QSqlRelationalTableModel(this);
myeditModel->setTable("myFirstTable");
myeditModel->setRelation(myeditModel->fieldIndex("myFirstForeignKeyID"/*1*/), QSqlRelation("mySecondTable","id","name"));
myeditModel->setRelation(myeditModel->fieldIndex("mySecondForeignKeyID"/*2*/), QSqlRelation("myThirdTable","id","name"));
myeditModel->setRelation(myeditModel->fieldIndex("myCodeID"/*3*/), QSqlRelation("myFourthTable","id","myCode"));
myeditModel->select();
QSqlTableModel *relationModel1 = myeditModel->relationModel(1);
ui->myFirstComboBox->setModel(relationModel1);
ui->myFirstComboBox->setModelColumn(relationModel1->fieldIndex("name"));
QSqlTableModel *relationModel2 = myeditModel->relationModel(2);
ui->mySecondComboBox->setModel(relationModel2);
ui->mySecondComboBox->setModelColumn(relationModel2->fieldIndex("name"));
mapper = new QDataWidgetMapper(this);
mapper->setSubmitPolicy(QDataWidgetMapper::AutoSubmit);
mapper->setModel(myeditModel);
mapper->setItemDelegate(new QSqlRelationalDelegate(this));
mapper->addMapping(ui->myFirstComboBox, 1);
mapper->addMapping(ui->mySecondComboBox, 2);
mapper->addMapping(ui->codeEdit, 3);
mapper->addMapping(ui->dateEdit, 4);
//bla bla bla...
//bla bla bla...
mapper->setCurrentIndex(row);
QString filterValue = ui->codeEdit->text();
myproxy= new QSortFilterProxyModel(this);
myproxy->setSourceModel(myeditModel);
myproxy->setFilterCaseSensitivity(Qt::CaseInsensitive);
myproxy->setFilterRegExp(QRegExp(filterValue, Qt::CaseInsensitive, QRegExp::FixedString));
myproxy->setFilterKeyColumn(/*-1*/3);
ui->EditView->setModel(myproxy);
ui->EditView->resizeRowsToContents();
ui->EditView->resizeColumnsToContents();
ui->EditView->setSortingEnabled(true);
ui->EditView->setColumnHidden(0, true);
}
myEditDialog::~myEditDialog()
{
delete ui;
}
void myEditDialog::on_codeEdit_selictionChanged(const QString &arg1)
{
myproxy->setFilterFixedString(arg1);
}
To copy to clipboard, switch view to plain text mode
Bookmarks