|
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.core.QObject
com.trolltech.qt.core.QAbstractItemModel
com.trolltech.qt.gui.QAbstractTableModel
com.trolltech.qt.sql.QSqlQueryModel
com.trolltech.qt.sql.QSqlTableModel
com.trolltech.qt.sql.QSqlRelationalTableModel
public class QSqlRelationalTableModel
The QSqlRelationalTableModel class provides an editable data model for a single database table, with foreign key support.
QSqlRelationalTableModel acts like QSqlTableModel, but allows columns to be set as foreign keys into other database tables.
![]() | ![]() |
The screenshot on the left shows a plain QSqlTableModel in a QTableView. Foreign keys (city and country) aren't resolved to human-readable values. The screenshot on the right shows a QSqlRelationalTableModel, with foreign keys resolved into human-readable text strings.
The following code snippet shows how the QSqlRelationalTableModel was set up:
model->setTable("employee"); model->setRelation(2, QSqlRelation("city", "id", "name")); model->setRelation(3, QSqlRelation("country", "id", "name"));
The setRelation function calls establish a relationship between two tables. The first call specifies that column 2 in table employee is a foreign key that maps with field id of table city, and that the view should present the city's name field to the user. The second call does something similar with column 3.
If you use a read-write QSqlRelationalTableModel, 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:
QTableView *view = new QTableView; view->setModel(model); view->setItemDelegate(new QSqlRelationalDelegate(view));
The sql/relationaltablemodel example illustrates how to use QSqlRelationalTableModel in conjunction with QSqlRelationalDelegate to provide tables with foreigh key support.
Notes:
Table Model Example
Nested Class Summary |
---|
Nested classes/interfaces inherited from class com.trolltech.qt.sql.QSqlTableModel |
---|
QSqlTableModel.EditStrategy |
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter |
---|
QSignalEmitter.AbstractSignal, QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I> |
Field Summary |
---|
Fields inherited from class com.trolltech.qt.sql.QSqlTableModel |
---|
beforeDelete, beforeInsert, beforeUpdate, primeInsert |
Fields inherited from class com.trolltech.qt.core.QAbstractItemModel |
---|
dataChanged, headerDataChanged, layoutAboutToBeChanged, layoutChanged |
Constructor Summary | |
---|---|
QSqlRelationalTableModel()
Equivalent to QSqlRelationalTableModel(0, QSqlDatabase()). |
|
QSqlRelationalTableModel(QObject parent)
Equivalent to QSqlRelationalTableModel(parent, QSqlDatabase()). |
|
QSqlRelationalTableModel(QObject parent,
QSqlDatabase db)
Creates an empty QSqlRelationalTableModel and sets the parent to parent and the database connection to db. |
Method Summary | |
---|---|
void |
clear()
This function is reimplemented for internal reasons. |
java.lang.Object |
data(QModelIndex item,
int role)
This function is reimplemented for internal reasons. |
static QSqlRelationalTableModel |
fromNativePointer(QNativePointer nativePointer)
This function returns the QSqlRelationalTableModel instance pointed to by nativePointer |
protected boolean |
insertRowIntoTable(QSqlRecord values)
This function is reimplemented for internal reasons. |
protected java.lang.String |
orderByClause()
This function is reimplemented for internal reasons. |
QSqlRelation |
relation(int column)
Returns the relation for the column column, or an invalid relation if no relation is set. |
QSqlTableModel |
relationModel(int column)
Returns a QSqlTableModel object for accessing the table for which column is a foreign key, or 0 if there is no relation for the given column. |
boolean |
removeColumns(int column,
int count,
QModelIndex parent)
This function is reimplemented for internal reasons. |
void |
revertRow(int row)
This function is reimplemented for internal reasons. |
boolean |
select()
This function is reimplemented for internal reasons. |
protected java.lang.String |
selectStatement()
This function is reimplemented for internal reasons. |
boolean |
setData(QModelIndex item,
java.lang.Object value,
int role)
Sets the data for the role in the item with the specified item to the value given. |
void |
setRelation(int column,
QSqlRelation relation)
Lets the specified column be a foreign index specified by relation. |
void |
setTable(java.lang.String tableName)
This function is reimplemented for internal reasons. |
protected boolean |
updateRowInTable(int row,
QSqlRecord values)
This function is reimplemented for internal reasons. |
Methods inherited from class com.trolltech.qt.sql.QSqlTableModel |
---|
database, deleteRowFromTable, editStrategy, fieldIndex, filter, flags, headerData, indexInQuery, insertRecord, insertRows, isDirty, primaryKey, removeRows, revert, revertAll, rowCount, setEditStrategy, setFilter, setPrimaryKey, setQuery, setRecord, setSort, sort, submit, submitAll, tableName |
Methods inherited from class com.trolltech.qt.sql.QSqlQueryModel |
---|
canFetchMore, columnCount, fetchMore, insertColumns, lastError, query, queryChange, record, record, setHeaderData, setLastError, setQuery, setQuery |
Methods inherited from class com.trolltech.qt.gui.QAbstractTableModel |
---|
dropMimeData, hasChildren, index, parent |
Methods inherited from class com.trolltech.qt.core.QAbstractItemModel |
---|
beginInsertColumns, beginInsertRows, beginRemoveColumns, beginRemoveRows, buddy, changePersistentIndex, changePersistentIndexList, columnCount, createIndex, createIndex, createIndex, data, data, data, decodeData, encodeData, endInsertColumns, endInsertRows, endRemoveColumns, endRemoveRows, hasChildren, hasIndex, hasIndex, headerData, index, insertColumn, insertColumn, insertColumns, insertRow, insertRow, insertRows, itemData, match, match, match, match, mimeData, mimeTypes, persistentIndexList, removeColumn, removeColumn, removeColumns, removeRow, removeRow, removeRows, reset, rowCount, setData, setData, setData, setHeaderData, setItemData, setSupportedDragActions, setSupportedDragActions, sibling, sort, span, supportedDragActions, supportedDropActions |
Methods inherited from class com.trolltech.qt.core.QObject |
---|
blockSignals, childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, property, removeEventFilter, setObjectName, setParent, setProperty, signalsBlocked, startTimer, thread, timerEvent |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
disconnect, disconnect, signalSender |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Constructor Detail |
---|
public QSqlRelationalTableModel(QObject parent)
Equivalent to QSqlRelationalTableModel(parent, QSqlDatabase()).
public QSqlRelationalTableModel()
Equivalent to QSqlRelationalTableModel(0, QSqlDatabase()).
public QSqlRelationalTableModel(QObject parent, QSqlDatabase db)
Creates an empty QSqlRelationalTableModel and sets the parent to parent and the database connection to db. If db is not valid, the default database connection will be used.
Method Detail |
---|
public final QSqlRelation relation(int column)
Returns the relation for the column column, or an invalid relation if no relation is set.
public void clear()
This function is reimplemented for internal reasons.
clear
in class QSqlTableModel
public java.lang.Object data(QModelIndex item, int role)
This function is reimplemented for internal reasons.
data
in class QSqlTableModel
protected boolean insertRowIntoTable(QSqlRecord values)
This function is reimplemented for internal reasons.
insertRowIntoTable
in class QSqlTableModel
protected java.lang.String orderByClause()
This function is reimplemented for internal reasons.
orderByClause
in class QSqlTableModel
public QSqlTableModel relationModel(int column)
Returns a QSqlTableModel object for accessing the table for which column is a foreign key, or 0 if there is no relation for the given column.
The returned object is owned by the QSqlRelationalTableModel.
public boolean removeColumns(int column, int count, QModelIndex parent)
This function is reimplemented for internal reasons.
removeColumns
in class QSqlTableModel
public void revertRow(int row)
This function is reimplemented for internal reasons.
revertRow
in class QSqlTableModel
public boolean select()
This function is reimplemented for internal reasons.
select
in class QSqlTableModel
protected java.lang.String selectStatement()
This function is reimplemented for internal reasons.
selectStatement
in class QSqlTableModel
public boolean setData(QModelIndex item, java.lang.Object value, int role)
Sets the data for the role in the item with the specified item to the value given. Depending on the edit strategy, the value might be applied to the database at once, or it may be cached in the model.
Returns true if the value could be set, or false on error (for example, if item is out of bounds).
For relational columns, value must be the index, not the display value.
setData
in class QSqlTableModel
public void setRelation(int column, QSqlRelation relation)
Lets the specified column be a foreign index specified by relation.
Example:
model->setTable("employee"); model->setRelation(2, QSqlRelation("city", "id", "name"));
The setRelation call specifies that column 2 in table employee is a foreign key that maps with field id of table city, and that the view should present the city's name field to the user.
Note: The table's primary key may not contain a relation to another table.
public void setTable(java.lang.String tableName)
This function is reimplemented for internal reasons.
setTable
in class QSqlTableModel
protected boolean updateRowInTable(int row, QSqlRecord values)
This function is reimplemented for internal reasons.
updateRowInTable
in class QSqlTableModel
public static QSqlRelationalTableModel fromNativePointer(QNativePointer nativePointer)
nativePointer
- the QNativePointer of which object should be returned.
|
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |