289 void clearEditBuffer();
291 void revertCachedRow(
int row);
311 for (
int i = 0; i < relations.count(); ++i) {
327 return baseRec.
indexOf(fieldname);
332 editBuffer = baseRec;
333 clearGenerated(editBuffer);
341 for (
int i = 0; i < relations.count(); ++i)
342 relations[i].clearDictionary();
458 d->relations.value(index.
column()).isValid()) {
468 switch (
d->strategy) {
472 if ((index.
row() ==
d->editIndex || index.
row() ==
d->insertIndex)
473 &&
d->editBuffer.isGenerated(index.
column()))
474 v =
d->editBuffer.value(index.
column());
508 &&
d->relations.value(index.
column()).isValid()) {
541 if (
d->relations.size() <= column)
542 d->relations.resize(column + 1);
543 d->relations[column].init(
this, relation);
555 return d->relations.value(column).rel;
559 const QString &fieldName)
const 578 if (
d->relations.isEmpty())
592 for (
int i = 0; i < rec.
count(); ++i) {
603 for (
int i = 0; i < rec.
count(); ++i) {
612 fieldNames.
insert(name, fieldNames.
value(name, 0) + 1);
616 for (
int i = 0; i < rec.
count(); ++i) {
625 if (fieldNames.
value(fieldList[i]) > 1) {
633 fieldNames.
insert(fieldList[i], fieldNames.
value(fieldList[i])-1);
705 if ( column < 0 || column >=
d->relations.count())
714 return relation.
model;
732 d->relations.clear();
771 d->joinMode = joinMode;
789 d->baseRec =
d->db.record(table);
800 for (
int i = 0; i < values.
count(); ++i) {
801 int realCol = q->indexInQuery(q->createIndex(row, i)).column();
802 if (realCol != -1 && relations.value(realCol).isValid()) {
805 values.
replace(i, baseRec.field(realCol));
820 d->translateFieldNames(row, rec);
833 d->translateFieldNames(0, rec);
863 if (parent.
isValid() || column < 0 || column + count >
d->rec.count())
866 for (
int i = 0; i < count; ++i) {
867 d->baseRec.remove(column);
868 if (
d->relations.count() > column)
869 d->relations.remove(column);
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
The QVariant class acts like a union for the most common Qt data types.
void setTable(const QString &tableName)
Reimplemented Function
QString section(QChar sep, int start, int end=-1, SectionFlags flags=SectionDefault) const
This function returns a section of the string.
The QSqlRelationalTableModel class provides an editable data model for a single database table...
virtual QString selectStatement() const
Returns the SQL SELECT statement used internally to populate the model.
void clearCache()
Reimplemented Function
int rowCount(const QModelIndex &parent=QModelIndex()) const
Reimplemented Function
#define QT_END_NAMESPACE
This macro expands to.
virtual QSqlTableModel * relationModel(int column) const
Returns a QSqlTableModel object for accessing the table for which column is a foreign key...
void clear()
Removes all items from the hash.
void init(QSqlRelationalTableModel *parent, const QSqlRelation &relation)
virtual void setRelation(int column, const QSqlRelation &relation)
Lets the specified column be a foreign index specified by relation.
QString tableName() const
Returns the name of the table to which a foreign key refers.
QString filter() const
Returns the currently set filter.
virtual ~QSqlRelationalTableModel()
Destroys the object and frees any allocated resources.
void clear()
Reimplemented Function
QVariant value() const
Returns the value of the field as a QVariant.
QSqlDatabase database() const
Returns a pointer to the used QSqlDatabase or 0 if no database was set.
QString & prepend(QChar c)
QSqlRelationalTableModel * m_parent
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Returns the index of the data in row and column with parent.
int select(int, fd_set *, fd_set *, fd_set *, struct timeval *)
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
virtual void clearCache()
The QSqlDatabase class represents a connection to a database.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
JoinMode
This enum specifies the type of mode to use when joining two tables.
The QSqlRecord class encapsulates a database record.
bool select()
Reimplemented Function
The QString class provides a Unicode character string.
void populateDictionary()
The QObject class is the base class of all Qt objects.
QSqlRelationalTableModel::JoinMode joinMode
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
QSqlDriver * driver() const
Returns the database driver used to access the database connection.
const T value(const Key &key) const
Returns the value associated with the key.
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
bool isIdentifierEscaped(const QString &identifier, IdentifierType type) const
Returns whether identifier is escaped according to the database rules.
bool insertRowIntoTable(const QSqlRecord &values)
Reimplemented Function
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...
void clear()
Reimplemented Function
void reserve(int size)
Attempts to allocate memory for at least size characters.
void append(const T &t)
Inserts value at the end of the list.
#define QT_BEGIN_NAMESPACE
This macro expands to.
QSqlRecord record(const QString &tablename) const
Returns a QSqlRecord populated with the names of all the fields in the table (or view) called tablena...
virtual void setTable(const QString &tableName)
Sets the database table on which the model operates to tableName.
QRelatedTableModel * model
static bool isEmpty(const char *str)
virtual bool insertRowIntoTable(const QSqlRecord &values)
Inserts the values values into the currently active database table.
QSqlQuery query() const
Returns the QSqlQuery associated with this model.
int size() const
Returns the number of characters in this string.
static void qAppendWhereClause(QString &query, const QString &clause1, const QString &clause2)
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
QString orderByClause() const
Reimplemented Function
int row() const
Returns the row this model index refers to.
void revertCachedRow(int row)
The QStringList class provides a list of strings.
bool removeColumns(int column, int count, const QModelIndex &parent=QModelIndex())
Reimplemented Function
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
static QChar fromLatin1(char c)
Converts the Latin-1 character c to its equivalent QChar.
virtual void revertCachedRow(int row)
QSqlRelation relation(int column) const
Returns the relation for the column column, or an invalid relation if no relation is set...
bool updateRowInTable(int row, const QSqlRecord &values)
Reimplemented Function
virtual bool updateRowInTable(int row, const QSqlRecord &values)
Updates the given row in the currently active database table with the specified values.
virtual QString orderByClause() const
Returns an SQL ORDER BY clause based on the currently set sort order.
The QSqlRelation class stores information about an SQL foreign key.
bool isDictionaryInitialized()
void setJoinMode(QSqlRelationalTableModel::JoinMode joinMode)
Sets the SQL join mode to the value given by joinMode to show or hide rows with NULL foreign keys...
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
QSqlField field(int i) const
Returns the field at position index.
bool isValid() const
Returns true if the QSqlRelation object is valid; otherwise returns false.
bool removeColumns(int column, int count, const QModelIndex &parent=QModelIndex())
Removes count columns from the parent model, starting at index column.
QString join(const QString &sep) const
Joins all the string list's strings into a single string with each element separated by the given sep...
int count() const
Returns the number of fields in the record.
void revertRow(int row)
Reimplemented Function
QVariant data(const QModelIndex &item, int role=Qt::DisplayRole) const
Reimplemented Function
QString indexColumn() const
Returns the index column from table tableName() to which a foreign key refers.
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
#define Q_DECLARE_PUBLIC(Class)
QString & append(QChar c)
int compare(const QString &s) const
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Sets the data for the item index for the role role to value.
QString relationField(const QString &tableName, const QString &fieldName) const
QString tableName() const
Returns the name of the currently selected table.
QObject * parent() const
Returns a pointer to the parent object.
QSqlRelationalTableModel(QObject *parent=0, QSqlDatabase db=QSqlDatabase())
Creates an empty QSqlRelationalTableModel and sets the parent to parent and the database connection t...
The QModelIndex class is used to locate data in a data model.
void replace(int pos, const QSqlField &field)
Replaces the field at position pos with the given field.
The QSqlTableModel class provides an editable data model for a single database table.
virtual bool select()
Populates the model with data from the table that was set via setTable(), using the specified filter ...
QString displayColumn() const
Returns the column from table tableName() that should be presented to the user instead of a foreign k...
QSqlRecord record(int row) const
Returns the record containing information about the fields of the current query.
QString selectStatement() const
Reimplemented Function
virtual void revertRow(int row)
Reverts all changes for the specified row.
void setValue(int i, const QVariant &val)
Sets the value of the field at position index to val.
QSqlRelationalTableModelPrivate()
bool setData(const QModelIndex &item, const QVariant &value, int role=Qt::EditRole)
Sets the data for the role in the item with the specified index to the value given.
QString stripDelimiters(const QString &identifier, IdentifierType type) const
Returns the identifier with the leading and trailing delimiters removed, identifier can either be a t...
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
QString fieldName(int i) const
Returns the name of the field at position index.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
QVector< QRelation > relations
void translateFieldNames(int row, QSqlRecord &values) const
QVariant data(const QModelIndex &idx, int role=Qt::DisplayRole) const
Reimplemented Function
QVariant value(int i) const
Returns the value of the field located at position index in the record.
QHash< QString, QVariant > dictionary
int column() const
Returns the column this model index refers to.
void setGenerated(const QString &name, bool generated)
Sets the generated flag for the field called name to generated.
int nameToIndex(const QString &name) const