From 33c212b7d25726b78c4bf630548a76feaab872f0 Mon Sep 17 00:00:00 2001 From: Mark Brand Date: Wed, 30 Jan 2013 00:39:53 +0100 Subject: QSqlTableModel::setData(): fix non-change detection Commit 10ff9de91bedf93852f13a58287afd8831644759 introduced the optimization of ignoring non-changes, but it overshot the mark. It neglected to consider that QVariant's equality operator does not compare the null flag. It also failed to consider that setData() has a useful side effect of setting the generated flag in a column of a pending INSERT. This is important when the application actually wants a NULL to be inserted into the column. Task-number: QTBUG-29217 Change-Id: I1368f7acc21eebfeb5a8d23746fc38f6f30fd395 Reviewed-by: Andy Shaw Reviewed-by: Mark Brand --- src/sql/models/qsqltablemodel.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/sql') diff --git a/src/sql/models/qsqltablemodel.cpp b/src/sql/models/qsqltablemodel.cpp index 32dd517a7a..a2a83e6a4b 100644 --- a/src/sql/models/qsqltablemodel.cpp +++ b/src/sql/models/qsqltablemodel.cpp @@ -587,7 +587,10 @@ bool QSqlTableModel::setData(const QModelIndex &index, const QVariant &value, in if (!(flags(index) & Qt::ItemIsEditable)) return false; - if (QSqlTableModel::data(index, role) == value) + const QVariant oldValue = QSqlTableModel::data(index, role); + if (value == oldValue + && value.isNull() == oldValue.isNull() + && d->cache.value(index.row()).op() != QSqlTableModelPrivate::Insert) return true; QSqlTableModelPrivate::ModifiedRow &row = d->cache[index.row()]; -- cgit v1.2.3