52 #define QSQL_PREFETCH 255 217 return (!parent.
isValid() && !
d->atEnd);
238 return index.
isValid() ? 0 :
d->bottom.row() + 1;
246 return index.
isValid() ? 0 :
d->rec.count();
267 if (!
d->rec.isGenerated(item.
column()))
270 if (dItem.
row() >
d->bottom.row())
271 const_cast<QSqlQueryModelPrivate *>(
d)->prefetch(dItem.
row());
273 if (!
d->query.seek(dItem.
row())) {
274 d->error =
d->query.lastError();
278 return d->query.value(dItem.
column());
289 QVariant val =
d->headers.value(section).value(role);
299 return d->rec.fieldName(section);
333 bool columnsChanged = (newRec !=
d->rec);
337 if (
d->colOffsets.size() != newRec.
count() || columnsChanged)
338 d->initColOffsets(newRec.
count());
340 bool mustClearModel =
d->bottom.isValid();
341 if (mustClearModel) {
356 if (columnsChanged && hasNewData)
364 "cannot be used in a data model"),
371 if (hasQuerySize &&
d->query.size() > 0) {
372 newBottom =
createIndex(
d->query.size() - 1,
d->rec.count() - 1);
374 d->bottom =
createIndex(
d->query.size() - 1, columnsChanged ? 0 :
d->rec.count() - 1);
380 d->bottom = newBottom;
420 d->colOffsets.clear();
446 if (
d->headers.size() <= section)
447 d->headers.resize(
qMax(section + 1, 16));
448 d->headers[section][role] = value;
505 for (
int i = 0; i < rec.
count(); ++i)
546 if (count <= 0 || parent.
isValid() || column < 0 || column >
d->rec.count())
550 for (
int c = 0;
c < count; ++
c) {
554 d->rec.insert(column, field);
555 if (
d->colOffsets.size() <
d->rec.count()) {
556 int nVal =
d->colOffsets.isEmpty() ? 0 :
d->colOffsets[
d->colOffsets.size() - 1];
557 d->colOffsets.append(nVal);
558 Q_ASSERT(
d->colOffsets.size() >=
d->rec.count());
560 for (
int i = column + 1; i <
d->colOffsets.count(); ++i)
581 if (count <= 0 || parent.
isValid() || column < 0 || column >=
d->rec.count())
587 for (i = 0; i < count; ++i)
588 d->rec.remove(column);
589 for (i = column; i <
d->colOffsets.count(); ++i)
590 d->colOffsets[i] -= count;
612 || !
d->rec.isGenerated(item.
column()))
The QVariant class acts like a union for the most common Qt data types.
The QSqlError class provides SQL database error information.
QModelIndex indexInQuery(const QModelIndex &item) const
Returns the index of the value in the database result set for the given item in the model...
void * internalPointer() const
Returns a void * pointer used by the model to associate the index with the internal data structure...
const QSqlDriver * driver() const
Returns the database driver associated with the query.
QSqlError lastError() const
Returns information about the last error that occurred on the database.
#define QT_END_NAMESPACE
This macro expands to.
void beginInsertColumns(const QModelIndex &parent, int first, int last)
Begins a column insertion operation.
int rowCount(const QModelIndex &parent=QModelIndex()) const
If the database supports returning the size of a query (see QSqlDriver::hasFeature()), the number of rows of the current query is returned.
virtual bool hasFeature(DriverFeature f) const =0
Returns true if the driver supports feature feature; otherwise returns false.
void setReadOnly(bool readOnly)
Sets the read only flag of the field's value to readOnly.
QSqlRecord record() const
Returns a QSqlRecord containing the field information for the current query.
bool canFetchMore(const QModelIndex &parent=QModelIndex()) const
Returns true if it is possible to read more rows from the database.
The QSqlQuery class provides a means of executing and manipulating SQL statements.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Returns the index of the data in row and column with parent.
void beginRemoveColumns(const QModelIndex &parent, int first, int last)
Begins a column removal operation.
The QSqlDatabase class represents a connection to a database.
QModelIndex createIndex(int row, int column, void *data=0) const
Creates a model index for the given row and column with the internal pointer ptr. ...
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QSqlRecord class encapsulates a database record.
void endInsertRows()
Ends a row insertion operation.
The QString class provides a Unicode character string.
bool isActive() const
Returns true if the query is active.
QVariant data(const QModelIndex &item, int role=Qt::DisplayRole) const
Returns the value for the specified item and role.
The QObject class is the base class of all Qt objects.
virtual void queryChange()
This virtual function is called whenever the query changes.
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Returns the data for the given role and section in the header with the specified orientation.
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
QVarLengthArray< int, 56 > colOffsets
void setGenerated(bool gen)
Sets the generated state.
int columnCount(const QModelIndex &parent=QModelIndex()) const
Reimplemented Function
The QSqlQueryModel class provides a read-only data model for SQL result sets.
#define QT_BEGIN_NAMESPACE
This macro expands to.
QSqlQuery query() const
Returns the QSqlQuery associated with this model.
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::EditRole)
Sets the caption for a horizontal header for the specified role to value.
int row() const
Returns the row this model index refers to.
void initColOffsets(int size)
bool insertColumns(int column, int count, const QModelIndex &parent=QModelIndex())
Inserts count columns into the model at position column.
void endRemoveRows()
Ends a row removal operation.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
void setQuery(const QSqlQuery &query)
Resets the model and sets the data provider to be the given query.
int count() const
Returns the number of fields in the record.
QSqlError lastError() const
Returns error information about the last error (if any) that occurred with this query.
virtual void clear()
Clears the model and releases any acquired resource.
void headerDataChanged(Qt::Orientation orientation, int first, int last)
This signal is emitted whenever a header is changed.
void setLastError(const QSqlError &error)
Protected function which allows derived classes to set the value of the last error that occurred on t...
QObject * parent() const
Returns a pointer to the parent object.
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Returns the header data for the given role in the section of the header with the specified orientatio...
void beginRemoveRows(const QModelIndex &parent, int first, int last)
Begins a row removal operation.
The QModelIndex class is used to locate data in a data model.
QSqlRecord record() const
Returns an empty record containing information about the fields of the current query.
void endInsertColumns()
Ends a column insertion operation.
bool isForwardOnly() const
Returns true if you can only scroll forward through a result set; otherwise returns false...
bool isValid() const
Returns true if an error is set, otherwise false.
QSqlQueryModel(QObject *parent=0)
Creates an empty QSqlQueryModel with the given parent.
bool seek(int i, bool relative=false)
Retrieves the record at position index, if available, and positions the query on the retrieved record...
void setValue(int i, const QVariant &val)
Sets the value of the field at position index to val.
The QSqlField class manipulates the fields in SQL database tables and views.
virtual ~QSqlQueryModel()
Destroys the object and frees any allocated resources.
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
bool next()
Retrieves the next record in the result, if available, and positions the query on the retrieved recor...
void fetchMore(const QModelIndex &parent=QModelIndex())
Fetches more rows from a database.
bool removeColumns(int column, int count, const QModelIndex &parent=QModelIndex())
Removes count columns from the model starting from position column.
The QAbstractTableModel class provides an abstract model that can be subclassed to create table model...
void reset()
Resets the model to its original state in any attached views.
void beginInsertRows(const QModelIndex &parent, int first, int last)
Begins a row insertion operation.
int column() const
Returns the column this model index refers to.
void endRemoveColumns()
Ends a column removal operation.