summaryrefslogtreecommitdiffstats
path: root/src/sql/models/qsqltablemodel.cpp
diff options
context:
space:
mode:
authorRohan McGovern <rohan.mcgovern@nokia.com>2011-05-15 23:09:31 (GMT)
committerRohan McGovern <rohan.mcgovern@nokia.com>2011-05-15 23:09:31 (GMT)
commit5aa1cbcdacd19b2e526e358eddac1b7d55a994b5 (patch)
tree4aba78405e3d98081662fcb934f673acd1b79d42 /src/sql/models/qsqltablemodel.cpp
parent8592bcc80b7ec245b485fa54f8bd41c4484e93e0 (diff)
parent7e4a9187bb11b794e45d95d2e9fae026d6b0d07d (diff)
downloadQt-5aa1cbcdacd19b2e526e358eddac1b7d55a994b5.zip
Qt-5aa1cbcdacd19b2e526e358eddac1b7d55a994b5.tar.gz
Qt-5aa1cbcdacd19b2e526e358eddac1b7d55a994b5.tar.bz2
Merge remote branch 'origin/4.8' into qa-review-master
Conflicts: tests/auto/qaccessibility/tst_qaccessibility.cpp tests/auto/qsslsocket/tst_qsslsocket.cpp
Diffstat (limited to 'src/sql/models/qsqltablemodel.cpp')
-rw-r--r--src/sql/models/qsqltablemodel.cpp64
1 files changed, 38 insertions, 26 deletions
diff --git a/src/sql/models/qsqltablemodel.cpp b/src/sql/models/qsqltablemodel.cpp
index bf7c0aa..99b516a 100644
--- a/src/sql/models/qsqltablemodel.cpp
+++ b/src/sql/models/qsqltablemodel.cpp
@@ -138,6 +138,7 @@ void QSqlTableModelPrivate::revertInsertedRow()
void QSqlTableModelPrivate::clearEditBuffer()
{
editBuffer = rec;
+ clearGenerated(editBuffer);
}
void QSqlTableModelPrivate::clearCache()
@@ -145,6 +146,18 @@ void QSqlTableModelPrivate::clearCache()
cache.clear();
}
+void QSqlTableModelPrivate::clearGenerated(QSqlRecord &rec)
+{
+ for (int i = rec.count() - 1; i >= 0; i--)
+ rec.setGenerated(i, false);
+}
+
+void QSqlTableModelPrivate::setGeneratedValue(QSqlRecord &rec, int c, QVariant v)
+{
+ rec.setValue(c, v);
+ rec.setGenerated(c, true);
+}
+
void QSqlTableModelPrivate::revertCachedRow(int row)
{
Q_Q(QSqlTableModel);
@@ -201,7 +214,7 @@ bool QSqlTableModelPrivate::exec(const QString &stmt, bool prepStatement,
}
int i;
for (i = 0; i < rec.count(); ++i) {
- if (rec.isGenerated(i) && rec.value(i).type() != QVariant::Invalid)
+ if (rec.isGenerated(i))
editQuery.addBindValue(rec.value(i));
}
for (i = 0; i < whereValues.count(); ++i) {
@@ -435,26 +448,22 @@ QVariant QSqlTableModel::data(const QModelIndex &index, int role) const
case OnFieldChange:
case OnRowChange:
if (index.row() == d->insertIndex) {
- QVariant val;
if (item.column() < 0 || item.column() >= d->rec.count())
- return val;
- val = d->editBuffer.value(index.column());
- if (val.type() == QVariant::Invalid)
- val = QVariant(d->rec.field(item.column()).type());
- return val;
+ return QVariant();
+ return d->editBuffer.value(index.column());
}
if (d->editIndex == item.row()) {
- QVariant var = d->editBuffer.value(item.column());
- if (var.isValid())
- return var;
+ if (d->editBuffer.isGenerated(item.column()))
+ return d->editBuffer.value(item.column());
+ }
+ break;
+ case OnManualSubmit:
+ if (d->cache.contains(index.row())) {
+ const QSqlTableModelPrivate::ModifiedRow row = d->cache.value(index.row());
+ if (row.rec.isGenerated(item.column()) || row.op == QSqlTableModelPrivate::Insert)
+ return row.rec.value(item.column());
}
break;
- case OnManualSubmit: {
- const QSqlTableModelPrivate::ModifiedRow row = d->cache.value(index.row());
- const QVariant var = row.rec.value(item.column());
- if (var.isValid() || row.op == QSqlTableModelPrivate::Insert)
- return var;
- break; }
}
// We need to handle row mapping here, but not column mapping
@@ -503,13 +512,13 @@ bool QSqlTableModel::isDirty(const QModelIndex &index) const
case OnFieldChange:
return false;
case OnRowChange:
- return index.row() == d->editIndex && d->editBuffer.value(index.column()).isValid();
+ return index.row() == d->editIndex && d->editBuffer.isGenerated(index.column());
case OnManualSubmit: {
const QSqlTableModelPrivate::ModifiedRow row = d->cache.value(index.row());
return row.op == QSqlTableModelPrivate::Insert
|| row.op == QSqlTableModelPrivate::Delete
|| (row.op == QSqlTableModelPrivate::Update
- && row.rec.value(index.column()).isValid());
+ && row.rec.isGenerated(index.column()));
}
}
return false;
@@ -538,11 +547,11 @@ bool QSqlTableModel::setData(const QModelIndex &index, const QVariant &value, in
switch (d->strategy) {
case OnFieldChange: {
if (index.row() == d->insertIndex) {
- d->editBuffer.setValue(index.column(), value);
+ QSqlTableModelPrivate::setGeneratedValue(d->editBuffer, index.column(), value);
return true;
}
d->clearEditBuffer();
- d->editBuffer.setValue(index.column(), value);
+ QSqlTableModelPrivate::setGeneratedValue(d->editBuffer, index.column(), value);
isOk = updateRowInTable(index.row(), d->editBuffer);
if (isOk)
select();
@@ -550,7 +559,7 @@ bool QSqlTableModel::setData(const QModelIndex &index, const QVariant &value, in
break; }
case OnRowChange:
if (index.row() == d->insertIndex) {
- d->editBuffer.setValue(index.column(), value);
+ QSqlTableModelPrivate::setGeneratedValue(d->editBuffer, index.column(), value);
return true;
}
if (d->editIndex != index.row()) {
@@ -558,7 +567,7 @@ bool QSqlTableModel::setData(const QModelIndex &index, const QVariant &value, in
submit();
d->clearEditBuffer();
}
- d->editBuffer.setValue(index.column(), value);
+ QSqlTableModelPrivate::setGeneratedValue(d->editBuffer, index.column(), value);
d->editIndex = index.row();
emit dataChanged(index, index);
break;
@@ -567,9 +576,10 @@ bool QSqlTableModel::setData(const QModelIndex &index, const QVariant &value, in
if (row.op == QSqlTableModelPrivate::None) {
row.op = QSqlTableModelPrivate::Update;
row.rec = d->rec;
+ QSqlTableModelPrivate::clearGenerated(row.rec);
row.primaryValues = d->primaryValues(indexInQuery(index).row());
}
- row.rec.setValue(index.column(), value);
+ QSqlTableModelPrivate::setGeneratedValue(row.rec, index.column(), value);
emit dataChanged(index, index);
break; }
}
@@ -1330,6 +1340,7 @@ bool QSqlTableModel::setRecord(int row, const QSqlRecord &record)
if (mrow.op == QSqlTableModelPrivate::None) {
mrow.op = QSqlTableModelPrivate::Update;
mrow.rec = d->rec;
+ QSqlTableModelPrivate::clearGenerated(mrow.rec);
mrow.primaryValues = d->primaryValues(indexInQuery(createIndex(row, 0)).row());
}
QString fieldName;
@@ -1338,10 +1349,11 @@ bool QSqlTableModel::setRecord(int row, const QSqlRecord &record)
if (d->db.driver()->isIdentifierEscaped(fieldName, QSqlDriver::FieldName))
fieldName = d->db.driver()->stripDelimiters(fieldName, QSqlDriver::FieldName);
int idx = mrow.rec.indexOf(fieldName);
- if (idx == -1)
+ if (idx == -1) {
isOk = false;
- else
- mrow.rec.setValue(idx, record.value(i));
+ } else {
+ QSqlTableModelPrivate::setGeneratedValue(mrow.rec, idx, record.value(i));
+ }
}
if (isOk)