Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |
The QDataTable class provides a flexible SQL table widget that supports browsing and editing. More...
#include <qdatatable.h>
Inherits QTable.
QDataTable supports various functions for presenting and editing SQL data from a QSqlCursor in a table.
If you want a to present your data in a form use QDataBrowser, or for read-only forms, QDataView.
When displaying data, QDataTable only retrieves data for visible rows. If the driver supports the 'query size' property the QDataTable 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.
QDataTable inherits QTable'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 QSqlCursor). QDataTable 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 cancelled 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 QSqlCursor 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.
QDataTable creates editors using the default QSqlEditorFactory. 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 QString with text() or as a QVariant 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.
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().
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().
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.
See also Database Classes.
This enum describes the refresh options.
If autoPopulate is TRUE (the default is FALSE), columns are automatically created based upon the fields in the cursor record. Note that autoPopulate only governs the creation of columns; to load the cursor's data into the table use refresh().
If the cursor 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.
If label is specified, it is used as the column's header label, otherwise the field's display label is used when setSqlCursor() is called. The iconset is used to set the icon used by the column header; by default there is no icon.
See also setSqlCursor() and refresh().
Examples: sql/overview/subclass1/main.cpp, sql/overview/subclass3/main.cpp, sql/overview/table2/main.cpp, and sql/sqltable/main.cpp.
Reimplemented from QTable.
Returns TRUE if the data table automatically applies edits; otherwise returns FALSE. See the "autoEdit" property for details.
This signal is emitted just before the currently selected record is deleted from the database. The buf 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 buf 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 buf parameter points to the edit buffer being updated. Connect to this signal when you want to transform the user's data behind-the-scenes.
Editing takes place using the cursor's edit buffer(see QSqlCursor::editBuffer()).
When editing begins, a new row is created in the table marked with an asterisk '*' in the row's vertical header column, i.e. at the left of the row.
Editing takes place using the cursor's edit buffer (see QSqlCursor::editBuffer()).
row and col refer to the row and column in the QDataTable.
(replace is provided for reimplementors and reflects the API of QTable::beginEdit().)
Returns TRUE if the data table confirms cancel operations; otherwise returns FALSE. See the "confirmCancels" property for details.
Returns TRUE if the data table confirms delete operations; otherwise returns FALSE. See the "confirmDelete" property for details.
Returns TRUE if the data table confirms edit operations; otherwise returns FALSE. See the "confirmEdits" property for details.
Returns TRUE if the data table confirms insert operations; otherwise returns FALSE. See the "confirmInsert" property for details.
Returns TRUE if the data table confirms update operations; otherwise returns FALSE. See the "confirmUpdate" property for details.
This signal is emitted whenever a new row is selected in the table. The record parameter points to the contents of the newly selected record.
This signal is emitted whenever the cursor record was changed due to an edit. The mode parameter is the type of edit that just took place.
Returns the format used for displaying date/time values. See the "dateFormat" property for details.
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.
Returns the text used to represent false values. See the "falseText" property for details.
Returns the data filter for the data table. See the "filter" property for details.
The search will wrap, i.e. if the first (or if backwards is TRUE, last) cell is reached without finding str the search will continue until it reaches the starting cell. If str is not found the search will fail and the current cell will remain unchanged.
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.
See also QSqlEditorFactory.
See also QSqlPropertyMap.
Returns the text used to represent NULL values. See the "nullText" property for details.
Returns the number of columns in the table. See the "numCols" property for details.
Reimplemented from QTable.
Returns the number of rows in the table. See the "numRows" property for details.
Reimplemented from QTable.
If you want to draw custom field content you must reimplement paintField() to do the custom drawing. The default implementation renders the field 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.
Example: sql/overview/table4/main.cpp.
This signal is emitted after the cursor is primed for delete by the table, when a delete action is beginning on the table. The buf 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 buf 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 buf 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'.
Examples: sql/overview/subclass1/main.cpp, sql/overview/table1/main.cpp, sql/overview/table2/main.cpp, and sql/sqltable/main.cpp.
Refreshes the table. If there is no currently defined cursor (see setSqlCursor()), nothing happens. The mode parameter determines which type of refresh will take place.
See also Refresh, setSqlCursor(), and addColumn().
See also QSqlField.
See also setSqlCursor().
Sets whether the data table automatically applies edits to autoEdit. See the "autoEdit" property for details.
If label is specified, it is used as the column's header label, otherwise the field's display label is used when setSqlCursor() is called. The iconset is used to set the icon used by the column header; by default there is no icon.
See also setSqlCursor() and refresh().
See also refresh().
Reimplemented from QTable.
Sets whether the data table confirms cancel operations to confirm. See the "confirmCancels" property for details.
Sets whether the data table confirms delete operations to confirm. See the "confirmDelete" property for details.
Sets whether the data table confirms edit operations to confirm. See the "confirmEdits" property for details.
Sets whether the data table confirms insert operations to confirm. See the "confirmInsert" property for details.
Sets whether the data table confirms update operations to confirm. See the "confirmUpdate" property for details.
Sets the format used for displaying date/time values to f. See the "dateFormat" property for details.
Sets the text used to represent false values to falseText. See the "falseText" property for details.
Sets the data filter for the data table to filter. See the "filter" property for details.
Sets the text used to represent NULL values to nullText. See the "nullText" property for details.
Sets the data table's sort to sort. See the "sort" property for details.
Sets the sort to be applied to the displayed data to sort. If there is no current cursor, nothing happens. A QSqlIndex contains field names and their ordering (ASC or DESC); these are used to compose the ORDER BY clause.
See also sort.
See also refresh(), readOnly, setAutoDelete(), and QSqlDriver::nullText().
Sets the text used to represent true values to trueText. See the "trueText" property for details.
Returns the data table's sort. See the "sort" property for details.
See also sorting.
The wholeRows parameter is ignored; QDataTable always sorts whole rows by the specified column.
Reimplemented from QTable.
See also sorting.
Reimplemented from QTable.
Returns the text used to represent true values. See the "trueText" property for details.
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.
This property holds whether the data table automatically applies edits.
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:
Set this property's value with setAutoEdit() and get this property's value with autoEdit().
This property holds whether the data table confirms cancel operations.
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.
See also confirmEdits and confirmCancel().
Set this property's value with setConfirmCancels() and get this property's value with confirmCancels().
This property holds whether the data table confirms delete operations.
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.
See also confirmCancels, confirmEdits, confirmUpdate, and confirmInsert.
Set this property's value with setConfirmDelete() and get this property's value with confirmDelete().
This property holds whether the data table confirms edit operations.
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.
See also confirmCancels, confirmInsert, confirmUpdate, and confirmDelete.
Set this property's value with setConfirmEdits() and get this property's value with confirmEdits().
This property holds whether the data table confirms insert operations.
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.
See also confirmCancels, confirmEdits, confirmUpdate, and confirmDelete.
Set this property's value with setConfirmInsert() and get this property's value with confirmInsert().
This property holds whether the data table confirms update operations.
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.
See also confirmCancels, confirmEdits, confirmInsert, and confirmDelete.
Set this property's value with setConfirmUpdate() and get this property's value with confirmUpdate().
This property holds the format used for displaying date/time values.
The dateFormat property is used for displaying date/time values in the table. The default value is Qt::LocalDate.
Set this property's value with setDateFormat() and get this property's value with dateFormat().
This property holds the text used to represent false values.
The falseText property will be used to represent NULL values in the table. The default value is "False".
Set this property's value with setFalseText() and get this property's value with falseText().
This property holds the data filter for the data table.
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.
There is no default filter.
See also sort.
Set this property's value with setFilter() and get this property's value with filter().
This property holds the text used to represent NULL values.
The nullText property will be used to represent NULL values in the table. The default value is provided by the cursor's driver.
Set this property's value with setNullText() and get this property's value with nullText().
This property holds the number of columns in the table.
Get this property's value with numCols().
This property holds the number of rows in the table.
Get this property's value with numRows().
This property holds the data table's sort.
The table's sort affects the order in which data records are displayed in the table. To apply a sort, use refresh().
When examining the sort property, a string list is returned with each item having the form 'fieldname order' (e.g., 'id ASC', 'surname DESC').
There is no default sort.
Note that if you want to iterate over the sort list, you should iterate over a copy, e.g.
QStringList list = myDataTable.sort(); QStringList::Iterator it = list.begin(); while( it != list.end() ) { myProcessing( *it ); ++it; }
See also filter and refresh().
Set this property's value with setSort() and get this property's value with sort().
This property holds the text used to represent true values.
The trueText property will be used to represent NULL values in the table. The default value is "True".
Set this property's value with setTrueText() and get this property's value with trueText().
This file is part of the Qt toolkit. Copyright © 1995-2003 Trolltech. All Rights Reserved.
Copyright © 2003 Trolltech | Trademarks | Qt version 3.1.2
|