diff options
author | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2013-02-13 11:58:07 +0100 |
---|---|---|
committer | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2013-02-14 14:24:57 +0100 |
commit | e65cd6f3794e12e6bc5c2ee985eae8e70ff5f333 (patch) | |
tree | 8965835c375422d63b2ccfa927b31a56e64bda1d /src/sql/models/qsqltablemodel.cpp | |
parent | d1ee7189553e13337b198fe4ba66d79fb7a7f41d (diff) | |
parent | e95a758236cf2c68e33da4ddb62bff4fe8d9dd8b (diff) |
Merge remote-tracking branch 'origin/stable' into dev
Conflicts:
src/concurrent/doc/qtconcurrent.qdocconf
src/corelib/doc/qtcore.qdocconf
src/corelib/global/qglobal.h
src/dbus/doc/qtdbus.qdocconf
src/dbus/qdbusmessage.h
src/gui/doc/qtgui.qdocconf
src/gui/image/qimagereader.cpp
src/network/doc/qtnetwork.qdocconf
src/opengl/doc/qtopengl.qdocconf
src/opengl/qgl.h
src/plugins/platforms/windows/qwindowswindow.cpp
src/printsupport/doc/qtprintsupport.qdocconf
src/sql/doc/qtsql.qdocconf
src/testlib/doc/qttestlib.qdocconf
src/tools/qdoc/doc/config/qt-cpp-ignore.qdocconf
src/widgets/doc/qtwidgets.qdocconf
src/xml/doc/qtxml.qdocconf
Change-Id: Ie9a1fa2cc44bec22a0b942e817a1095ca3414629
Diffstat (limited to 'src/sql/models/qsqltablemodel.cpp')
-rw-r--r-- | src/sql/models/qsqltablemodel.cpp | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/sql/models/qsqltablemodel.cpp b/src/sql/models/qsqltablemodel.cpp index 32dd517a7a..2e395b0a59 100644 --- a/src/sql/models/qsqltablemodel.cpp +++ b/src/sql/models/qsqltablemodel.cpp @@ -355,6 +355,16 @@ void QSqlTableModel::setTable(const QString &tableName) if (d->rec.count() == 0) d->error = QSqlError(QLatin1String("Unable to find table ") + d->tableName, QString(), QSqlError::StatementError); + + // Remember the auto index column if there is one now. + // The record that will be obtained from the query after select lacks this feature. + d->autoColumn.clear(); + for (int c = 0; c < d->rec.count(); ++c) { + if (d->rec.field(c).isAutoValue()) { + d->autoColumn = d->rec.fieldName(c); + break; + } + } } /*! @@ -587,7 +597,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()]; @@ -772,6 +785,11 @@ bool QSqlTableModel::submitAll() } if (success) { + if (d->strategy != OnManualSubmit && mrow.op() == QSqlTableModelPrivate::Insert) { + int c = mrow.rec().indexOf(d->autoColumn); + if (c != -1 && !mrow.rec().isGenerated(c)) + mrow.setValue(c, d->editQuery.lastInsertId()); + } mrow.setSubmitted(); if (d->strategy != OnManualSubmit) success = selectRow(row); @@ -821,7 +839,8 @@ bool QSqlTableModel::submit() user canceled editing the current row. Reverts the changes if the model's strategy is set to - OnRowChange. Does nothing for the other edit strategies. + OnRowChange or OnFieldChange. Does nothing for the OnManualSubmit + strategy. Use revertAll() to revert all pending changes for the OnManualSubmit strategy or revertRow() to revert a specific row. @@ -831,7 +850,7 @@ bool QSqlTableModel::submit() void QSqlTableModel::revert() { Q_D(QSqlTableModel); - if (d->strategy == OnRowChange) + if (d->strategy == OnRowChange || d->strategy == OnFieldChange) revertAll(); } |