Sophie

Sophie

distrib > Mandriva > current > i586 > media > main-updates > by-pkgid > 8e6051afcdb111a0317a58fb64c2abf5 > files > 4915

qt4-doc-4.6.3-0.2mdv2010.2.i586.rpm

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- qsqlrelationaltablemodel.cpp -->
<head>
  <title>Qt 4.6: QSqlRelationalTableModel Class Reference</title>
  <link href="classic.css" rel="stylesheet" type="text/css" />
</head>
<body>
<a name="//apple_ref/cpp/cl//QSqlRelationalTableModel"></a>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" valign="top" width="32"><a href="http://qt.nokia.com/"><img src="images/qt-logo.png" align="left" border="0" /></a></td>
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">All&nbsp;Functions</font></a>&nbsp;&middot; <a href="overviews.html"><font color="#004faf">Overviews</font></a></td></tr></table><h1 class="title">QSqlRelationalTableModel Class Reference<br /><span class="small-subtitle">[<a href="qtsql.html">QtSql</a> module]</span>
</h1>
<p>The QSqlRelationalTableModel class provides an editable data model for a single database table, with foreign key support. <a href="#details">More...</a></p>
<pre> #include &lt;QSqlRelationalTableModel&gt;</pre><p><b>This class is not part of the Qt GUI Framework Edition.</b></p>
<p>Inherits <a href="qsqltablemodel.html">QSqlTableModel</a>.</p>
<ul>
<li><a href="qsqlrelationaltablemodel-members.html">List of all members, including inherited members</a></li>
</ul>
<hr />
<a name="public-functions"></a>
<h2>Public Functions</h2>
<table class="alignedsummary" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr><td class="memItemLeft" align="right" valign="top"></td><td class="memItemRight" valign="bottom"><b><a href="qsqlrelationaltablemodel.html#QSqlRelationalTableModel">QSqlRelationalTableModel</a></b> ( QObject * <i>parent</i> = 0, QSqlDatabase <i>db</i> = QSqlDatabase() )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual </td><td class="memItemRight" valign="bottom"><b><a href="qsqlrelationaltablemodel.html#dtor.QSqlRelationalTableModel">~QSqlRelationalTableModel</a></b> ()</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">QSqlRelation </td><td class="memItemRight" valign="bottom"><b><a href="qsqlrelationaltablemodel.html#relation">relation</a></b> ( int <i>column</i> ) const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual QSqlTableModel * </td><td class="memItemRight" valign="bottom"><b><a href="qsqlrelationaltablemodel.html#relationModel">relationModel</a></b> ( int <i>column</i> ) const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual void </td><td class="memItemRight" valign="bottom"><b><a href="qsqlrelationaltablemodel.html#setRelation">setRelation</a></b> ( int <i>column</i>, const QSqlRelation &amp; <i>relation</i> )</td></tr>
</table>
<hr />
<a name="reimplemented-public-functions"></a>
<h2>Reimplemented Public Functions</h2>
<table class="alignedsummary" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr><td class="memItemLeft" align="right" valign="top">virtual void </td><td class="memItemRight" valign="bottom"><b><a href="qsqlrelationaltablemodel.html#clear">clear</a></b> ()</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual QVariant </td><td class="memItemRight" valign="bottom"><b><a href="qsqlrelationaltablemodel.html#data">data</a></b> ( const QModelIndex &amp; <i>index</i>, int <i>role</i> = Qt::DisplayRole ) const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual bool </td><td class="memItemRight" valign="bottom"><b><a href="qsqlrelationaltablemodel.html#removeColumns">removeColumns</a></b> ( int <i>column</i>, int <i>count</i>, const QModelIndex &amp; <i>parent</i> = QModelIndex() )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual bool </td><td class="memItemRight" valign="bottom"><b><a href="qsqlrelationaltablemodel.html#select">select</a></b> ()</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual bool </td><td class="memItemRight" valign="bottom"><b><a href="qsqlrelationaltablemodel.html#setData">setData</a></b> ( const QModelIndex &amp; <i>index</i>, const QVariant &amp; <i>value</i>, int <i>role</i> = Qt::EditRole )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual void </td><td class="memItemRight" valign="bottom"><b><a href="qsqlrelationaltablemodel.html#setTable">setTable</a></b> ( const QString &amp; <i>table</i> )</td></tr>
</table>
<ul>
<li><div bar="2" class="fn"></div>25 public functions inherited from <a href="qsqltablemodel.html#public-functions">QSqlTableModel</a></li>
<li><div bar="2" class="fn"></div>16 public functions inherited from <a href="qsqlquerymodel.html#public-functions">QSqlQueryModel</a></li>
<li><div bar="2" class="fn"></div>2 public functions inherited from <a href="qabstracttablemodel.html#public-functions">QAbstractTableModel</a></li>
<li><div bar="2" class="fn"></div>35 public functions inherited from <a href="qabstractitemmodel.html#public-functions">QAbstractItemModel</a></li>
<li><div bar="2" class="fn"></div>29 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li>
</ul>
<hr />
<a name="public-slots"></a>
<h2>Public Slots</h2>
<table class="alignedsummary" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr><td class="memItemLeft" align="right" valign="top">virtual void </td><td class="memItemRight" valign="bottom"><b><a href="qsqlrelationaltablemodel.html#revertRow">revertRow</a></b> ( int <i>row</i> )</td></tr>
</table>
<ul>
<li><div bar="2" class="fn"></div>4 public slots inherited from <a href="qsqltablemodel.html#public-slots">QSqlTableModel</a></li>
<li><div bar="2" class="fn"></div>2 public slots inherited from <a href="qabstractitemmodel.html#public-slots">QAbstractItemModel</a></li>
<li><div bar="2" class="fn"></div>1 public slot inherited from <a href="qobject.html#public-slots">QObject</a></li>
</ul>
<hr />
<a name="reimplemented-protected-functions"></a>
<h2>Reimplemented Protected Functions</h2>
<table class="alignedsummary" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr><td class="memItemLeft" align="right" valign="top">virtual bool </td><td class="memItemRight" valign="bottom"><b><a href="qsqlrelationaltablemodel.html#insertRowIntoTable">insertRowIntoTable</a></b> ( const QSqlRecord &amp; <i>values</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual QString </td><td class="memItemRight" valign="bottom"><b><a href="qsqlrelationaltablemodel.html#orderByClause">orderByClause</a></b> () const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual QString </td><td class="memItemRight" valign="bottom"><b><a href="qsqlrelationaltablemodel.html#selectStatement">selectStatement</a></b> () const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual bool </td><td class="memItemRight" valign="bottom"><b><a href="qsqlrelationaltablemodel.html#updateRowInTable">updateRowInTable</a></b> ( int <i>row</i>, const QSqlRecord &amp; <i>values</i> )</td></tr>
</table>
<ul>
<li><div bar="2" class="fn"></div>8 protected functions inherited from <a href="qsqltablemodel.html#protected-functions">QSqlTableModel</a></li>
<li><div bar="2" class="fn"></div>3 protected functions inherited from <a href="qsqlquerymodel.html#protected-functions">QSqlQueryModel</a></li>
<li><div bar="2" class="fn"></div>21 protected functions inherited from <a href="qabstractitemmodel.html#protected-functions">QAbstractItemModel</a></li>
<li><div bar="2" class="fn"></div>7 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li>
</ul>
<h3>Additional Inherited Members</h3>
<ul>
<li><div class="fn"></div>1 property inherited from <a href="qobject.html#properties">QObject</a></li>
<li><div class="fn"></div>4 signals inherited from <a href="qsqltablemodel.html#signals">QSqlTableModel</a></li>
<li><div class="fn"></div>18 signals inherited from <a href="qabstractitemmodel.html#signals">QAbstractItemModel</a></li>
<li><div class="fn"></div>1 signal inherited from <a href="qobject.html#signals">QObject</a></li>
<li><div class="fn"></div>5 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li>
<li><div class="fn"></div>8 protected functions inherited from <a href="qsqltablemodel.html#protected-functions">QSqlTableModel</a></li>
<li><div class="fn"></div>3 protected functions inherited from <a href="qsqlquerymodel.html#protected-functions">QSqlQueryModel</a></li>
<li><div class="fn"></div>21 protected functions inherited from <a href="qabstractitemmodel.html#protected-functions">QAbstractItemModel</a></li>
<li><div class="fn"></div>7 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li>
</ul>
<a name="details"></a>
<hr />
<h2>Detailed Description</h2>
<p>The QSqlRelationalTableModel class provides an editable data model for a single database table, with foreign key support.</p>
<p>QSqlRelationalTableModel acts like <a href="qsqltablemodel.html">QSqlTableModel</a>, but allows columns to be set as foreign keys into other database tables.</p>
<p><table class="generic" align="center" cellpadding="2" cellspacing="1" border="0">
<tr valign="top" class="odd"><td><img src="images/noforeignkeys.png" /></td><td><img src="images/foreignkeys.png" /></td></tr>
</table></p>
<p>The screenshot on the left shows a plain <a href="qsqltablemodel.html">QSqlTableModel</a> in a <a href="qtableview.html">QTableView</a>. Foreign keys (<tt>city</tt> and <tt>country</tt>) aren't resolved to human-readable values. The screenshot on the right shows a QSqlRelationalTableModel, with foreign keys resolved into human-readable text strings.</p>
<p>The following code snippet shows how the QSqlRelationalTableModel 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">setRelation</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 QSqlRelationalTableModel, you probably want to use <a href="qsqlrelationaldelegate.html">QSqlRelationalDelegate</a> on the view. Unlike the default delegate, <a href="qsqlrelationaldelegate.html">QSqlRelationalDelegate</a> provides a combobox for fields that are foreign keys into other tables. To use the class, simply call <a href="qabstractitemview.html#setItemDelegate">QAbstractItemView::setItemDelegate</a>() on the view with an instance of <a href="qsqlrelationaldelegate.html">QSqlRelationalDelegate</a>:</p>
<pre>     QTableView *view = new QTableView;
     view-&gt;setModel(model);
     view-&gt;setItemDelegate(new QSqlRelationalDelegate(view));</pre>
<p>The <a href="sql-relationaltablemodel.html">sql/relationaltablemodel</a> example illustrates how to use QSqlRelationalTableModel in conjunction with <a href="qsqlrelationaldelegate.html">QSqlRelationalDelegate</a> to provide tables with foreigh key support.</p>
<p align="center"><img src="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>
<li>If a relation's display column name is also used as a column name in the main table, or if it is used as display column name in more than one relation it will be aliased. The alias is is the relation's table name and display column name joined by an underscore (e.g&#x2e; tablename_columnname). All occurrences of the duplicate display column name are aliased when duplication is detected, but no aliasing is done to the column names in the main table. The aliasing doesn't affect <a href="qsqlrelation.html">QSqlRelation</a>, so <a href="qsqlrelation.html#displayColumn">QSqlRelation::displayColumn</a>() will return the original display column name, but <a href="qsqlrecord.html#fieldName">QSqlRecord::fieldName</a>() will return aliases.</li>
<li>When using <a href="qsqlrelationaltablemodel.html#setData">setData</a>() the role should always be <a href="qt.html#ItemDataRole-enum">Qt::EditRole</a>, and when using <a href="qsqlrelationaltablemodel.html#data">data</a>() the role should always be <a href="qt.html#ItemDataRole-enum">Qt::DisplayRole</a>.</li>
</ul>
<p>See also <a href="qsqlrelation.html">QSqlRelation</a>, <a href="qsqlrelationaldelegate.html">QSqlRelationalDelegate</a>, and <a href="sql-relationaltablemodel.html">Relational Table Model Example</a>.</p>
<hr />
<h2>Member Function Documentation</h2>
<a name="//apple_ref/cpp/instm/QSqlRelationalTableModel/QSqlRelationalTableModel"></a>
<h3 class="fn"><a name="QSqlRelationalTableModel"></a>QSqlRelationalTableModel::QSqlRelationalTableModel ( <a href="qobject.html">QObject</a> * <i>parent</i> = 0, <a href="qsqldatabase.html">QSqlDatabase</a> <i>db</i> = QSqlDatabase() )</h3>
<p>Creates an empty <a href="qsqlrelationaltablemodel.html">QSqlRelationalTableModel</a> and sets the parent to <i>parent</i> and the database connection to <i>db</i>. If <i>db</i> is not valid, the default database connection will be used.</p>
<a name="//apple_ref/cpp/instm/QSqlRelationalTableModel/~QSqlRelationalTableModel"></a>
<h3 class="fn"><a name="dtor.QSqlRelationalTableModel"></a>QSqlRelationalTableModel::~QSqlRelationalTableModel ()&nbsp;&nbsp;<tt> [virtual]</tt></h3>
<p>Destroys the object and frees any allocated resources.</p>
<a name="//apple_ref/cpp/instm/QSqlRelationalTableModel/clear"></a>
<h3 class="fn"><a name="clear"></a>void QSqlRelationalTableModel::clear ()&nbsp;&nbsp;<tt> [virtual]</tt></h3>
<p>Reimplemented from <a href="qsqlquerymodel.html#clear">QSqlQueryModel::clear</a>().</p>
<a name="//apple_ref/cpp/instm/QSqlRelationalTableModel/data"></a>
<h3 class="fn"><a name="data"></a><a href="qvariant.html">QVariant</a> QSqlRelationalTableModel::data ( const <a href="qmodelindex.html">QModelIndex</a> &amp; <i>index</i>, int <i>role</i> = Qt::DisplayRole ) const&nbsp;&nbsp;<tt> [virtual]</tt></h3>
<p>Reimplemented from <a href="qabstractitemmodel.html#data">QAbstractItemModel::data</a>().</p>
<p>See also <a href="qsqlrelationaltablemodel.html#setData">setData</a>().</p>
<a name="//apple_ref/cpp/instm/QSqlRelationalTableModel/insertRowIntoTable"></a>
<h3 class="fn"><a name="insertRowIntoTable"></a>bool QSqlRelationalTableModel::insertRowIntoTable ( const <a href="qsqlrecord.html">QSqlRecord</a> &amp; <i>values</i> )&nbsp;&nbsp;<tt> [virtual protected]</tt></h3>
<p>Reimplemented from <a href="qsqltablemodel.html#insertRowIntoTable">QSqlTableModel::insertRowIntoTable</a>().</p>
<a name="//apple_ref/cpp/instm/QSqlRelationalTableModel/orderByClause"></a>
<h3 class="fn"><a name="orderByClause"></a><a href="qstring.html">QString</a> QSqlRelationalTableModel::orderByClause () const&nbsp;&nbsp;<tt> [virtual protected]</tt></h3>
<p>Reimplemented from <a href="qsqltablemodel.html#orderByClause">QSqlTableModel::orderByClause</a>().</p>
<a name="//apple_ref/cpp/instm/QSqlRelationalTableModel/relation"></a>
<h3 class="fn"><a name="relation"></a><a href="qsqlrelation.html">QSqlRelation</a> QSqlRelationalTableModel::relation ( int <i>column</i> ) const</h3>
<p>Returns the relation for the column <i>column</i>, or an invalid relation if no relation is set.</p>
<p>See also <a href="qsqlrelationaltablemodel.html#setRelation">setRelation</a>() and <a href="qsqlrelation.html#isValid">QSqlRelation::isValid</a>().</p>
<a name="//apple_ref/cpp/instm/QSqlRelationalTableModel/relationModel"></a>
<h3 class="fn"><a name="relationModel"></a><a href="qsqltablemodel.html">QSqlTableModel</a> * QSqlRelationalTableModel::relationModel ( int <i>column</i> ) const&nbsp;&nbsp;<tt> [virtual]</tt></h3>
<p>Returns a <a href="qsqltablemodel.html">QSqlTableModel</a> object for accessing the table for which <i>column</i> is a foreign key, or 0 if there is no relation for the given <i>column</i>.</p>
<p>The returned object is owned by the <a href="qsqlrelationaltablemodel.html">QSqlRelationalTableModel</a>.</p>
<p>See also <a href="qsqlrelationaltablemodel.html#setRelation">setRelation</a>() and <a href="qsqlrelationaltablemodel.html#relation">relation</a>().</p>
<a name="//apple_ref/cpp/instm/QSqlRelationalTableModel/removeColumns"></a>
<h3 class="fn"><a name="removeColumns"></a>bool QSqlRelationalTableModel::removeColumns ( int <i>column</i>, int <i>count</i>, const <a href="qmodelindex.html">QModelIndex</a> &amp; <i>parent</i> = QModelIndex() )&nbsp;&nbsp;<tt> [virtual]</tt></h3>
<p>Reimplemented from <a href="qabstractitemmodel.html#removeColumns">QAbstractItemModel::removeColumns</a>().</p>
<a name="//apple_ref/cpp/instm/QSqlRelationalTableModel/revertRow"></a>
<h3 class="fn"><a name="revertRow"></a>void QSqlRelationalTableModel::revertRow ( int <i>row</i> )&nbsp;&nbsp;<tt> [virtual slot]</tt></h3>
<p>Reimplemented from <a href="qsqltablemodel.html#revertRow">QSqlTableModel::revertRow</a>().</p>
<a name="//apple_ref/cpp/instm/QSqlRelationalTableModel/select"></a>
<h3 class="fn"><a name="select"></a>bool QSqlRelationalTableModel::select ()&nbsp;&nbsp;<tt> [virtual]</tt></h3>
<p>Reimplemented from <a href="qsqltablemodel.html#select">QSqlTableModel::select</a>().</p>
<a name="//apple_ref/cpp/instm/QSqlRelationalTableModel/selectStatement"></a>
<h3 class="fn"><a name="selectStatement"></a><a href="qstring.html">QString</a> QSqlRelationalTableModel::selectStatement () const&nbsp;&nbsp;<tt> [virtual protected]</tt></h3>
<p>Reimplemented from <a href="qsqltablemodel.html#selectStatement">QSqlTableModel::selectStatement</a>().</p>
<a name="//apple_ref/cpp/instm/QSqlRelationalTableModel/setData"></a>
<h3 class="fn"><a name="setData"></a>bool QSqlRelationalTableModel::setData ( const <a href="qmodelindex.html">QModelIndex</a> &amp; <i>index</i>, const <a href="qvariant.html">QVariant</a> &amp; <i>value</i>, int <i>role</i> = Qt::EditRole )&nbsp;&nbsp;<tt> [virtual]</tt></h3>
<p>Reimplemented from <a href="qabstractitemmodel.html#setData">QAbstractItemModel::setData</a>().</p>
<p>Sets the data for the <i>role</i> in the item with the specified <i>index</i> to the <i>value</i> 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 <i>index</i> is out of bounds).</p>
<p>For relational columns, <i>value</i> must be the index, not the display value. The index must also exist in the referenced table, otherwise the function returns false.</p>
<p>See also <a href="qsqltablemodel.html#editStrategy">editStrategy</a>(), <a href="qsqlrelationaltablemodel.html#data">data</a>(), <a href="qsqltablemodel.html#submit">submit</a>(), and <a href="qsqlrelationaltablemodel.html#revertRow">revertRow</a>().</p>
<a name="//apple_ref/cpp/instm/QSqlRelationalTableModel/setRelation"></a>
<h3 class="fn"><a name="setRelation"></a>void QSqlRelationalTableModel::setRelation ( int <i>column</i>, const <a href="qsqlrelation.html">QSqlRelation</a> &amp; <i>relation</i> )&nbsp;&nbsp;<tt> [virtual]</tt></h3>
<p>Lets the specified <i>column</i> be a foreign index specified by <i>relation</i>.</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 setRelation() 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>
<p>See also <a href="qsqlrelationaltablemodel.html#relation">relation</a>().</p>
<a name="//apple_ref/cpp/instm/QSqlRelationalTableModel/setTable"></a>
<h3 class="fn"><a name="setTable"></a>void QSqlRelationalTableModel::setTable ( const <a href="qstring.html">QString</a> &amp; <i>table</i> )&nbsp;&nbsp;<tt> [virtual]</tt></h3>
<p>Reimplemented from <a href="qsqltablemodel.html#setTable">QSqlTableModel::setTable</a>().</p>
<a name="//apple_ref/cpp/instm/QSqlRelationalTableModel/updateRowInTable"></a>
<h3 class="fn"><a name="updateRowInTable"></a>bool QSqlRelationalTableModel::updateRowInTable ( int <i>row</i>, const <a href="qsqlrecord.html">QSqlRecord</a> &amp; <i>values</i> )&nbsp;&nbsp;<tt> [virtual protected]</tt></h3>
<p>Reimplemented from <a href="qsqltablemodel.html#updateRowInTable">QSqlTableModel::updateRowInTable</a>().</p>
<p /><address><hr /><div align="center">
<table width="100%" cellspacing="0" border="0"><tr class="address">
<td width="40%" align="left">Copyright &copy; 2010 Nokia Corporation and/or its subsidiary(-ies)</td>
<td width="20%" align="center"><a href="trademarks.html">Trademarks</a></td>
<td width="40%" align="right"><div align="right">Qt 4.6.3</div></td>
</tr></table></div></address></body>
</html>