<class name="QSqlRelationalTableModel" doc="/** <p>The <a href="QSqlRelationalTableModel.html#QSqlRelationalTableModel(com.trolltech.qt.core.QObject, com.trolltech.qt.sql.QSqlDatabase)"><tt>QSqlRelationalTableModel</tt></a> class provides an editable data model for a single database table, with foreign key support.</p> <p><a href="QSqlRelationalTableModel.html#QSqlRelationalTableModel(com.trolltech.qt.core.QObject, com.trolltech.qt.sql.QSqlDatabase)"><tt>QSqlRelationalTableModel</tt></a> acts like <a href="QSqlTableModel.html#QSqlTableModel(com.trolltech.qt.core.QObject, com.trolltech.qt.sql.QSqlDatabase)"><tt>QSqlTableModel</tt></a>, but allows columns to be set as foreign keys into other database tables.</p> <p><table align="center" cellpadding="2" cellspacing="1" border="0"> <tr valign="top" class="odd"><td><img src="%2E%2E/images/noforeignkeys.png" /></td><td><img src="%2E%2E/images/foreignkeys.png" /></td></tr> </table></p> <p>The screenshot on the left shows a plain <a href="QSqlTableModel.html#QSqlTableModel(com.trolltech.qt.core.QObject, com.trolltech.qt.sql.QSqlDatabase)"><tt>QSqlTableModel</tt></a> in a <a href="%2E%2E/gui/QTableView.html"><tt>QTableView</tt></a>. Foreign keys (<tt>city</tt> and <tt>country</tt>) aren't resolved to human-readable values. The screenshot on the right shows a <a href="QSqlRelationalTableModel.html#QSqlRelationalTableModel(com.trolltech.qt.core.QObject, com.trolltech.qt.sql.QSqlDatabase)"><tt>QSqlRelationalTableModel</tt></a>, with foreign keys resolved into human-readable text strings.</p> <p>The following code snippet shows how the <a href="QSqlRelationalTableModel.html#QSqlRelationalTableModel(com.trolltech.qt.core.QObject, com.trolltech.qt.sql.QSqlDatabase)"><tt>QSqlRelationalTableModel</tt></a> was set up:</p> <pre> model-&gt;setTable(&quot;employee&quot;); model-&gt;setRelation(2, QSqlRelation(&quot;city&quot;, &quot;id&quot;, &quot;name&quot;)); model-&gt;setRelation(3, QSqlRelation(&quot;country&quot;, &quot;id&quot;, &quot;name&quot;));</pre> <p>The <a href="QSqlRelationalTableModel.html#setRelation(int, com.trolltech.qt.sql.QSqlRelation)"><tt>setRelation</tt></a> function calls establish a relationship between two tables. The first call specifies that column 2 in table <tt>employee</tt> is a foreign key that maps with field <tt>id</tt> of table <tt>city</tt>, and that the view should present the <tt>city</tt>'s <tt>name</tt> field to the user. The second call does something similar with column 3.</p> <p>If you use a read-write <a href="QSqlRelationalTableModel.html#QSqlRelationalTableModel(com.trolltech.qt.core.QObject, com.trolltech.qt.sql.QSqlDatabase)"><tt>QSqlRelationalTableModel</tt></a>, you probably want to use QSqlRelationalDelegate on the view. Unlike the default delegate, QSqlRelationalDelegate provides a combobox for fields that are foreign keys into other tables. To use the class, simply call QAbstractItemView::setItemDelegate() on the view with an instance of QSqlRelationalDelegate:</p> <pre> QTableView *view = new QTableView; view-&gt;setModel(model); view-&gt;setItemDelegate(new QSqlRelationalDelegate(view));</pre> <p>The sql/relationaltablemodel</tt> example illustrates how to use <a href="QSqlRelationalTableModel.html#QSqlRelationalTableModel(com.trolltech.qt.core.QObject, com.trolltech.qt.sql.QSqlDatabase)"><tt>QSqlRelationalTableModel</tt></a> in conjunction with QSqlRelationalDelegate to provide tables with foreigh key support.</p> <p align="center"><img src="%2E%2E/images/relationaltable.png" /></p><p>Notes:</p> <ul> <li>The table must have a primary key declared.</li> <li>The table's primary key may not contain a relation to another table.</li> <li>If a relational table contains keys that refer to non-existent rows in the referenced table, the rows containing the invalid keys will not be exposed through the model. The user or the database is responsible for keeping referential integrity.</li> </ul> @see <a href="QSqlRelation.html"><tt>QSqlRelation</tt></a> @see <tt>QSqlRelationalDelegate</tt> @see Relational Table Model Example</tt> */"> <signal name="protected final void beforeDelete(int row)" doc="/** <p>This signal is emitted before the <tt>row</tt> is deleted.</p> <dl> <dt><b>Compatible Slot Signatures:</b></dt> <dd><tt>void mySlot(int row)</tt></dd> <dd><tt>void mySlot()</tt></dd> </dl> */"/> <signal name="protected final void beforeInsert(com.trolltech.qt.sql.QSqlRecord record)" doc="/** <p>This signal is emitted before a new row is inserted. The values that are about to be inserted are stored in <tt>record</tt> and can be modified before they will be inserted.</p> <dl> <dt><b>Compatible Slot Signatures:</b></dt> <dd><tt>void mySlot(com.trolltech.qt.sql.QSqlRecord record)</tt></dd> <dd><tt>void mySlot()</tt></dd> </dl> */"/> <signal name="protected final void beforeUpdate(int row, com.trolltech.qt.sql.QSqlRecord record)" doc="/** <p>This signal is emitted before the <tt>row</tt> is updated with the values from <tt>record</tt>.</p> <p>Note that only values that are marked as generated will be updated. The generated flag can be set with <tt>QSqlRecord::setGenerated</tt> and checked with <tt>QSqlRecord::isGenerated</tt>.</p> <dl> <dt><b>Compatible Slot Signatures:</b></dt> <dd><tt>void mySlot(int row, com.trolltech.qt.sql.QSqlRecord record)</tt></dd> <dd><tt>void mySlot(int row)</tt></dd> <dd><tt>void mySlot()</tt></dd> </dl> <dl> <dt><b>See Also:</b></dt> <dd><tt>QSqlRecord::isGenerated</tt></dd> </dl> */"/> <signal name="protected final void dataChanged(com.trolltech.qt.core.QModelIndex topLeft, com.trolltech.qt.core.QModelIndex bottomRight)" doc="/** <p>This signal is emitted whenever the data in an existing item changes. The affected items are those between <tt>topLeft</tt> and <tt>bottomRight</tt> inclusive (of the same parent).</p> <p>Note that this signal must be emitted explicitly when reimplementing the <a href="QSqlRelationalTableModel.html#setData(com.trolltech.qt.core.QModelIndex, java.lang.Object, int)"><tt>setData</tt></a> function.</p> <dl> <dt><b>Compatible Slot Signatures:</b></dt> <dd><tt>void mySlot(com.trolltech.qt.core.QModelIndex topLeft, com.trolltech.qt.core.QModelIndex bottomRight)</tt></dd> <dd><tt>void mySlot(com.trolltech.qt.core.QModelIndex topLeft)</tt></dd> <dd><tt>void mySlot()</tt></dd> </dl> <dl> <dt><b>See Also:</b></dt> <dd><a href="QSqlRelationalTableModel.html#headerDataChanged(com.trolltech.qt.core.Qt.Orientation, int, int)"><tt>headerDataChanged</tt></a>, <a href="QSqlRelationalTableModel.html#setData(com.trolltech.qt.core.QModelIndex, java.lang.Object, int)"><tt>setData</tt></a>, <a href="QSqlRelationalTableModel.html#layoutChanged()"><tt>layoutChanged</tt></a></dd> </dl> */"/> <signal name="protected final void headerDataChanged(com.trolltech.qt.core.Qt.Orientation orientation, int first, int last)" doc="/** <p>This signal is emitted whenever a header is changed. The <tt>orientation</tt> indicates whether the horizontal or vertical header has changed. The sections in the header from the <tt>first</tt> to the <tt>last</tt> need to be updated.</p> <p>Note that this signal must be emitted explicitly when reimplementing the <a href="QSqlQueryModel.html#setHeaderData(int, com.trolltech.qt.core.Qt.Orientation, java.lang.Object, int)"><tt>setHeaderData</tt></a> function.</p> <p>If you are changing the number of columns or rows you don't need to emit this signal, but use the begin/end functions.</p> <dl> <dt><b>Compatible Slot Signatures:</b></dt> <dd><tt>void mySlot(com.trolltech.qt.core.Qt.Orientation orientation, int first, int last)</tt></dd> <dd><tt>void mySlot(com.trolltech.qt.core.Qt.Orientation orientation, int first)</tt></dd> <dd><tt>void mySlot(com.trolltech.qt.core.Qt.Orientation orientation)</tt></dd> <dd><tt>void mySlot()</tt></dd> </dl> <dl> <dt><b>See Also:</b></dt> <dd><a href="QSqlTableModel.html#headerData(int, com.trolltech.qt.core.Qt.Orientation, int)"><tt>headerData</tt></a>, <a href="QSqlQueryModel.html#setHeaderData(int, com.trolltech.qt.core.Qt.Orientation, java.lang.Object, int)"><tt>setHeaderData</tt></a>, <a href="QSqlRelationalTableModel.html#dataChanged(com.trolltech.qt.core.QModelIndex, com.trolltech.qt.core.QModelIndex)"><tt>dataChanged</tt></a></dd> </dl> */"/> <signal name="protected final void layoutAboutToBeChanged()" doc="/** <p>This signal is emitted just before the layout of a model is changed. Components connected to this signal use it to adapt to changes in the model's layout.</p> <p>Subclasses should update any persistent model indexes after emitting <a href="QSqlRelationalTableModel.html#layoutAboutToBeChanged()"><tt>layoutAboutToBeChanged</tt></a>.</p> <dl> <dt><b>Compatible Slot Signature:</b></dt> <dd><tt>void mySlot()</tt></dd> </dl> <dl> <dt><b>See Also:</b></dt> <dd><a href="QSqlRelationalTableModel.html#layoutChanged()"><tt>layoutChanged</tt></a>, <a href="%2E%2E/core/%2E%2E/core/QAbstractItemModel.html#changePersistentIndex(com.trolltech.qt.core.QModelIndex, com.trolltech.qt.core.QModelIndex)"><tt>changePersistentIndex</tt></a></dd> </dl> */"/> <signal name="protected final void layoutChanged()" doc="/** <p>This signal is emitted whenever the layout of items exposed by the model has changed; for example, when the model has been sorted. When this signal is received by a view, it should update the layout of items to reflect this change.</p> <p>When subclassing <a href="%2E%2E/core/%2E%2E/core/QAbstractItemModel.html#QAbstractItemModel(com.trolltech.qt.core.QObject)"><tt>QAbstractItemModel</tt></a> or <a href="%2E%2E/gui/QAbstractProxyModel.html"><tt>QAbstractProxyModel</tt></a>, ensure that you emit <a href="QSqlRelationalTableModel.html#layoutAboutToBeChanged()"><tt>layoutAboutToBeChanged</tt></a> before changing the order of items or altering the structure of the data you expose to views, and emit <a href="QSqlRelationalTableModel.html#layoutChanged()"><tt>layoutChanged</tt></a> after changing the layout.</p> <p>Subclasses should update any persistent model indexes before emitting <a href="QSqlRelationalTableModel.html#layoutChanged()"><tt>layoutChanged</tt></a>.</p> <dl> <dt><b>Compatible Slot Signature:</b></dt> <dd><tt>void mySlot()</tt></dd> </dl> <dl> <dt><b>See Also:</b></dt> <dd><a href="QSqlRelationalTableModel.html#layoutAboutToBeChanged()"><tt>layoutAboutToBeChanged</tt></a>, <a href="QSqlRelationalTableModel.html#dataChanged(com.trolltech.qt.core.QModelIndex, com.trolltech.qt.core.QModelIndex)"><tt>dataChanged</tt></a>, <a href="QSqlRelationalTableModel.html#headerDataChanged(com.trolltech.qt.core.Qt.Orientation, int, int)"><tt>headerDataChanged</tt></a>, <a href="%2E%2E/core/%2E%2E/core/QAbstractItemModel.html#reset()"><tt>reset</tt></a>, <a href="%2E%2E/core/%2E%2E/core/QAbstractItemModel.html#changePersistentIndex(com.trolltech.qt.core.QModelIndex, com.trolltech.qt.core.QModelIndex)"><tt>changePersistentIndex</tt></a></dd> </dl> */"/> <signal name="protected final void primeInsert(int row, com.trolltech.qt.sql.QSqlRecord record)" doc="/** <p>This signal is emitted when an insertion is initiated in the given <tt>row</tt>. The <tt>record</tt> parameter can be written to (since it is a reference), for example to populate some fields with default values.</p> <dl> <dt><b>Compatible Slot Signatures:</b></dt> <dd><tt>void mySlot(int row, com.trolltech.qt.sql.QSqlRecord record)</tt></dd> <dd><tt>void mySlot(int row)</tt></dd> <dd><tt>void mySlot()</tt></dd> </dl> */"/> <method name="public QSqlRelationalTableModel(com.trolltech.qt.core.QObject parent, com.trolltech.qt.sql.QSqlDatabase db)" doc="/** <p>Creates an empty <a href="QSqlRelationalTableModel.html#QSqlRelationalTableModel(com.trolltech.qt.core.QObject, com.trolltech.qt.sql.QSqlDatabase)"><tt>QSqlRelationalTableModel</tt></a> and sets the parent to <tt>parent</tt> and the database connection to <tt>db</tt>. If <tt>db</tt> is not valid, the default database connection will be used.</p> */"/> <method name="public QSqlRelationalTableModel(com.trolltech.qt.core.QObject parent)" doc="/** <p>Equivalent to <a href="QSqlRelationalTableModel.html#QSqlRelationalTableModel(com.trolltech.qt.core.QObject, com.trolltech.qt.sql.QSqlDatabase)"><tt>QSqlRelationalTableModel</tt></a>(<tt>parent</tt>, QSqlDatabase()). */"/> <method name="public QSqlRelationalTableModel()" doc="/** <p>Equivalent to <a href="QSqlRelationalTableModel.html#QSqlRelationalTableModel(com.trolltech.qt.core.QObject, com.trolltech.qt.sql.QSqlDatabase)"><tt>QSqlRelationalTableModel</tt></a>(0, QSqlDatabase()). */"/> <method name="public final com.trolltech.qt.sql.QSqlRelation relation(int column)" doc="/** <p>Returns the relation for the column <tt>column</tt>, or an invalid relation if no relation is set.</p> @see <a href="QSqlRelationalTableModel.html#setRelation(int, com.trolltech.qt.sql.QSqlRelation)"><tt>setRelation</tt></a> @see <tt>QSqlRelation::isValid</tt> */"/> <method name="public void clear()" doc="/** <p>This function is reimplemented for internal reasons.</p> */"/> <method name="public java.lang.Object data(com.trolltech.qt.core.QModelIndex item, int role)" doc="/** <p>This function is reimplemented for internal reasons.</p> @see <a href="QSqlRelationalTableModel.html#setData(com.trolltech.qt.core.QModelIndex, java.lang.Object, int)"><tt>setData</tt></a> */"/> <method name="public final java.lang.Object data(com.trolltech.qt.core.QModelIndex item)" doc="/** <p>Equivalent to <a href="QSqlRelationalTableModel.html#data(com.trolltech.qt.core.QModelIndex, int)">data</tt></a>(<tt>item</tt>, Qt::DisplayRole). */"/> <method name="protected boolean insertRowIntoTable(com.trolltech.qt.sql.QSqlRecord values)" doc="/** <p>This function is reimplemented for internal reasons.</p> */"/> <method name="protected java.lang.String orderByClause()" doc="/** <p>This function is reimplemented for internal reasons.</p> */"/> <method name="public com.trolltech.qt.sql.QSqlTableModel relationModel(int column)" doc="/** <p>Returns a <a href="QSqlTableModel.html#QSqlTableModel(com.trolltech.qt.core.QObject, com.trolltech.qt.sql.QSqlDatabase)"><tt>QSqlTableModel</tt></a> object for accessing the table for which <tt>column</tt> is a foreign key, or 0 if there is no relation for the given <tt>column</tt>.</p> <p>The returned object is owned by the <a href="QSqlRelationalTableModel.html#QSqlRelationalTableModel(com.trolltech.qt.core.QObject, com.trolltech.qt.sql.QSqlDatabase)"><tt>QSqlRelationalTableModel</tt></a>.</p> @see <a href="QSqlRelationalTableModel.html#setRelation(int, com.trolltech.qt.sql.QSqlRelation)"><tt>setRelation</tt></a> @see <a href="QSqlRelationalTableModel.html#relation(int)"><tt>relation</tt></a> */"/> <method name="public boolean removeColumns(int column, int count, com.trolltech.qt.core.QModelIndex parent)" doc="/** <p>This function is reimplemented for internal reasons.</p> */"/> <method name="public final boolean removeColumns(int column, int count)" doc="/** <p>Equivalent to <a href="QSqlRelationalTableModel.html#removeColumns(int, int, com.trolltech.qt.core.QModelIndex)"><tt>removeColumns</tt></a>(<tt>column</tt>, <tt>count</tt>, QModelIndex()). */"/> <method name="public void revertRow(int row)" doc="/** <p>This function is reimplemented for internal reasons.</p> */"/> <method name="public boolean select()" doc="/** <p>This function is reimplemented for internal reasons.</p> */"/> <method name="protected java.lang.String selectStatement()" doc="/** <p>This function is reimplemented for internal reasons.</p> */"/> <method name="public boolean setData(com.trolltech.qt.core.QModelIndex item, java.lang.Object value, int role)" doc="/** <p>Sets the data for the <tt>role</tt> in the item with the specified <tt>item</tt> to the <tt>value</tt> given. Depending on the edit strategy, the value might be applied to the database at once, or it may be cached in the model.</p> <p>Returns true if the value could be set, or false on error (for example, if <tt>item</tt> is out of bounds).</p> <p>For relational columns, <tt>value</tt> must be the index, not the display value.</p> @see <a href="QSqlTableModel.html#editStrategy()"><tt>editStrategy</tt></a> @see <a href="QSqlRelationalTableModel.html#data(com.trolltech.qt.core.QModelIndex, int)"><tt>data</tt></a> @see <a href="QSqlTableModel.html#submit()"><tt>submit</tt></a> @see <a href="QSqlRelationalTableModel.html#revertRow(int)"><tt>revertRow</tt></a> */"/> <method name="public final boolean setData(com.trolltech.qt.core.QModelIndex item, java.lang.Object value)" doc="/** <p>Equivalent to <a href="QSqlRelationalTableModel.html#setData(com.trolltech.qt.core.QModelIndex, java.lang.Object, int)"><tt>setData</tt></a>(<tt>item</tt>, <tt>value</tt>, Qt::EditRole). */"/> <method name="public void setRelation(int column, com.trolltech.qt.sql.QSqlRelation relation)" doc="/** <p>Lets the specified <tt>column</tt> be a foreign index specified by <tt>relation</tt>.</p> <p>Example:</p> <pre> model-&gt;setTable(&quot;employee&quot;); model-&gt;setRelation(2, QSqlRelation(&quot;city&quot;, &quot;id&quot;, &quot;name&quot;));</pre> <p>The <a href="QSqlRelationalTableModel.html#setRelation(int, com.trolltech.qt.sql.QSqlRelation)"><tt>setRelation</tt></a> call specifies that column 2 in table <tt>employee</tt> is a foreign key that maps with field <tt>id</tt> of table <tt>city</tt>, and that the view should present the <tt>city</tt>'s <tt>name</tt> field to the user.</p> <p>Note: The table's primary key may not contain a relation to another table.</p> @see <a href="QSqlRelationalTableModel.html#relation(int)"><tt>relation</tt></a> */"/> <method name="public void setTable(java.lang.String tableName)" doc="/** <p>This function is reimplemented for internal reasons.</p> */"/> <method name="protected boolean updateRowInTable(int row, com.trolltech.qt.sql.QSqlRecord values)" doc="/** <p>This function is reimplemented for internal reasons.</p> */"/> </class>