PDA

View Full Version : QSqlTableModel and OnManualSubmit appears buggy if rows are removed



Al_
25th January 2010, 18:37
Hi

Related to a topic discussed a few months ago (http://www.qtcentre.org/threads/23932-QSqlTableModel-and-QTableView-critics?highlight=OnManualSubmit), I find QSqlTableModel behaves unexpected, not to say buggy, if used with OnManualSubmit. This notably affects removed rows.
Removed rows are highlighted with '!' in views, but are still counted by QSqlTableModel::rowCount(). Here the implementation from qsqltablemodel.cpp
int QSqlTableModel::rowCount(const QModelIndex &parent) const
{
Q_D(const QSqlTableModel);

if (parent.isValid())
return 0;

int rc = QSqlQueryModel::rowCount();
if (d->strategy == OnManualSubmit) {
for (QSqlTableModelPrivate::CacheMap::ConstIterator it = d->cache.constBegin();
it != d->cache.constEnd(); ++it) {
if (it.value().op == QSqlTableModelPrivate::Insert)
++rc;
}
} else if (d->insertIndex >= 0) {
++rc;
}
return rc;
}Line 12 checks for newly, not yet commited inserts and line 13 increments the row count accordingly. IMO, the same should be done for removed, but not yet commited rows. Somthing like the following statements is missing:

if (it.value().op == QSqlTableModelPrivate::Delete)
--rc;Similarly, removed rows should no longer be visible in views. This has been reported to the Qt bug tracker as suggestion (http://bugreports.qt.nokia.com/browse/QTBUG-492); why is this not considered a plain and simple bug?

Does anybody have awrapper that solves these deficiencies of QSqlTableModel?

Regards

Al_

cyrfer
25th January 2010, 19:19
I just want to say that I too have not been successful when trying to delete selected rows.

Al_
25th January 2010, 20:56
Actually, it works to delete rows from code, but the deleted rows still remain visible and the row count of the model does not change. The row is removed from the model only after submitAll() and then the row count is finally also reflecting the correct new count.

As you are also affected by this behaviour, I suggest you have a look at http://bugreports.qt.nokia.com/browse/QTBUG-492; you have also the option to vote to have this issue resolved.

If QSqlTableModel::removeRows (or QAbstractItemModel::removeRow) does not work at all for you, then you have a different issue; in that case feel free to post code to scrutinze.

Cheers

Al_