From: Mark Brand Date: Tue, 14 Feb 2012 21:26:43 +0000 (+0100) Subject: QSqlTableModel: unify code for cache-clearing before select X-Git-Tag: qt-v5.0.0-alpha1~711 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=52dab549868d41fbfb6f3f612c380fb750755aa3;p=profile%2Fivi%2Fqtbase.git QSqlTableModel: unify code for cache-clearing before select The code in submitAll() had the same goal as the code in select, so it has been unified. The new code in select() avoids sending lots of dataChanged() signals for rows that are going to be removed by QSqlQueryModel anyway. Change-Id: Ic22e038223720185e47ed0cc573147745ecc8fc9 Reviewed-by: Yunqiao Yin --- diff --git a/src/sql/models/qsqltablemodel.cpp b/src/sql/models/qsqltablemodel.cpp index b36a54b..571c28f 100644 --- a/src/sql/models/qsqltablemodel.cpp +++ b/src/sql/models/qsqltablemodel.cpp @@ -378,13 +378,19 @@ bool QSqlTableModel::select() if (query.isEmpty()) return false; - // clear the submitted flags so revertAll can do its job - for (QSqlTableModelPrivate::CacheMap::Iterator it = d->cache.begin(); - it != d->cache.constEnd(); - ++it) - it.value().setSubmitted(false); + QSqlTableModelPrivate::CacheMap::Iterator it = d->cache.end(); + while (it != d->cache.constBegin()) { + --it; + // rows must be accounted for + if (it.value().op() == QSqlTableModelPrivate::Insert) { + beginRemoveRows(QModelIndex(), it.key(), it.key()); + it = d->cache.erase(it); + endRemoveRows(); + } else { + it = d->cache.erase(it); + } + } - revertAll(); QSqlQuery qu(query, d->db); setQuery(qu); @@ -681,19 +687,6 @@ bool QSqlTableModel::submitAll() it.value().setSubmitted(true); } - // all changes have been committed - - // clean up inserted rows - QSqlTableModelPrivate::CacheMap::Iterator it = d->cache.end(); - while (it != d->cache.constBegin()) { - --it; - if (it.value().op() == QSqlTableModelPrivate::Insert) { - beginRemoveRows(QModelIndex(), it.key(), it.key()); - it = d->cache.erase(it); - endRemoveRows(); - } - } - d->clearCache(); return select(); }