diff options
author | Michael Goddard <michael.goddard@nokia.com> | 2010-11-02 02:14:03 (GMT) |
---|---|---|
committer | Jason McDonald <jason.mcdonald@nokia.com> | 2011-02-09 07:12:39 (GMT) |
commit | a7b953fb6f246f3d61723872ac97a1721fece128 (patch) | |
tree | cdc105b9c81716caf31691be386a34b4a2cf72f3 /src/sql/models/qsqltablemodel.cpp | |
parent | e8eea4ed6a09a4adbf3850a6943b50b9817122f8 (diff) | |
download | Qt-a7b953fb6f246f3d61723872ac97a1721fece128.zip Qt-a7b953fb6f246f3d61723872ac97a1721fece128.tar.gz Qt-a7b953fb6f246f3d61723872ac97a1721fece128.tar.bz2 |
QSqlTableModel/QSqlQueryModel and insertColumns problem.
After inserting a column, fetching data through QSqlTableModel was
off by one or more, since it passed the indexInQuery through to
QSQM. Also, the headerData would sometimes return a blank string
for an inserted column, and sometimes the column number.
The autotests have been beefed up a little to check insertRows and
insertColumns play nicely.
Change-Id: I7399d4c4d94f958884b67ab9b39b5cf2485d8416
Task-number: QTBUG-12626
Reviewed-by: Charles Yin
(cherry picked from commit 9c61e9a40e774fe32b16c133a5cdd6b9d9d29d83)
Diffstat (limited to 'src/sql/models/qsqltablemodel.cpp')
-rw-r--r-- | src/sql/models/qsqltablemodel.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/sql/models/qsqltablemodel.cpp b/src/sql/models/qsqltablemodel.cpp index ca491c4..4df1d63 100644 --- a/src/sql/models/qsqltablemodel.cpp +++ b/src/sql/models/qsqltablemodel.cpp @@ -425,6 +425,10 @@ QVariant QSqlTableModel::data(const QModelIndex &index, int role) const if (!index.isValid() || (role != Qt::DisplayRole && role != Qt::EditRole)) return QVariant(); + // Problem.. we need to use QSQM::indexInQuery to handle inserted columns + // but inserted rows we need to handle + // and indexInQuery is not virtual (grrr) so any values we pass to QSQM need + // to handle the insertedRows QModelIndex item = indexInQuery(index); switch (d->strategy) { @@ -452,7 +456,9 @@ QVariant QSqlTableModel::data(const QModelIndex &index, int role) const return var; break; } } - return QSqlQueryModel::data(item, role); + + // We need to handle row mapping here, but not column mapping + return QSqlQueryModel::data(index.sibling(item.row(), index.column()), role); } /*! @@ -1230,7 +1236,7 @@ int QSqlTableModel::rowCount(const QModelIndex &parent) const QModelIndex QSqlTableModel::indexInQuery(const QModelIndex &item) const { Q_D(const QSqlTableModel); - const QModelIndex it = QSqlQueryModel::indexInQuery(item); + const QModelIndex it = QSqlQueryModel::indexInQuery(item); // this adjusts columns only if (d->strategy == OnManualSubmit) { int rowOffset = 0; QSqlTableModelPrivate::CacheMap::ConstIterator i = d->cache.constBegin(); |