From 76fa96b99e9ee79d0a2016fb28f17bc2dc58ab0a Mon Sep 17 00:00:00 2001 From: Mark Brand Date: Mon, 13 Feb 2012 09:26:21 +0100 Subject: [PATCH] QSqlRelationalTableModelPrivate: simplify field name translation It's not appropriate to use indexInQuery() here. First of all, the row might be an inserted row, and thus not be in the query. The intent was probably to get the column position in the query, but this is certainly not row dependent. Furthermore, if there are inserted or removed columns, these are managed within QSqlQueryModel. Change-Id: I89668655b263747a5b849136404112e911722b3d Reviewed-by: Yunqiao Yin --- src/sql/models/qsqlrelationaltablemodel.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/sql/models/qsqlrelationaltablemodel.cpp b/src/sql/models/qsqlrelationaltablemodel.cpp index 75bf3ebe43..8dd18ca1d0 100644 --- a/src/sql/models/qsqlrelationaltablemodel.cpp +++ b/src/sql/models/qsqlrelationaltablemodel.cpp @@ -268,7 +268,7 @@ public: void clearCache(); void revertCachedRow(int row); - void translateFieldNames(int row, QSqlRecord &values) const; + void translateFieldNames(QSqlRecord &values) const; QSqlRelationalTableModel::JoinMode joinMode; }; @@ -744,16 +744,13 @@ void QSqlRelationalTableModel::setTable(const QString &table) /*! \internal */ -void QSqlRelationalTableModelPrivate::translateFieldNames(int row, QSqlRecord &values) const +void QSqlRelationalTableModelPrivate::translateFieldNames(QSqlRecord &values) const { - Q_Q(const QSqlRelationalTableModel); - for (int i = 0; i < values.count(); ++i) { - int realCol = q->indexInQuery(q->createIndex(row, i)).column(); - if (realCol != -1 && relations.value(realCol).isValid()) { + if (relations.value(i).isValid()) { QVariant v = values.value(i); bool gen = values.isGenerated(i); - values.replace(i, baseRec.field(realCol)); + values.replace(i, baseRec.field(i)); values.setValue(i, v); values.setGenerated(i, gen); } @@ -768,7 +765,7 @@ bool QSqlRelationalTableModel::updateRowInTable(int row, const QSqlRecord &value Q_D(QSqlRelationalTableModel); QSqlRecord rec = values; - d->translateFieldNames(row, rec); + d->translateFieldNames(rec); return QSqlTableModel::updateRowInTable(row, rec); } @@ -781,7 +778,7 @@ bool QSqlRelationalTableModel::insertRowIntoTable(const QSqlRecord &values) Q_D(QSqlRelationalTableModel); QSqlRecord rec = values; - d->translateFieldNames(0, rec); + d->translateFieldNames(rec); return QSqlTableModel::insertRowIntoTable(rec); }