summaryrefslogtreecommitdiffstats
path: root/src/sql
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
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')
-rw-r--r--src/sql/models/qsqlquerymodel.cpp6
-rw-r--r--src/sql/models/qsqltablemodel.cpp10
2 files changed, 13 insertions, 3 deletions
diff --git a/src/sql/models/qsqlquerymodel.cpp b/src/sql/models/qsqlquerymodel.cpp
index 8730192..9800e67 100644
--- a/src/sql/models/qsqlquerymodel.cpp
+++ b/src/sql/models/qsqlquerymodel.cpp
@@ -279,7 +279,11 @@ QVariant QSqlQueryModel::headerData(int section, Qt::Orientation orientation, in
val = d->headers.value(section).value(Qt::EditRole);
if (val.isValid())
return val;
- if (role == Qt::DisplayRole && d->rec.count() > section)
+
+ // See if it's an inserted column (iiq.column() != -1)
+ QModelIndex dItem = indexInQuery(createIndex(0, section));
+
+ if (role == Qt::DisplayRole && d->rec.count() > section && dItem.column() != -1)
return d->rec.fieldName(section);
}
return QAbstractItemModel::headerData(section, orientation, role);
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();