dyngoman
17th September 2012, 09:44
Good day to all,
I know this issue has been posted before but i could not find a suitable answer.
The problem is this :
I have a QDataWidgetMapper with the model set to a QSortFilterProxyModel that filters a QSqlRelationalTableModel.
model= new QSqlRelationalTableModel(this);
filter= new QSortFilterProxyModel(this);
filter->setSourceModel(model);
model->setTable("patients");
model->setRelation(3,QSqlRelation("doctors","doctor_id","doctor_name"));
model->select();
the data stored in the model comes from a" medical patients " tabel in witch the a field doctor_id is linked to primary key in doctors table like this
patients table :
================================================== =======
name [text] |condition [text] | treatment [text] |doctor_id
================================================== =======
doctors table:
==============================
[I]doctor_id | [I]doctor_name [text]
==============================
It's pretty straight forward right.
I filter the model by field name to make make the user's selection easier
Next I apply a mapper:
mapper = new QDataWidgetMapper(this);
mapper->setModel(filter);
mapper->setItemDelegate(new QSqlRelationalDelegate(this));
I mapped all other field to text edit widgets but I needed a combo box to select a doctor_name
QSqlTableModel* doctors= model->relationModel(model->fieldIndex("doctor_id "));
comboBox->setModel(tabelMedici);
comboBox->setModelColumn(tabelMedici->fieldIndex("doctor_name"));//populates the combo box with the names
mapper->addMapping(comboBox,model->fieldIndex("doctor_id "));
Finaly i need to navigate the model in a tableViewer
tableView->setModel(filter);
connect(tableView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)) ,
mapper, SLOT(setCurrentModelIndex(QModelIndex)));
when i do a selection in tableView all the text widgets change values in accordance except comboBox witch doesn't change anything.
The combo box gets populated but is doesn't automatically change selection to the relevant field value.
What am I missing here?
Any suggestions?
I know this issue has been posted before but i could not find a suitable answer.
The problem is this :
I have a QDataWidgetMapper with the model set to a QSortFilterProxyModel that filters a QSqlRelationalTableModel.
model= new QSqlRelationalTableModel(this);
filter= new QSortFilterProxyModel(this);
filter->setSourceModel(model);
model->setTable("patients");
model->setRelation(3,QSqlRelation("doctors","doctor_id","doctor_name"));
model->select();
the data stored in the model comes from a" medical patients " tabel in witch the a field doctor_id is linked to primary key in doctors table like this
patients table :
================================================== =======
name [text] |condition [text] | treatment [text] |doctor_id
================================================== =======
doctors table:
==============================
[I]doctor_id | [I]doctor_name [text]
==============================
It's pretty straight forward right.
I filter the model by field name to make make the user's selection easier
Next I apply a mapper:
mapper = new QDataWidgetMapper(this);
mapper->setModel(filter);
mapper->setItemDelegate(new QSqlRelationalDelegate(this));
I mapped all other field to text edit widgets but I needed a combo box to select a doctor_name
QSqlTableModel* doctors= model->relationModel(model->fieldIndex("doctor_id "));
comboBox->setModel(tabelMedici);
comboBox->setModelColumn(tabelMedici->fieldIndex("doctor_name"));//populates the combo box with the names
mapper->addMapping(comboBox,model->fieldIndex("doctor_id "));
Finaly i need to navigate the model in a tableViewer
tableView->setModel(filter);
connect(tableView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)) ,
mapper, SLOT(setCurrentModelIndex(QModelIndex)));
when i do a selection in tableView all the text widgets change values in accordance except comboBox witch doesn't change anything.
The combo box gets populated but is doesn't automatically change selection to the relevant field value.
What am I missing here?
Any suggestions?