Hello.
I am trying to get a new row inserted into a QSqlTableModel from a proxy model.
I am aware of the map{To,From}Source methods, but I am not having much luck. Probably because I don’t get the logic behind this.
Right now I am trying this:
QModelIndex index_this;
QModelIndex index_source;
// get row count from the source model
int row = myBudget->models.cases_and_accesories->sourceModel()->rowCount();
// this, unfortunately, does nothing in the proxy model, which is what I'd like
myBudget->models.cases_and_accesories->sourceModel()->insertRow(row);
index_source = myBudget->models.cases_and_accesories->sourceModel()->index(row, 4);
index_this = myBudget->models.cases_and_accesories->mapFromSource(index_source);
ui->tableView_cascosYAccesorios->setCurrentIndex(index_this);
qDebug() << Q_FUNC_INFO << QString("index_this: %1, %2; index_source: %3,%4")
.arg(index_this.row()).arg(index_this.column())
.arg(index_source.row()).arg(index_source.column());
ui->tableView_cascosYAccesorios->edit(index_this);
qDebug() reports that index_source has sane and adequate values, but index_this is -1,-1, so, unsurprisingly, I can’t edit anything in the proxy model (there’s no new row either, so no surprise there).
I am sure there must be something simple I am missing…
Can anyone help me on this one? I have looked at the examples, the addressbook particularly, and they seem to pick the row from the source model, just as I do. But surely there’s some other bit that I am not getting.
Thank you for any help.
↧