From: Mark Brand Date: Wed, 11 Jul 2012 14:29:53 +0000 (+0200) Subject: QSqlTM: add reimplemented record() method X-Git-Tag: v5.0.0-beta1~753 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fbf010a26617b3986e9a76bd9c004403aebfcdc2;p=profile%2Fivi%2Fqtbase.git QSqlTM: add reimplemented record() method QSqlQueryModel::record(row) populates the record it returns with values from virtual data(), so the values themselves can be supplied by QSqlTableModel. However, it is also desirable to be able to interrogate QSqlTableModel for the actual current record in its cache, including properties such as the generated flag. Change-Id: I733901913b7d237d5762448e953a99b5bd83fc7f Reviewed-by: Michael Goddard --- diff --git a/src/sql/models/qsqltablemodel.cpp b/src/sql/models/qsqltablemodel.cpp index 0416656..4f3db2b 100644 --- a/src/sql/models/qsqltablemodel.cpp +++ b/src/sql/models/qsqltablemodel.cpp @@ -538,7 +538,7 @@ bool QSqlTableModel::setData(const QModelIndex &index, const QVariant &value, in if (row.op() == QSqlTableModelPrivate::None) row = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Update, - record(index.row())); + QSqlQueryModel::record(index.row())); row.setValue(index.column(), value); emit dataChanged(index, index); @@ -1044,7 +1044,8 @@ bool QSqlTableModel::removeRows(int row, int count, const QModelIndex &parent) revertRow(idx); } else { if (mrow.op() == QSqlTableModelPrivate::None) - mrow = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Delete, record(idx)); + mrow = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Delete, + QSqlQueryModel::record(idx)); else mrow.setOp(QSqlTableModelPrivate::Delete); if (d->strategy == OnManualSubmit) @@ -1250,6 +1251,34 @@ Qt::ItemFlags QSqlTableModel::flags(const QModelIndex &index) const return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable; } +QSqlRecord QSqlTableModel::record() const +{ + return QSqlQueryModel::record(); +} + +/*! +\reimp +\since 5.0 + Returns the record at \a row in the model. + + If \a row is the index of a valid row, the record + will be populated with values from that row. + + If the model is not initialized, an empty record will be + returned. + + \sa QSqlRecord::isEmpty() +*/ +QSqlRecord QSqlTableModel::record(int row) const +{ + Q_D(const QSqlTableModel); + + if (d->cache.contains(row)) + return d->cache.value(row).rec(); + + return QSqlQueryModel::record(row); +} + /*! Applies \a values to the \a row in the model. The source and target fields are mapped by field name, not by position in @@ -1301,7 +1330,7 @@ bool QSqlTableModel::setRecord(int row, const QSqlRecord &values) QSqlTableModelPrivate::ModifiedRow &mrow = d->cache[row]; if (mrow.op() == QSqlTableModelPrivate::None) mrow = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Update, - record(row)); + QSqlQueryModel::record(row)); Map::const_iterator i = map.constBegin(); const Map::const_iterator e = map.constEnd(); diff --git a/src/sql/models/qsqltablemodel.h b/src/sql/models/qsqltablemodel.h index 62e0986..0cdab4b 100644 --- a/src/sql/models/qsqltablemodel.h +++ b/src/sql/models/qsqltablemodel.h @@ -74,6 +74,8 @@ public: Qt::ItemFlags flags(const QModelIndex &index) const; + QSqlRecord record() const; + QSqlRecord record(int row) const; QVariant data(const QModelIndex &idx, int role = Qt::DisplayRole) const; bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);