35 for (
int i = 0;
i <
r.count() &&
i <
values.size(); ++
i)
58 for ( ;
i !=
e && (maxRow < 0 ||
i.key() <= maxRow); ++
i)
59 if (
i.value().insert())
96 Q_ASSERT_X(
false,
"QSqlTableModelPrivate::revertCachedRow()",
"Invalid entry in cache map");
100 if (!
r.submitted()) {
102 emit q->dataChanged(
q->createIndex(
row, 0),
103 q->createIndex(
row,
q->columnCount() - 1));
113 int oldKey =
it.key();
150 for (
i = 0;
i < whereValues.
count(); ++
i)
299 d->initRecordAndPrimaryIndex();
301 if (
d->rec.count() == 0)
307 d->autoColumn.clear();
308 for (
int c = 0;
c <
d->rec.count(); ++
c) {
309 if (
d->rec.field(
c).isAutoValue()) {
310 d->autoColumn =
d->rec.fieldName(
c);
347 if (!
d->query.isActive() ||
lastError().isValid()) {
349 d->initRecordAndPrimaryIndex();
375 const int table_sort_col =
d->sortColumn;
377 const QString table_filter =
d->filter;
384 d->filter.remove(0, wh.
size());
388 if (!
d->filter.isEmpty())
391 d->sortColumn = table_sort_col;
392 d->filter = table_filter;
402 q.setForwardOnly(
true);
407 newValues =
q.record();
410 bool needsAddingToCache = !exists ||
d->cache.contains(
row);
412 if (!needsAddingToCache) {
414 needsAddingToCache = curValues.
count() != newValues.
count();
415 if (!needsAddingToCache) {
418 for (
int f = curValues.
count() - 1;
f >= 0; --
f) {
420 needsAddingToCache =
true;
427 if (needsAddingToCache) {
428 d->cache[
row].refresh(exists, newValues);
445 const auto it =
d->cache.constFind(
index.row());
447 return it->rec().value(
index.column());
480 for (;
i !=
e; ++
i) {
481 if (!
i.value().submitted())
497 if (!
index.isValid())
500 const auto it =
d->cache.constFind(
index.row());
501 if (
it ==
d->cache.constEnd())
510 &&
row.rec().isGenerated(
index.column()));
542 if (
d->busyInsertingRows)
555 if (
value == oldValue
610 whereValues, prepStatement);
617 return d->exec(
SqlTm::concat(stmt, where), prepStatement, rec, whereValues);
649 return d->exec(stmt, prepStatement, rec,
QSqlRecord() );
709 const auto cachedKeys =
d->cache.keys();
710 for (
int row : cachedKeys) {
712 QSqlTableModelPrivate::CacheMap::iterator
it =
d->cache.find(
row);
713 if (
it ==
d->cache.end())
731 Q_ASSERT_X(
false,
"QSqlTableModel::submitAll()",
"Invalid cache operation");
739 mrow.
setValue(
c,
d->editQuery.lastInsertId());
834 d->strategy = strategy;
858 for (
int i = rows.
size() - 1;
i >= 0; --
i)
873 d->revertCachedRow(
row);
885 return d->primaryIndex;
900 d->primaryIndex =
key;
968 return d->rec.indexOf(fieldName);
981 if (
d->tableName.isEmpty()) {
985 if (
d->rec.isEmpty()) {
996 d->error =
QSqlError(
"Unable to select fields from table "_L1 +
d->tableName,
1015 if (
parent.isValid() || column < 0 || column + count >
d->rec.count())
1019 if (
d->query.isActive())
1065 for (
int idx =
row +
count - 1; idx >=
row; --idx) {
1116 d->busyInsertingRows =
true;
1122 if (!
d->cache.isEmpty()) {
1124 while (
it !=
d->cache.begin() && (--
it).key() >=
row) {
1125 int oldKey =
it.key();
1128 it =
d->cache.insert(oldKey +
count, oldValue);
1139 d->busyInsertingRows =
false;
1195 const auto it =
d->cache.constFind(
item.row());
1199 const int rowOffset =
d->insertCount(
item.row());
1230 if (
d->query.isActive())
1250 if (
index.internalPointer() ||
index.column() < 0 ||
index.column() >=
d->rec.count()
1254 bool editable =
true;
1256 if (
d->rec.field(
index.column()).isReadOnly()) {
1317 for (
int i = 0, cnt = rec.
count();
i < cnt; ++
i)
1349 Q_ASSERT_X(
row >= 0,
"QSqlTableModel::setRecord()",
"Cannot set a record to a row less than 0");
1350 if (
d->busyInsertingRows)
1365 for (
int i = 0;
i <
values.count(); ++
i) {
1366 int idx =
d->nameToIndex(
values.fieldName(
i));
1379 for ( ;
i !=
e; ++
i) {
1385 d->strategy = strategy;
1387 if (!
values.isGenerated(
i.key()))
1408 const QSqlRecord &pIndex =
d->primaryIndex.isEmpty() ?
d->rec :
d->primaryIndex;
1419#include "moc_qsqltablemodel.cpp"
virtual Q_INVOKABLE Qt::ItemFlags flags(const QModelIndex &index) const
Returns the item flags for the given index.
Q_INVOKABLE Qt::SortOrder order
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles=QList< int >())
This signal is emitted whenever the data in an existing item changes.
virtual Q_INVOKABLE bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Sets the role data for the item at index to value.
void headerDataChanged(Qt::Orientation orientation, int first, int last)
This signal is emitted whenever a header is changed.
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.
QObject * parent() const
Returns a pointer to the parent object.
qsizetype size() const noexcept
T value(qsizetype i) const
iterator insert(const Key &key, const T &value)
T value(const Key &key, const T &defaultValue=T()) const
iterator erase(const_iterator it)
iterator find(const Key &key)
const_iterator ConstIterator
const_iterator constBegin() const
const_iterator constEnd() const
iterator insert(const T &value)
The QSqlDatabase class handles a connection to a database.
QSqlIndex primaryIndex(const QString &tablename) const
Returns the primary index for table tablename.
QSqlDriver * driver() const
Returns the database driver used to access the database connection.
QSqlRecord record(const QString &tablename) const
Returns a QSqlRecord populated with the names of all the fields in the table (or view) called tablena...
static QSqlDatabase database(const QString &connectionName=QLatin1StringView(defaultConnection), bool open=true)
\threadsafe
virtual QString stripDelimiters(const QString &identifier, IdentifierType type) const
Returns the identifier with the leading and trailing delimiters removed, identifier can either be a t...
virtual bool isIdentifierEscaped(const QString &identifier, IdentifierType type) const
Returns whether identifier is escaped according to the database rules.
virtual bool hasFeature(DriverFeature f) const =0
Returns true if the driver supports feature feature; otherwise returns false.
The QSqlError class provides SQL database error information.
The QSqlField class manipulates the fields in SQL database tables and views.
The QSqlIndex class provides functions to manipulate and describe database indexes.
void initColOffsets(int size)
static const QLatin1StringView orderBy()
static const QLatin1StringView asc()
static const QLatin1StringView sp()
static const QLatin1StringView desc()
static const QString concat(const QString &a, const QString &b)
static const QLatin1StringView where()
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.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
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...
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.
The QSqlQuery class provides a means of executing and manipulating SQL statements.
const QSqlDriver * driver() const
Returns the database driver associated with the query.
bool prepare(const QString &query)
Prepares the SQL query query for execution.
void clear()
Clears the result set and releases any resources held by the query.
QSqlError lastError() const
Returns error information about the last error (if any) that occurred with this query.
QString lastQuery() const
Returns the text of the current query being used, or an empty string if there is no current query tex...
bool exec(const QString &query)
Executes the SQL in query.
void addBindValue(const QVariant &val, QSql::ParamType type=QSql::In)
Adds the value val to the list of values when using positional value binding.
The QSqlRecord class encapsulates a database record.
void clear()
Removes all the record's fields.
QVariant value(int i) const
Returns the value of the field located at position index in the record.
bool isNull(int i) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
int count() const
Returns the number of fields in the record.
QSqlRecord keyValues(const QSqlRecord &keyFields) const
void setValue(int i, const QVariant &val)
Sets the value of the field at position index to val.
bool isGenerated(int i) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
void setGenerated(const QString &name, bool generated)
Sets the generated flag for the field called name to generated.
int indexOf(const QString &name) const
Returns the position of the field called name within the record, or -1 if it cannot be found.
The QSqlResult class provides an abstract interface for accessing data from specific SQL databases.
const QSqlRecord & rec() const
QSqlRecord primaryValues(const QSqlRecord &pi) const
void setValue(int c, const QVariant &v)
virtual int nameToIndex(const QString &name) const
virtual void clearCache()
int insertCount(int maxRow=-1) const
bool exec(const QString &stmt, bool prepStatement, const QSqlRecord &rec, const QSqlRecord &whereValues)
QSqlRecord record(const QList< QVariant > &values) const
virtual void revertCachedRow(int row)
QString strippedFieldName(const QString &name) const
void initRecordAndPrimaryIndex()
The QSqlTableModel class provides an editable data model for a single database table.
EditStrategy
This enum type describes which strategy to choose when editing values in the database.
void primeInsert(int row, QSqlRecord &record)
This signal is emitted by insertRows(), when an insertion is initiated in the given row of the curren...
virtual void setFilter(const QString &filter)
Sets the current filter to filter.
virtual QString orderByClause() const
Returns an SQL {ORDER BY} clause based on the currently set sort order.
bool removeColumns(int column, int count, const QModelIndex &parent=QModelIndex()) override
Removes count columns from the parent model, starting at index column.
void setPrimaryKey(const QSqlIndex &key)
Protected method that allows subclasses to set the primary key to key.
bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
Inserts count empty rows at position row.
void sort(int column, Qt::SortOrder order) override
Sorts the data by column with the sort order order.
QVariant data(const QModelIndex &idx, int role=Qt::DisplayRole) const override
\reimp
void beforeInsert(QSqlRecord &record)
This signal is emitted by insertRowIntoTable() before a new row is inserted into the currently active...
QSqlRecord record() const
This is an overloaded function.
QSqlTableModel(QObject *parent=nullptr, const QSqlDatabase &db=QSqlDatabase())
Creates an empty QSqlTableModel and sets the parent to parent and the database connection to db.
bool isDirty() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
QSqlRecord primaryValues(int row) const
virtual bool selectRow(int row)
QString filter() const
Returns the currently set filter.
QSqlIndex primaryKey() const
Returns the primary key for the current table, or an empty QSqlIndex if the table is not set or has n...
virtual void setSort(int column, Qt::SortOrder order)
Sets the sort order for column to order.
EditStrategy editStrategy() const
Returns the current edit strategy.
virtual bool updateRowInTable(int row, const QSqlRecord &values)
Updates the given row in the currently active database table with the specified values.
void revert() override
This reimplemented slot is called by the item delegates when the user canceled editing the current ro...
bool clearItemData(const QModelIndex &index) override
\reimp
virtual bool insertRowIntoTable(const QSqlRecord &values)
Inserts the values values into the currently active database table.
void clear() override
\reimp
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Sets the data for the item index for the role role to value.
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
\reimp
QString tableName() const
Returns the name of the currently selected table.
void revertAll()
Reverts all pending changes.
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
Removes count rows starting at row.
bool submitAll()
Submits all pending changes and returns true on success.
virtual void setTable(const QString &tableName)
Sets the database table on which the model operates to tableName.
void beforeDelete(int row)
This signal is emitted by deleteRowFromTable() before the row is deleted from the currently active da...
QModelIndex indexInQuery(const QModelIndex &item) const override
Returns the index of the value in the database result set for the given item in the model.
virtual QString selectStatement() const
Returns the SQL SELECT statement used internally to populate the model.
virtual bool select()
Populates the model with data from the table that was set via setTable(), using the specified filter ...
bool submit() override
This reimplemented slot is called by the item delegates when the user stopped editing the current row...
virtual void setEditStrategy(EditStrategy strategy)
Sets the strategy for editing values in the database to strategy.
QSqlDatabase database() const
Returns the model's database connection.
virtual bool deleteRowFromTable(int row)
Deletes the given row from the currently active database table.
bool insertRecord(int row, const QSqlRecord &record)
Inserts the record at position row.
int fieldIndex(const QString &fieldName) const
Returns the index of the field fieldName, or -1 if no corresponding field exists in the model.
bool setRecord(int row, const QSqlRecord &record)
Applies values to the row in the model.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
\reimp
Qt::ItemFlags flags(const QModelIndex &index) const override
\reimp
virtual ~QSqlTableModel()
Destroys the object and frees any allocated resources.
void beforeUpdate(int row, QSqlRecord &record)
This signal is emitted by updateRowInTable() before the row is updated in the currently active databa...
virtual void revertRow(int row)
Reverts all changes for the specified row.
\macro QT_RESTRICTED_CAST_FROM_ASCII
void clear()
Clears the contents of the string and makes it null.
qsizetype size() const
Returns the number of characters in this string.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
bool isNull() const
Returns true if this is a null variant, false otherwise.
QMap< QString, QString > map
[6]
QSet< QString >::iterator it
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLenum GLsizei GLsizei GLint * values
[15]
GLenum GLenum GLsizei count
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
GLenum GLenum GLsizei void GLsizei void * column
GLdouble GLdouble GLdouble GLdouble q
GLenum GLenum GLsizei void * row
GLfixed GLfixed GLint GLint order
#define Q_ASSERT_X(cond, x, msg)
QList< QPair< QString, QString > > Map
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent