summaryrefslogtreecommitdiffstats
path: root/src/sql/models/qsqltablemodel.cpp
diff options
context:
space:
mode:
authorMichael Goddard <michael.goddard@nokia.com>2010-11-02 02:14:03 (GMT)
committerMichael Goddard <michael.goddard@nokia.com>2011-02-04 05:41:01 (GMT)
commit9c61e9a40e774fe32b16c133a5cdd6b9d9d29d83 (patch)
tree081b136915ae1bf29c1567bd5bdca841099860d1 /src/sql/models/qsqltablemodel.cpp
parentaccc1acc8632e5b21114600b5bcb92cf74004097 (diff)
downloadQt-9c61e9a40e774fe32b16c133a5cdd6b9d9d29d83.zip
Qt-9c61e9a40e774fe32b16c133a5cdd6b9d9d29d83.tar.gz
Qt-9c61e9a40e774fe32b16c133a5cdd6b9d9d29d83.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
Diffstat (limited to 'src/sql/models/qsqltablemodel.cpp')
-rw-r--r--src/sql/models/qsqltablemodel.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/sql/models/qsqltablemodel.cpp b/src/sql/models/qsqltablemodel.cpp
index 3bb46cc..6f9c284 100644
--- a/src/sql/models/qsqltablemodel.cpp
+++ b/src/sql/models/qsqltablemodel.cpp
@@ -423,6 +423,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) {
@@ -450,7 +454,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);
}
/*!
@@ -1225,7 +1231,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();