QSqlTableModel::indexInQuery(): fix for inserted rows
authorMark Brand <mabrand@mabrand.nl>
Mon, 13 Feb 2012 07:46:23 +0000 (08:46 +0100)
committerQt by Nokia <qt-info@nokia.com>
Wed, 15 Feb 2012 01:36:42 +0000 (02:36 +0100)
Should return invalid QModelIndex since inserted row does not map to
query.

Change-Id: Ib1d15cf4198a7063717fb3f3b594b2b1d8a54dfe
Reviewed-by: Yunqiao Yin <charles.yin@nokia.com>
src/sql/models/qsqltablemodel.cpp

index b21a965..932bbbf 100644 (file)
@@ -1143,6 +1143,9 @@ int QSqlTableModel::rowCount(const QModelIndex &parent) const
 QModelIndex QSqlTableModel::indexInQuery(const QModelIndex &item) const
 {
     Q_D(const QSqlTableModel);
+    if (d->cache.value(item.row()).op() == QSqlTableModelPrivate::Insert)
+        return QModelIndex();
+
     const int rowOffset = d->insertCount(item.row());
     return QSqlQueryModel::indexInQuery(createIndex(item.row() - rowOffset, item.column(), item.internalPointer()));
 }