Qt 4.8
qsqlrelationaltablemodel.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtSql module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
43 
44 #include "qhash.h"
45 #include "qstringlist.h"
46 #include "qsqldatabase.h"
47 #include "qsqldriver.h"
48 #include "qsqlerror.h"
49 #include "qsqlfield.h"
50 #include "qsqlindex.h"
51 #include "qsqlquery.h"
52 #include "qsqlrecord.h"
53 
54 #include "qsqltablemodel_p.h"
55 
56 #include "qdebug.h"
57 
59 
143 class QRelatedTableModel;
144 
145 struct QRelation
146 {
147  public:
149  void init(QSqlRelationalTableModel *parent, const QSqlRelation &relation);
150 
151  void populateModel();
152 
154  void populateDictionary();
155  void clearDictionary();
156 
157  void clear();
158  bool isValid();
159 
162  QHash<QString, QVariant> dictionary;//maps keys to display values
163 
164  private:
167 };
168 
170 {
171 public:
173  bool select();
174 private:
177 };
178 /*
179  A QRelation must be initialized before it is considered valid.
180  Note: population of the model and dictionary are kept separate
181  from initialization, and are populated on an as needed basis.
182 */
184 {
185  Q_ASSERT(parent != NULL);
186  m_parent = parent;
187  rel = relation;
188 }
189 
191 {
192  if (!isValid())
193  return;
194  Q_ASSERT(m_parent != NULL);
195 
196  if (!model) {
199  model->select();
200  }
201 }
202 
204 {
205  return m_dictInitialized;
206 }
207 
209 {
210  if (!isValid())
211  return;
212 
213  if (model == NULL)
214  populateModel();
215 
216  QSqlRecord record;
217  QString indexColumn;
218  QString displayColumn;
219  for (int i=0; i < model->rowCount(); ++i) {
220  record = model->record(i);
221 
222  indexColumn = rel.indexColumn();
224  indexColumn = m_parent->database().driver()->stripDelimiters(indexColumn, QSqlDriver::FieldName);
225 
226  displayColumn = rel.displayColumn();
228  displayColumn = m_parent->database().driver()->stripDelimiters(displayColumn, QSqlDriver::FieldName);
229 
230  dictionary[record.field(indexColumn).value().toString()] =
231  record.field(displayColumn).value();
232  }
233  m_dictInitialized = true;
234 }
235 
237 {
238  dictionary.clear();
239  m_dictInitialized = false;
240 }
241 
243 {
244  delete model;
245  model = 0;
246  clearDictionary();
247 }
248 
250 {
251  return (rel.isValid() && m_parent != NULL);
252 }
253 
254 
255 
257  QSqlTableModel(parent, db), firstSelect(true), relation(rel)
258 {
259 }
260 
262 {
263  if (firstSelect) {
264  firstSelect = false;
265  return QSqlTableModel::select();
266  }
268  bool res = QSqlTableModel::select();
269  if (res)
271  return res;
272 }
273 
274 
276 {
278 public:
281  joinMode( QSqlRelationalTableModel::InnerJoin )
282  {}
283  QString relationField(const QString &tableName, const QString &fieldName) const;
284 
285  int nameToIndex(const QString &name) const;
287  QSqlRecord baseRec; // the record without relations
288  void clearChanges();
289  void clearEditBuffer();
290  void clearCache();
291  void revertCachedRow(int row);
292 
293  void translateFieldNames(int row, QSqlRecord &values) const;
295 };
296 
297 static void qAppendWhereClause(QString &query, const QString &clause1, const QString &clause2)
298 {
299  if (clause1.isEmpty() && clause2.isEmpty())
300  return;
301  if (clause1.isEmpty() || clause2.isEmpty())
302  query.append(QLatin1String(" WHERE (")).append(clause1).append(clause2);
303  else
304  query.append(QLatin1String(" WHERE (")).append(clause1).append(
305  QLatin1String(") AND (")).append(clause2);
306  query.append(QLatin1String(") "));
307 }
308 
310 {
311  for (int i = 0; i < relations.count(); ++i) {
312  QRelation &rel = relations[i];
313  rel.clear();
314  }
315 }
316 
318 {
320 }
321 
323 {
324  QString fieldname = name;
325  if (db.driver()->isIdentifierEscaped(fieldname, QSqlDriver::FieldName))
326  fieldname = db.driver()->stripDelimiters(fieldname, QSqlDriver::FieldName);
327  return baseRec.indexOf(fieldname);
328 }
329 
331 {
332  editBuffer = baseRec;
333  clearGenerated(editBuffer);
334 }
335 
340 {
341  for (int i = 0; i < relations.count(); ++i)
342  relations[i].clearDictionary();
343 
345 }
346 
440 {
441 }
442 
447 {
448 }
449 
454 {
456 
457  if (role == Qt::DisplayRole && index.column() >= 0 && index.column() < d->relations.count() &&
458  d->relations.value(index.column()).isValid()) {
459  QRelation &relation = d->relations[index.column()];
460  if (!relation.isDictionaryInitialized())
461  relation.populateDictionary();
462 
463  //only perform a dictionary lookup for the display value
464  //when the value at index has been changed or added.
465  //At an unmodified index, the underlying model will
466  //already have the correct display value.
467  QVariant v;
468  switch (d->strategy) {
469  case OnFieldChange:
470  break;
471  case OnRowChange:
472  if ((index.row() == d->editIndex || index.row() == d->insertIndex)
473  && d->editBuffer.isGenerated(index.column()))
474  v = d->editBuffer.value(index.column());
475  break;
476  case OnManualSubmit:
477  const QSqlTableModelPrivate::ModifiedRow row = d->cache.value(index.row());
478  if (row.op != QSqlTableModelPrivate::None && row.rec.isGenerated(index.column()))
479  v = row.rec.value(index.column());
480  break;
481  }
482  if (v.isValid())
483  return relation.dictionary[v.toString()];
484  }
485  return QSqlTableModel::data(index, role);
486 }
487 
504  int role)
505 {
507  if ( role == Qt::EditRole && index.column() > 0 && index.column() < d->relations.count()
508  && d->relations.value(index.column()).isValid()) {
509  QRelation &relation = d->relations[index.column()];
510  if (!relation.isDictionaryInitialized())
511  relation.populateDictionary();
512  if (!relation.dictionary.contains(value.toString()))
513  return false;
514  }
515  return QSqlTableModel::setData(index, value, role);
516 }
517 
537 {
539  if (column < 0)
540  return;
541  if (d->relations.size() <= column)
542  d->relations.resize(column + 1);
543  d->relations[column].init(this, relation);
544 }
545 
553 {
555  return d->relations.value(column).rel;
556 }
557 
559  const QString &fieldName) const
560 {
561  QString ret;
562  ret.reserve(tableName.size() + fieldName.size() + 1);
563  ret.append(tableName).append(QLatin1Char('.')).append(fieldName);
564 
565  return ret;
566 }
567 
572 {
574  QString query;
575 
576  if (tableName().isEmpty())
577  return query;
578  if (d->relations.isEmpty())
580 
581  QString tList;
582  QString fList;
583  QString where;
584 
585  QSqlRecord rec = d->baseRec;
586  QStringList tables;
587  const QRelation nullRelation;
588 
589  // Count how many times each field name occurs in the record
590  QHash<QString, int> fieldNames;
591  QStringList fieldList;
592  for (int i = 0; i < rec.count(); ++i) {
593  QSqlRelation relation = d->relations.value(i, nullRelation).rel;
594  QString name;
595  if (relation.isValid())
596  {
597  // Count the display column name, not the original foreign key
598  name = relation.displayColumn();
599  if (d->db.driver()->isIdentifierEscaped(name, QSqlDriver::FieldName))
600  name = d->db.driver()->stripDelimiters(name, QSqlDriver::FieldName);
601 
602  QSqlRecord rec = database().record(relation.tableName());
603  for (int i = 0; i < rec.count(); ++i) {
604  if (name.compare(rec.fieldName(i), Qt::CaseInsensitive) == 0) {
605  name = rec.fieldName(i);
606  break;
607  }
608  }
609  }
610  else
611  name = rec.fieldName(i);
612  fieldNames.insert(name, fieldNames.value(name, 0) + 1);
613  fieldList.append(name);
614  }
615 
616  for (int i = 0; i < rec.count(); ++i) {
617  QSqlRelation relation = d->relations.value(i, nullRelation).rel;
618  if (relation.isValid()) {
619  QString relTableAlias = QString::fromLatin1("relTblAl_%1").arg(i);
620  if (!fList.isEmpty())
621  fList.append(QLatin1String(", "));
622  fList.append(d->relationField(relTableAlias,relation.displayColumn()));
623 
624  // If there are duplicate field names they must be aliased
625  if (fieldNames.value(fieldList[i]) > 1) {
626  QString relTableName = relation.tableName().section(QChar::fromLatin1('.'), -1, -1);
627  if (d->db.driver()->isIdentifierEscaped(relTableName, QSqlDriver::TableName))
628  relTableName = d->db.driver()->stripDelimiters(relTableName, QSqlDriver::TableName);
629  QString displayColumn = relation.displayColumn();
630  if (d->db.driver()->isIdentifierEscaped(displayColumn, QSqlDriver::FieldName))
631  displayColumn = d->db.driver()->stripDelimiters(displayColumn, QSqlDriver::FieldName);
632  fList.append(QString::fromLatin1(" AS %1_%2_%3").arg(relTableName).arg(displayColumn).arg(fieldNames.value(fieldList[i])));
633  fieldNames.insert(fieldList[i], fieldNames.value(fieldList[i])-1);
634  }
635 
636  if (d->joinMode == QSqlRelationalTableModel::InnerJoin) {
637  // this needs fixing!! the below if is borken.
638  // Use LeftJoin mode if you want correct behavior
639  tables.append(relation.tableName().append(QLatin1Char(' ')).append(relTableAlias));
640  if(!where.isEmpty())
641  where.append(QLatin1String(" AND "));
642  where.append(d->relationField(tableName(), d->db.driver()->escapeIdentifier(rec.fieldName(i), QSqlDriver::FieldName)));
643  where.append(QLatin1String(" = "));
644  where.append(d->relationField(relTableAlias, relation.indexColumn()));
645  } else {
646  tables.append(QLatin1String(" LEFT JOIN"));
647  tables.append(relation.tableName().append(QLatin1Char(' ')).append(relTableAlias));
648  tables.append(QLatin1String("ON"));
649 
650  QString clause;
651  clause.append(d->relationField(tableName(), d->db.driver()->escapeIdentifier(rec.fieldName(i), QSqlDriver::FieldName)));
652  clause.append(QLatin1String(" = "));
653  clause.append(d->relationField(relTableAlias, relation.indexColumn()));
654 
655  tables.append(clause);
656  }
657  } else {
658  if (!fList.isEmpty())
659  fList.append(QLatin1String(", "));
660  fList.append(d->relationField(tableName(), d->db.driver()->escapeIdentifier(rec.fieldName(i), QSqlDriver::FieldName)));
661  }
662  }
663 
664  if (d->joinMode == QSqlRelationalTableModel::InnerJoin && !tables.isEmpty()) {
665  tList.append(tables.join(QLatin1String(", ")));
666  if(!tList.isEmpty())
667  tList.prepend(QLatin1String(", "));
668  } else
669  tList.append(tables.join(QLatin1String(" ")));
670 
671  if (fList.isEmpty())
672  return query;
673 
674  tList.prepend(tableName());
675  query.append(QLatin1String("SELECT "));
676  query.append(fList).append(QLatin1String(" FROM ")).append(tList);
677 
678  if (d->joinMode == QSqlRelationalTableModel::InnerJoin) {
679  qAppendWhereClause(query, where, filter());
680  } else if (!filter().isEmpty()) {
681  query.append(QLatin1String(" WHERE ("));
682  query.append(filter());
683  query.append(QLatin1String(")"));
684  }
685 
686  QString orderBy = orderByClause();
687  if (!orderBy.isEmpty())
688  query.append(QLatin1Char(' ')).append(orderBy);
689 
690  return query;
691 }
692 
703 {
705  if ( column < 0 || column >= d->relations.count())
706  return 0;
707 
708  QRelation &relation = const_cast<QSqlRelationalTableModelPrivate *>(d)->relations[column];
709  if (!relation.isValid())
710  return 0;
711 
712  if (!relation.model)
713  relation.populateModel();
714  return relation.model;
715 }
716 
721 {
723 }
724 
729 {
731  d->clearChanges();
732  d->relations.clear();
734 }
735 
736 
769 {
771  d->joinMode = joinMode;
772 }
777 {
778  return QSqlTableModel::select();
779 }
780 
785 {
787 
788  // memorize the table before applying the relations
789  d->baseRec = d->db.record(table);
790 
792 }
793 
797 {
799 
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()) {
803  QVariant v = values.value(i);
804  bool gen = values.isGenerated(i);
805  values.replace(i, baseRec.field(realCol));
806  values.setValue(i, v);
807  values.setGenerated(i, gen);
808  }
809  }
810 }
811 
816 {
818 
819  QSqlRecord rec = values;
820  d->translateFieldNames(row, rec);
821 
822  return QSqlTableModel::updateRowInTable(row, rec);
823 }
824 
829 {
831 
832  QSqlRecord rec = values;
833  d->translateFieldNames(0, rec);
834 
836 }
837 
842 {
844 
845  const QSqlRelation rel = d->relations.value(d->sortColumn).rel;
846  if (!rel.isValid())
848 
849  QString s = QLatin1String("ORDER BY ");
850  s.append(d->relationField(QLatin1String("relTblAl_") + QString::number(d->sortColumn),
851  rel.displayColumn()));
852  s += d->sortOrder == Qt::AscendingOrder ? QLatin1String(" ASC") : QLatin1String(" DESC");
853  return s;
854 }
855 
859 bool QSqlRelationalTableModel::removeColumns(int column, int count, const QModelIndex &parent)
860 {
862 
863  if (parent.isValid() || column < 0 || column + count > d->rec.count())
864  return false;
865 
866  for (int i = 0; i < count; ++i) {
867  d->baseRec.remove(column);
868  if (d->relations.count() > column)
869  d->relations.remove(column);
870  }
871  return QSqlTableModel::removeColumns(column, count, parent);
872 }
873 
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
void setTable(const QString &tableName)
Reimplemented Function
double d
Definition: qnumeric_p.h:62
QString section(QChar sep, int start, int end=-1, SectionFlags flags=SectionDefault) const
This function returns a section of the string.
Definition: qstring.h:781
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.
Definition: qglobal.h:90
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.
Definition: qhash.h:574
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.
Definition: qsqlfield.h:71
QSqlDatabase database() const
Returns a pointer to the used QSqlDatabase or 0 if no database was set.
QString & prepend(QChar c)
Definition: qstring.h:261
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 ...
Definition: qvariant.cpp:2270
virtual void clearCache()
The QSqlDatabase class represents a connection to a database.
Definition: qsqldatabase.h:78
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.
Definition: qsqlrecord.h:58
bool select()
Reimplemented Function
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
QSqlRelationalTableModel::JoinMode joinMode
#define Q_D(Class)
Definition: qglobal.h:2482
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
Definition: qhash.h:872
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.
Definition: qhash.h:606
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
bool select()
Populates the model with data from the table that was set via setTable(), using the specified filter ...
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
#define Q_Q(Class)
Definition: qglobal.h:2483
bool isIdentifierEscaped(const QString &identifier, IdentifierType type) const
Returns whether identifier is escaped according to the database rules.
Definition: qsqldriver.cpp:429
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...
Definition: qsqlrecord.cpp:519
void clear()
Reimplemented Function
void reserve(int size)
Attempts to allocate memory for at least size characters.
Definition: qstring.h:881
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
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.
Definition: qstring.h:102
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.
Definition: qstring.h:704
QString orderByClause() const
Reimplemented Function
int row() const
Returns the row this model index refers to.
QRelatedTableModel(QRelation *rel, QObject *parent=0, QSqlDatabase db=QSqlDatabase())
const char * name
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
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
Definition: qstring.cpp:2838
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
static QChar fromLatin1(char c)
Converts the Latin-1 character c to its equivalent QChar.
Definition: qchar.h:378
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.
quint16 values[128]
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.
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.
Definition: qsqlrecord.cpp:289
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&#39;s strings into a single string with each element separated by the given sep...
Definition: qstringlist.h:162
int count() const
Returns the number of fields in the record.
Definition: qsqlrecord.cpp:573
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
Definition: qstring.cpp:7186
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
QString & append(QChar c)
Definition: qstring.cpp:1777
int compare(const QString &s) const
Definition: qstring.cpp:5037
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
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.
Definition: qobject.h:273
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.
Definition: qsqlrecord.cpp:336
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.
Definition: qsqlrecord.cpp:585
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...
Definition: qsqldriver.cpp:455
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
QString fieldName(int i) const
Returns the name of the field at position index.
Definition: qsqlrecord.cpp:232
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
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.
Definition: qsqlrecord.cpp:203
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.
Definition: qsqlrecord.cpp:420
int nameToIndex(const QString &name) const