15#define QSQL_PREFETCH 255
25 const int oldBottomRow =
qMax(
bottom.row(), 0);
36 newBottom =
q->createIndex(
i,
bottom.column());
39 newBottom =
q->createIndex(-1,
bottom.column());
43 if (newBottom.row() >= 0 && newBottom.row() >
bottom.row()) {
174 return (!
parent.isValid() && !
d->atEnd);
196 return QHash<int, QByteArray> {
206 if (!
d->nestedResetLevel)
215 if (!
d->nestedResetLevel)
224 if (!
d->nestedResetLevel)
233 if (!
d->nestedResetLevel)
242 if (!
d->nestedResetLevel)
251 if (!
d->nestedResetLevel)
260 if (!
d->nestedResetLevel)
269 if (!
d->nestedResetLevel)
278 if (!
d->nestedResetLevel)
280 ++
d->nestedResetLevel;
288 --
d->nestedResetLevel;
289 if (!
d->nestedResetLevel)
307 return index.isValid() ? 0 :
d->bottom.row() + 1;
315 return index.isValid() ? 0 :
d->rec.count();
336 if (!
d->rec.isGenerated(
item.column()))
339 if (dItem.row() >
d->bottom.row())
342 if (!
d->query.seek(dItem.row())) {
343 d->
error =
d->query.lastError();
347 return d->query.value(dItem.column());
363 if (role ==
Qt::DisplayRole &&
d->rec.count() > section &&
d->columnInQuery(section) != -1)
364 return d->rec.fieldName(section);
382#if QT_DEPRECATED_SINCE(6, 2)
414 bool columnsChanged = (newRec !=
d->rec);
416 if (
d->colOffsets.size() != newRec.count() || columnsChanged)
417 d->initColOffsets(newRec.count());
421 d->query = std::move(
query);
425 if (
d->query.isForwardOnly()) {
426 d->error =
QSqlError(
"Forward-only queries cannot be used in a data model"_L1,
432 if (!
d->query.isActive()) {
433 d->error =
d->query.lastError();
483 d->colOffsets.clear();
510 if (
d->headers.size() <= section)
511 d->headers.resize(
qMax(section + 1, 16));
512 d->headers[section][role] =
value;
569 for (
int i = 0;
i < rec.
count(); ++
i)
607 if (
count <= 0 ||
parent.isValid() || column < 0 || column >
d->rec.count())
616 if (
d->colOffsets.size() <
d->rec.count()) {
617 int nVal =
d->colOffsets.isEmpty() ? 0 :
d->colOffsets[
d->colOffsets.size() - 1];
618 d->colOffsets.append(nVal);
619 Q_ASSERT(
d->colOffsets.size() >=
d->rec.count());
621 for (
int i =
column + 1;
i <
d->colOffsets.size(); ++
i)
642 if (
count <= 0 ||
parent.isValid() || column < 0 || column >=
d->rec.count())
650 for (
i =
column;
i <
d->colOffsets.size(); ++
i)
672 int modelColumn =
d->columnInQuery(
item.column());
680#include "moc_qsqlquerymodel.cpp"
void endResetModel()
Completes a model reset operation.
virtual Q_INVOKABLE 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.
void endRemoveRows()
Ends a row removal operation.
void beginRemoveColumns(const QModelIndex &parent, int first, int last)
Begins a column removal operation.
void headerDataChanged(Qt::Orientation orientation, int first, int last)
This signal is emitted whenever a header is changed.
void beginInsertColumns(const QModelIndex &parent, int first, int last)
Begins a column insertion operation.
void endInsertRows()
Ends a row insertion operation.
void beginResetModel()
Begins a model reset operation.
void endRemoveColumns()
Ends a column removal operation.
QModelIndex createIndex(int row, int column, const void *data=nullptr) const
Creates a model index for the given row and column with the internal pointer ptr.
void endInsertColumns()
Ends a column insertion operation.
void beginRemoveRows(const QModelIndex &parent, int first, int last)
Begins a row removal operation.
void beginInsertRows(const QModelIndex &parent, int first, int last)
Begins a row insertion operation.
QObject * parent() const
Returns a pointer to the parent object.
constexpr int row() const noexcept
Returns the row this model index refers to.
The QSqlDatabase class handles a connection to a database.
The QSqlError class provides SQL database error information.
The QSqlField class manipulates the fields in SQL database tables and views.
void setReadOnly(bool readOnly)
Sets \l readOnly to readOnly.
void setGenerated(bool gen)
Sets \l generated to gen.
QVarLengthArray< int, 56 > colOffsets
void initColOffsets(int size)
int columnInQuery(int modelColumn) const
The QSqlQueryModel class provides a read-only data model for SQL result sets.
void beginInsertRows(const QModelIndex &parent, int first, int last)
virtual QModelIndex indexInQuery(const QModelIndex &item) const
Returns the index of the value in the database result set for the given item in the model.
QVariant data(const QModelIndex &item, int role=Qt::DisplayRole) const override
Returns the value for the specified item and role.
QSqlQueryModel(QObject *parent=nullptr)
Creates an empty QSqlQueryModel with the given parent.
void beginRemoveRows(const QModelIndex &parent, int first, int last)
int rowCount(const QModelIndex &parent=QModelIndex()) const override
If the database supports returning the size of a query (see QSqlDriver::hasFeature()),...
const QSqlQuery & query(QT6_DECL_NEW_OVERLOAD) const
Returns a reference to the const QSqlQuery object associated with this model.
virtual void queryChange()
This virtual function is called whenever the query changes.
void setLastError(const QSqlError &error)
Protected function which allows derived classes to set the value of the last error that occurred on t...
bool canFetchMore(const QModelIndex &parent=QModelIndex()) const override
Returns true if it is possible to read more rows from the database.
void setQuery(QSqlQuery &&query)
Resets the model and sets the data provider to be the given query.
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Returns the header data for the given role in the section of the header with the specified orientatio...
virtual ~QSqlQueryModel()
Destroys the object and frees any allocated resources.
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::EditRole) override
Sets the caption for a horizontal header for the specified role to value.
void beginRemoveColumns(const QModelIndex &parent, int first, int last)
QHash< int, QByteArray > roleNames() const override
void fetchMore(const QModelIndex &parent=QModelIndex()) override
Fetches more rows from a database.
void beginInsertColumns(const QModelIndex &parent, int first, int last)
QSqlError lastError() const
Returns information about the last error that occurred on the database.
int columnCount(const QModelIndex &parent=QModelIndex()) const override
\reimp
QSqlRecord record() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
virtual void clear()
Clears the model and releases any acquired resource.
bool insertColumns(int column, int count, const QModelIndex &parent=QModelIndex()) override
Inserts count columns into the model at position column.
bool removeColumns(int column, int count, const QModelIndex &parent=QModelIndex()) override
Removes count columns from the model starting from position column.
The QSqlQuery class provides a means of executing and manipulating SQL statements.
The QSqlRecord class encapsulates a database record.
int count() const
Returns the number of fields in the record.
void setValue(int i, const QVariant &val)
Sets the value of the field at position index to val.
bool isGenerated(int i) const
Returns true if the record has a field at position index and this field is to be generated (the defau...
\macro QT_RESTRICTED_CAST_FROM_ASCII
constexpr size_type size() const noexcept
void resize(qsizetype sz)
Combined button and popup list for selecting options.
static jboolean copy(JNIEnv *, jobject)
#define QByteArrayLiteral(str)
#define QT_IGNORE_DEPRECATIONS(statement)
DBusConnection const char DBusError * error
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
constexpr const T & qMax(const T &a, const T &b)
GLsizei const GLfloat * v
[13]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLenum GLsizei void GLsizei void * column
GLdouble GLdouble GLdouble GLdouble q
GLenum GLenum GLsizei void * row
#define QT6_IMPL_NEW_OVERLOAD