merge private and public QSqlTableModel::setRecord()
Change-Id: I409bd32f85224db64363688d63fc372d1beaa0d3 Reviewed-by: Yunqiao Yin <charles.yin@nokia.com>
This commit is contained in:
parent
48c68b0546
commit
ccaa6734f1
@ -66,36 +66,6 @@ QSqlRecord QSqlTableModelPrivate::record(const QVector<QVariant> &values) const
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! \internal
|
|
||||||
Set a record for OnFieldChange and OnRowChange.
|
|
||||||
*/
|
|
||||||
bool QSqlTableModelPrivate::setRecord(int row, const QSqlRecord &record)
|
|
||||||
{
|
|
||||||
Q_Q(QSqlTableModel);
|
|
||||||
bool isOk = true;
|
|
||||||
|
|
||||||
QSqlTableModel::EditStrategy oldStrategy = strategy;
|
|
||||||
|
|
||||||
// FieldChange strategy makes no sense when setting an entire row
|
|
||||||
if (strategy == QSqlTableModel::OnFieldChange)
|
|
||||||
strategy = QSqlTableModel::OnRowChange;
|
|
||||||
for (int i = 0; i < record.count(); ++i) {
|
|
||||||
int idx = nameToIndex(record.fieldName(i));
|
|
||||||
if (idx == -1)
|
|
||||||
continue;
|
|
||||||
QModelIndex cIndex = q->createIndex(row, idx);
|
|
||||||
QVariant value = record.value(i);
|
|
||||||
QVariant oldValue = q->data(cIndex);
|
|
||||||
if (oldValue.isNull() || oldValue != value)
|
|
||||||
isOk &= q->setData(cIndex, value, Qt::EditRole);
|
|
||||||
}
|
|
||||||
if (isOk && oldStrategy == QSqlTableModel::OnFieldChange)
|
|
||||||
q->submitAll();
|
|
||||||
strategy = oldStrategy;
|
|
||||||
|
|
||||||
return isOk;
|
|
||||||
}
|
|
||||||
|
|
||||||
int QSqlTableModelPrivate::nameToIndex(const QString &name) const
|
int QSqlTableModelPrivate::nameToIndex(const QString &name) const
|
||||||
{
|
{
|
||||||
QString fieldname = name;
|
QString fieldname = name;
|
||||||
@ -1236,8 +1206,28 @@ bool QSqlTableModel::setRecord(int row, const QSqlRecord &record)
|
|||||||
bool isOk = true;
|
bool isOk = true;
|
||||||
switch (d->strategy) {
|
switch (d->strategy) {
|
||||||
case OnFieldChange:
|
case OnFieldChange:
|
||||||
case OnRowChange:
|
case OnRowChange: {
|
||||||
return d->setRecord(row, record);
|
EditStrategy oldStrategy = d->strategy;
|
||||||
|
|
||||||
|
// FieldChange strategy makes no sense when setting an entire row
|
||||||
|
if (d->strategy == OnFieldChange)
|
||||||
|
d->strategy = OnRowChange;
|
||||||
|
for (int i = 0; i < record.count(); ++i) {
|
||||||
|
int idx = d->nameToIndex(record.fieldName(i));
|
||||||
|
if (idx == -1)
|
||||||
|
continue;
|
||||||
|
QModelIndex cIndex = createIndex(row, idx);
|
||||||
|
QVariant value = record.value(i);
|
||||||
|
QVariant oldValue = data(cIndex);
|
||||||
|
if (oldValue.isNull() || oldValue != value)
|
||||||
|
isOk &= setData(cIndex, value, Qt::EditRole);
|
||||||
|
}
|
||||||
|
if (isOk && oldStrategy == OnFieldChange)
|
||||||
|
submitAll();
|
||||||
|
d->strategy = oldStrategy;
|
||||||
|
|
||||||
|
return isOk;
|
||||||
|
}
|
||||||
case OnManualSubmit: {
|
case OnManualSubmit: {
|
||||||
QSqlTableModelPrivate::ModifiedRow &mrow = d->cache[row];
|
QSqlTableModelPrivate::ModifiedRow &mrow = d->cache[row];
|
||||||
if (mrow.op == QSqlTableModelPrivate::None)
|
if (mrow.op == QSqlTableModelPrivate::None)
|
||||||
|
@ -76,7 +76,6 @@ public:
|
|||||||
bool exec(const QString &stmt, bool prepStatement,
|
bool exec(const QString &stmt, bool prepStatement,
|
||||||
const QSqlRecord &rec, const QSqlRecord &whereValues);
|
const QSqlRecord &rec, const QSqlRecord &whereValues);
|
||||||
virtual void revertCachedRow(int row);
|
virtual void revertCachedRow(int row);
|
||||||
bool setRecord(int row, const QSqlRecord &record);
|
|
||||||
virtual int nameToIndex(const QString &name) const;
|
virtual int nameToIndex(const QString &name) const;
|
||||||
void initRecordAndPrimaryIndex();
|
void initRecordAndPrimaryIndex();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user