part of my objective is to get as much of the Qt framework doing as much of the database interaction as I can, so I can code less and implement more
What I have so far is:
_photoSessionModel->setTable("PHOTO_SESSION");
connect(_photoSessionModel, SIGNAL(beforeUpdate(QSqlRecord&)), this, SLOT(on_photoSessionModel_beforeInsert(QSqlRecord&)));
connect(_photoSessionModel, SIGNAL(beforeUpdate(int,QSqlRecord&)), this, SLOT(on_photoSessionModel_beforeUpdate(int,QSqlRecord&)));
_photoSessionMapper->setModel(_photoSessionModel);
_photoSessionMapper->addMapping(ui.directoryImageComboBox, _photoSessionModel->fieldIndex("PHOTO_SESSION_IMAGE_ID"));
_photoSessionModel = new QSqlRelationalTableModel(this);
_photoSessionModel->setTable("PHOTO_SESSION");
_photoSessionModel->setEditStrategy(QSqlTableModel::OnRowChange);
connect(_photoSessionModel, SIGNAL(beforeUpdate(QSqlRecord&)), this, SLOT(on_photoSessionModel_beforeInsert(QSqlRecord&)));
connect(_photoSessionModel, SIGNAL(beforeUpdate(int,QSqlRecord&)), this, SLOT(on_photoSessionModel_beforeUpdate(int,QSqlRecord&)));
_photoSessionMapper = new QDataWidgetMapper(this);
_photoSessionMapper->setModel(_photoSessionModel);
_photoSessionMapper->setItemDelegate(new QSqlRelationalDelegate(this));
_photoSessionMapper->addMapping(ui.directoryImageComboBox, _photoSessionModel->fieldIndex("PHOTO_SESSION_IMAGE_ID"));
To copy to clipboard, switch view to plain text mode
The goal here is to add a QSqlRelation to the _photoSessionModel so that when the filter is changed on the model, the comboBox will do two things:
1: Change the list of images that show up in the combo box
2: Select the correct image, based on the id in the model.
What I do NOT want to have to do is update the model of the images, I am looking for Qt to do that for me. I am OK with creating the the image model, I am just looking for the Qt framework to do the updating when the _photoSessionModel.
The development I am doing is incremental right now, step one is getting this basic functionality working. Later I am going to want to come in and really fine tune how things are displayed, position, and what get highlighted, aka not the image itself, but just the name. So ideally I would like to create either a model or a delegate to display the images. I am not seeing anything on the QSqlRelation to allow me access to change the model. Can I simply use the default behavior of the QSqlRelation and then change the delegate on the comboBox to achieve what I am after?
Sam
the filter on the _photoSessionModel to the target session and have the model
Bookmarks