When displaying data, TQDataTable only retrieves data for visible rows. If the driver supports the 'query size' property the TQDataTable will have the correct number of rows and the vertical scrollbar will accurately reflect the number of rows displayed in proportion to the number of rows in the dataset. If the driver does not support the 'query size' property, rows are dynamically fetched from the database on an as-needed basis with the scrollbar becoming more accurate as the user scrolls down through the records. This allows extremely large queries to be displayed as quickly as possible, with minimum memory usage.
TQDataTable inherits TQTable's API and extends it with functions to sort and filter the data and sort columns. See setSqlCursor(), setFilter(), setSort(), setSorting(), sortColumn() and refresh().
When displaying editable cursors, cell editing will be enabled. (For more information on editable cursors, see TQSqlCursor). TQDataTable can be used to modify existing data and to add new records. When a user makes changes to a field in the table, the cursor's edit buffer is used. The table will not send changes in the edit buffer to the database until the user moves to a different record in the grid or presses Enter. Cell editing is initiated by pressing F2 (or right clicking and then clicking the appropriate popup menu item) and canceled by pressing Esc. If there is a problem updating or adding data, errors are handled automatically (see handleError() to change this behavior). Note that if autoEdit() is FALSE navigating to another record will cancel the insert or update.
The user can be asked to confirm all edits with setConfirmEdits(). For more precise control use setConfirmInsert(), setConfirmUpdate(), setConfirmDelete() and setConfirmCancels(). Use setAutoEdit() to control the behaviour of the table when the user edits a record and then navigates. (Note that setAutoDelete() is unrelated; it is used to set whether the TQSqlCursor is deleted when the table is deleted.)
Since the data table can perform edits, it must be able to uniquely identify every record so that edits are correctly applied. Because of this the underlying cursor must have a valid primary index to ensure that a unique record is inserted, updated or deleted within the database otherwise the database may be changed to an inconsistent state.
TQDataTable creates editors using the default TQSqlEditorFactory. Different editor factories can be used by calling installEditorFactory(). A property map is used to map between the cell's value and the editor. You can use your own property map with installPropertyMap().
The contents of a cell is available as a TQString with text() or as a TQVariant with value(). The current record is returned by currentRecord(). Use the find() function to search for a string in the table.
Editing actions can be applied programatically. For example, the insertCurrent() function reads the fields from the current record into the cursor and performs the insert. The updateCurrent() and deleteCurrent() functions perform similarly to update and delete the current record respectively.
.PP
Columns in the table can be created automatically based on the cursor (see setSqlCursor()). Columns can be manipulated manually using addColumn(), removeColumn() and setColumn().
The table automatically copies many of the properties of the cursor to format the display of data within cells (alignment, visibility, etc.). The cursor can be changed with setSqlCursor(). The filter (see setFilter()) and sort defined within the table are used instead of the filter and sort set on the cursor. For sorting options see setSort(), sortColumn(), sortAscending() and sortDescending(). Note that sorting operations will not behave as expected if you are using a TQSqlSelectCursor because it uses user-defined SQL queries to obtain data.
The text used to represent NULL, TRUE and FALSE values can be changed with setNullText(), setTrueText() and setFalseText() respectively. You can change the appearance of cells by reimplementing paintField().
.PP
Whenever a new row is selected in the table the currentChanged() signal is emitted. The primeInsert() signal is emitted when an insert is initiated. The primeUpdate() and primeDelete() signals are emitted when update and deletion are initiated respectively. Just before the database is updated a signal is emitted; beforeInsert(), beforeUpdate() or beforeDelete() as appropriate.
Constructs a data table which is a child of \fIparent\fR, called name \fIname\fR using the cursor \fIcursor\fR.
.PP
If \fIautoPopulate\fR is TRUE (the default is FALSE), columns are automatically created based upon the fields in the \fIcursor\fR record. Note that \fIautoPopulate\fR only governs the creation of columns; to load the cursor's data into the table use refresh().
.PP
If the \fIcursor\fR is read-only, the table also becomes read-only. In addition, the table adopts the cursor's driver's definition for representing NULL values as strings.
Adds the next column to be displayed using the field \fIfieldName\fR, column label \fIlabel\fR, width \fIwidth\fR and iconset \fIiconset\fR.
.PP
If \fIlabel\fR is specified, it is used as the column's header label, otherwise the field's display label is used when setSqlCursor() is called. The \fIiconset\fR is used to set the icon used by the column header; by default there is no icon.
.PP
See also setSqlCursor() and refresh().
.PP
Examples:
.)l sql/overview/subclass1/main.cpp, sql/overview/subclass3/main.cpp, sql/overview/table2/main.cpp, and sql/sqltable/main.cpp.
.SH "void TQDataTable::adjustColumn ( int col )\fC [virtual slot]\fR"
Resizes column \fIcol\fR so that the column width is wide enough to display the widest item the column contains (including the column label). If the table's TQSqlCursor is not currently active, the cursor will be refreshed before the column width is calculated. Be aware that this function may be slow on tables that contain large result sets.
This signal is emitted just before the currently selected record is deleted from the database. The \fIbuf\fR parameter points to the edit buffer being deleted. Connect to this signal to, for example, copy some of the fields for later use.
This signal is emitted just before the cursor's edit buffer is inserted into the database. The \fIbuf\fR parameter points to the edit buffer being inserted. Connect to this signal to, for example, populate a key field with a unique sequence number.
This signal is emitted just before the cursor's edit buffer is updated in the database. The \fIbuf\fR parameter points to the edit buffer being updated. Connect to this signal when you want to transform the user's data behind-the-scenes.
Protected virtual function called when editing is about to begin on a new record. If the table is read-only, or if there's no cursor or the cursor does not allow inserts, nothing happens.
Protected virtual function called when editing is about to begin on an existing row. If the table is read-only, or if there's no cursor, nothing happens.
Protected virtual function which returns a confirmation for cancelling an edit mode of \fIm\fR. Derived classes can reimplement this function to provide their own cancel dialog. The default implementation uses a message box which prompts the user to confirm the cancel.
Protected virtual function which returns a confirmation for an edit of mode \fIm\fR. Derived classes can reimplement this function to provide their own confirmation dialog. The default implementation uses a message box which prompts the user to confirm the edit action.
Returns the currently selected record, or 0 if there is no current selection. The table owns the pointer, so do \fInot\fR delete it or otherwise modify it or the cursor it points to.
For an editable table, issues a delete on the current cursor's primary index using the values of the currently selected row. If there is no current cursor or there is no current selection, nothing happens. If confirmEdits() or confirmDelete() is TRUE, confirmEdit() is called to confirm the delete. Returns TRUE if the delete succeeded; otherwise FALSE.
.PP
The underlying cursor must have a valid primary index to ensure that a unique record is deleted within the database otherwise the database may be changed to an inconsistent state.
Searches the current cursor for a cell containing the string \fIstr\fR starting at the current cell and working forwards (or backwards if \fIbackwards\fR is TRUE). If the string is found, the cell containing the string is set as the current cell. If \fIcaseSensitive\fR is FALSE the case of \fIstr\fR will be ignored.
.PP
The search will wrap, i.e. if the first (or if backwards is TRUE, last) cell is reached without finding \fIstr\fR the search will continue until it reaches the starting cell. If \fIstr\fR is not found the search will fail and the current cell will remain unchanged.
Protected virtual function which is called when an error \fIe\fR has occurred on the current cursor(). The default implementation displays a warning message to the user with information about the error.
For an editable table, issues an insert on the current cursor using the values in the cursor's edit buffer. If there is no current cursor or there is no current "insert" row, nothing happens. If confirmEdits() or confirmInsert() is TRUE, confirmEdit() is called to confirm the insert. Returns TRUE if the insert succeeded; otherwise returns FALSE.
.PP
The underlying cursor must have a valid primary index to ensure that a unique record is inserted within the database otherwise the database may be changed to an inconsistent state.
.SH "void TQDataTable::installEditorFactory ( TQSqlEditorFactory * f )"
Installs a new SQL editor factory \fIf\fR. This enables the user to create and instantiate their own editors for use in cell editing. Note that TQDataTable takes ownership of this pointer, and will delete it when it is no longer needed or when installEditorFactory() is called again.
.SH "void TQDataTable::installPropertyMap ( TQSqlPropertyMap * m )"
Installs a new property map \fIm\fR. This enables the user to create and instantiate their own property maps for use in cell editing. Note that TQDataTable takes ownership of this pointer, and will delete it when it is no longer needed or when installPropertMap() is called again.
Paints the \fIfield\fR on the painter \fIp\fR. The painter has already been translated to the appropriate cell's origin where the \fIfield\fR is to be rendered. \fIcr\fR describes the cell coordinates in the content coordinate system. The \fIselected\fR parameter is ignored.
.PP
If you want to draw custom field content you must reimplement paintField() to do the custom drawing. The default implementation renders the \fIfield\fR value as text. If the field is NULL, nullText() is displayed in the cell. If the field is Boolean, trueText() or falseText() is displayed as appropriate.
This signal is emitted after the cursor is primed for delete by the table, when a delete action is beginning on the table. The \fIbuf\fR parameter points to the edit buffer being deleted. Connect to this signal in order to, for example, record auditing information on deletions.
This signal is emitted after the cursor is primed for insert by the table, when an insert action is beginning on the table. The \fIbuf\fR parameter points to the edit buffer being inserted. Connect to this signal in order to, for example, prime the record buffer with default data values.
This signal is emitted after the cursor is primed for update by the table, when an update action is beginning on the table. The \fIbuf\fR parameter points to the edit buffer being updated. Connect to this signal in order to, for example, provide some visual feedback that the user is in 'edit mode'.
Refreshes the table. The cursor is refreshed using the current filter, the current sort, and the currently defined columns. Equivalent to calling refresh( TQDataTable::RefreshData ).
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Refreshes the table. If there is no currently defined cursor (see setSqlCursor()), nothing happens. The \fImode\fR parameter determines which type of refresh will take place.
.PP
See also Refresh, setSqlCursor(), and addColumn().
Sets the cursor auto-delete flag to \fIenable\fR. If \fIenable\fR is TRUE, the table will automatically delete the cursor specified by setSqlCursor(). If \fIenable\fR is FALSE (the default), the cursor will not be deleted.
Sets the \fIcol\fR column to display using the field \fIfieldName\fR, column label \fIlabel\fR, width \fIwidth\fR and iconset \fIiconset\fR.
.PP
If \fIlabel\fR is specified, it is used as the column's header label, otherwise the field's display label is used when setSqlCursor() is called. The \fIiconset\fR is used to set the icon used by the column header; by default there is no icon.
Sets the column \fIcol\fR to the width \fIw\fR. Note that unlike TQTable the TQDataTable is not immediately redrawn, you must call refresh(TQDataTable::RefreshColumns) yourself.
If the cursor's \fIsql\fR driver supports query sizes, the number of rows in the table is set to the size of the query. Otherwise, the table dynamically resizes itself as it is scrolled. If \fIsql\fR is not active, it is made active by issuing a select() on the cursor using the \fIsql\fR cursor's current filter and current sort.
Sets the sort to be applied to the displayed data to \fIsort\fR. If there is no current cursor, nothing happens. A TQSqlIndex contains field names and their ordering (ASC or DESC); these are used to compose the ORDER BY clause.
Sets \fIcursor\fR as the data source for the table. To force the display of the data from \fIcursor\fR, use refresh(). If \fIautoPopulate\fR is TRUE, columns are automatically created based upon the fields in the \fIcursor\fR record. If \fIautoDelete\fR is TRUE (the default is FALSE), the table will take ownership of the \fIcursor\fR and delete it when appropriate. If the \fIcursor\fR is read-only, the table becomes read-only. The table adopts the cursor's driver's definition for representing NULL values as strings.
Returns the text in cell \fIrow\fR, \fIcol\fR, or an empty string if the cell is empty. If the cell's value is NULL then nullText() will be returned. If the cell does not exist then TQString::null is returned.
For an editable table, issues an update using the cursor's edit buffer. If there is no current cursor or there is no current selection, nothing happens. If confirmEdits() or confirmUpdate() is TRUE, confirmEdit() is called to confirm the update. Returns TRUE if the update succeeded; otherwise returns FALSE.
.PP
The underlying cursor must have a valid primary index to ensure that a unique record is updated within the database otherwise the database may be changed to an inconsistent state.
Returns the value in cell \fIrow\fR, \fIcol\fR, or an invalid value if the cell does not exist or has no value.
.SS "Property Documentation"
.SH "bool autoEdit"
This property holds whether the data table automatically applies edits.
.PP
The default value for this property is TRUE. When the user begins an insert or update in the table there are two possible outcomes when they navigate to another record:
.PP
<ol type=1>
.TP
the insert or update is is performed -- this occurs if autoEdit is TRUE
.TP
the insert or update is abandoned -- this occurs if autoEdit is FALSE
.PP
Set this property's value with setAutoEdit() and get this property's value with autoEdit().
.SH "bool confirmCancels"
This property holds whether the data table confirms cancel operations.
.PP
If the confirmCancel property is TRUE, all cancels must be confirmed by the user through a message box (this behavior can be changed by overriding the confirmCancel() function), otherwise all cancels occur immediately. The default is FALSE.
.PP
See also confirmEdits and confirmCancel().
.PP
Set this property's value with setConfirmCancels() and get this property's value with confirmCancels().
.SH "bool confirmDelete"
This property holds whether the data table confirms delete operations.
.PP
If the confirmDelete property is TRUE, all deletions must be confirmed by the user through a message box (this behaviour can be changed by overriding the confirmEdit() function), otherwise all delete operations occur immediately.
.PP
See also confirmCancels, confirmEdits, confirmUpdate, and confirmInsert.
.PP
Set this property's value with setConfirmDelete() and get this property's value with confirmDelete().
.SH "bool confirmEdits"
This property holds whether the data table confirms edit operations.
.PP
If the confirmEdits property is TRUE, the data table confirms all edit operations (inserts, updates and deletes). Finer control of edit confirmation can be achieved using confirmCancels, confirmInsert, confirmUpdate and confirmDelete.
.PP
See also confirmCancels, confirmInsert, confirmUpdate, and confirmDelete.
.PP
Set this property's value with setConfirmEdits() and get this property's value with confirmEdits().
.SH "bool confirmInsert"
This property holds whether the data table confirms insert operations.
.PP
If the confirmInsert property is TRUE, all insertions must be confirmed by the user through a message box (this behaviour can be changed by overriding the confirmEdit() function), otherwise all insert operations occur immediately.
.PP
See also confirmCancels, confirmEdits, confirmUpdate, and confirmDelete.
.PP
Set this property's value with setConfirmInsert() and get this property's value with confirmInsert().
.SH "bool confirmUpdate"
This property holds whether the data table confirms update operations.
.PP
If the confirmUpdate property is TRUE, all updates must be confirmed by the user through a message box (this behaviour can be changed by overriding the confirmEdit() function), otherwise all update operations occur immediately.
.PP
See also confirmCancels, confirmEdits, confirmInsert, and confirmDelete.
.PP
Set this property's value with setConfirmUpdate() and get this property's value with confirmUpdate().
.SH "DateFormat dateFormat"
This property holds the format used for displaying date/time values.
This property holds the data filter for the data table.
.PP
The filter applies to the data shown in the table. To view data with a new filter, use refresh(). A filter string is an SQL WHERE clause without the WHERE keyword.
.PP
There is no default filter.
.PP
See also sort.
.PP
Set this property's value with setFilter() and get this property's value with filter().