Main Page   Class Hierarchy   Compound List   Compound Members   Examples   Search  

QdbtTabular Class Reference

The QdbtTabular widget provides a multi-column list of cells that can be scrolled. More...

#include <qdbttabular.h>

Class diagram for QdbtTabular:

QFrame QWidget QPaintDevice QObject Qt

List of all members.

Public Members

 QdbtTabular (QWidget *parent=0,const char *name=0,WFlags w=0)
 ~QdbtTabular ()
void setHeaderFont (const QFont &font)
const QFont headerFont () const
void setCellFont (const QFont &font)
const QFont cellFont () const
void setDimensions (int rows,int cols)
void setColumnWidth (int col,int width)
void changeSection (QdbtSection *section,int col)
QdbtSectionsection (int col)
void insertRow (int row=-1,bool selectable=TRUE)
void removeRow (int row)
void insertCol (int col=-1)
void removeCol (int col)
void clear ()
int numRows () const
int numCols () const
void changeCell (const QdbtTableCell *tc,int row,int col)
void changeCell (const char *text,const QPixmap *p,int row,int col, const QColor &color=Qt::black, int align=Qt::AlignLeft,bool editable=FALSE)
void changeCell (const char *text,int row,int col, const QColor &color=Qt::black, int align=Qt::AlignLeft,bool editable=FALSE)
void changeCell (const QPixmap *pixmap,int row,int col, int align=Qt::AlignLeft)
void showHeader ()
void hideHeader ()
bool headerVisible () const
int columnWidth (int col) const
int rowHeight (int row) const
int columnWidthHint (int col) const
const QdbtTableCellcell (int row,int col)
bool rowSelected (int row) const
void setRowSelected (int row,bool enable)
void setAutoUpdate (bool state)
bool autoUpdate () const
void update ()
QSize sizeHint () const
void enableTooltips ()
void disableTooltips ()
void selectByRow (bool enable)
bool rowSelectable (int row) const
void setRowSelectable (int row,bool enable)
void editCell (int row,int col,bool traverse=FALSE)
void exposeCell (int row,int col)
void fitAll ()
void showCascade ()
void hideCascade ()
void setCascadeText (int col, const QString &text)
void setCascadeMode (int col, const int mode)
void setCascadeAlignment (int col, const int align)
void setCascadeFont (const QFont &font)
void redrawHeader ()
void redrawCascade ()
void setHeaderCursor (const QCursor newCursor)
void setHeaderAppearance (int header_mode)
int headerAppearance ()

Signals

void sectionClicked (int col)
void selected (int row,bool state)
void activated (int row)
void cellEdited (int row,int col)
void cellSelected (int row,int col,bool state)
void cellActivated (int row,int col)

Protected Members

virtual void resizeEvent (QResizeEvent *)
virtual void drawContents (QPainter *)
virtual void enterTableEvent (QEvent *)
virtual void leaveTableEvent (QEvent *)
virtual void setPalette (const QPalette &)
QSize cellSize (int row,int col) const
QPoint cellOffset (int row,int col) const
int xOffset () const
int yOffset () const
int findRow (int yPos) const
int findCol (int xPos) const
int headerHeight () const

Detailed Description

The QdbtTabular widget provides a multi-column list of cells that can be scrolled.

Each cell in a QdbtTabular can either be empty or contain a QdbtTableCell. The default behavior of the table is row oriented. The user can select one row at a time. Multiple rows can be selected. A selected row is displayed with reversed colors.

Using selectByRow() individual cells can be selected instead of entire rows.

Default the table has a header. The header contains a section for each column. Sections are push buttons, with the following special properties:

The ability to resize a column can be turned off. The header consists of a number of buttons. Each button is a QdbtSection widget (or a widget derived from it) can be modified and using changeSection().

The number of rows and columns of the table can be (re-)set directly using setDimensions() or by inserting rows or inserting columns.

Newly created cells are empty. You can use changeCell() to replace an existing cell with another cell.

Cells can be made editable. This means that their contents can be edited if a user presses the middle mousebutton on a cell.

Warning:
The QdbtTabular assumes ownership of all cells and will delete them when they are not needed.

snapshot 1
snapshot 2
Examples:
example1.cpp, example2.cpp, example3.cpp, and example4.cpp.

Member Function Documentation

QdbtTabular::QdbtTabular (QWidget * parent = 0, const char * name = 0, WFlags f = 0)

Constructs an empty tabular (dimension 0 x 0) with an empty header. The parent, name and f arguments are passed to the QFrame constructor.

QdbtTabular::~QdbtTabular ()

Destroys the table.

void QdbtTabular::setHeaderFont (const QFont & font)

Sets the font that is used for the text in the table's sections to font

See also:
headerFont() and setCellFont().
Examples:
example1.cpp, example3.cpp, and example4.cpp.

const QFont QdbtTabular::headerFont () const

Returns the font that is currently used for the header.

See also:
setHeaderFont().

void QdbtTabular::setCellFont (const QFont & font)

Sets the font that is used for the text of each cell to font.

See also:
cellFont() and setHeaderFont().
Examples:
example1.cpp, example3.cpp, and example4.cpp.

const QFont QdbtTabular::cellFont () const

Returns the font that is currently used for the header.

See also:
setHeaderFont().

void QdbtTabular::setDimensions (int rows, int cols)

Set the dimension of the table to rows rows and cols columns. If the table is made smaller, the cells that fall outside the table will be deleted. If the table is made larger, empty cells are created. All cells that are inside the area covered by both the old size and the new size remain unchanged.

Try to use this function whenever possible, because it is much more efficient than repeatedly inserting rows and columns.

See also:
insertRow(), removeRow(), insertCol(), removeCol() and clear().
Examples:
example1.cpp, example2.cpp, example3.cpp, and example4.cpp.

void QdbtTabular::setColumnWidth (int col, int width)

Sets the width of column at col to width pixels.

See also:
columnWidth() and columnWidthHint().
Examples:
example1.cpp, example2.cpp, and example4.cpp.

void QdbtTabular::changeSection (QdbtSection * section, int col)

Sets a user specified widget representing the section of the header above column col.

If you want to change the look and/or feel of the default section, you should inherit your own widget from QdbtSection and supply a dynamicly allocated object as the section argument:

Example:

Assume you have a widget MySection that inherits from QdbtSection, then you can change column col of a table widget tabular like this

  MySection *section=new MySection(tabular);
  tabular->changeSection(section,col);

Warning:
The QdbtTabular widget assumes ownership of the section widgets, do not delete them manually.

See also:
section() and QdbtSection.
Examples:
example1.cpp, and example3.cpp.

QdbtSection * QdbtTabular::section (int col)

Returns a pointer to the widget representing the section of the header above column col.

You can use this pointer to get or set the text and/or alignment of the section.

Warning:
The table widget assumes control over the resize and location of the section widget. Do not change these properties manually.

See also:
changeSection() and QdbtSection.
Examples:
example1.cpp, and example4.cpp.

void QdbtTabular::insertRow (int index = -1, bool selectable = TRUE)

Insert a new row at row-index index in the table. A value of index=-1 will append a row to the end of the table. Each cell in the new row is empty.

If selectable is set to TRUE (the default) the row may be selected by the user.

If selectable is set to FALSE the row is not selectable by the user.

Notice that the value of selectable only has effect if the selection of rows is enabled.

See also: removeRow(), selectByRow(), setDimensions(), changeCell(), numRows().

Examples:
example1.cpp, and example4.cpp.

void QdbtTabular::removeRow (int index)

Removes row at index from the table. All cells in the row will be deleted.

See also:
insertRow() and setDimensions().
Examples:
example1.cpp.

void QdbtTabular::insertCol (int col = -1)

Insert a new column at column-index index A value of index=-1 will append a column to the end of the table

See also:
changeSection(), removeCol() and setDimensions().
Examples:
example1.cpp, and example4.cpp.

void QdbtTabular::removeCol (int col)

Removes the column at index index (and its section) from the table. All cells in the column will be deleted.

See also:
insertCol() and setDimensions().
Examples:
example1.cpp.

void QdbtTabular::clear () [inline]

Removes all cells from the table. This is equivalent to setDimensions(0,0).

Examples:
example1.cpp.

int QdbtTabular::numRows () const

Returns the number of rows in the table (not counting the header).

See also:
numCols().
Examples:
example1.cpp.

int QdbtTabular::numCols () const

Returns the number of columns in the table.

See also:
numRows().
Examples:
example1.cpp.

void QdbtTabular::changeCell (const QdbtTableCell * tc, int row, int col)

Deletes the contents of the cell at row row and column col and replaces it with a deep copy of the cell tc. If tc is the null pointer, the cell will become empty.

See also:
cell().
Examples:
example1.cpp, example2.cpp, example3.cpp, and example4.cpp.

void QdbtTabular::changeCell (const char * text, const QPixmap * pixmap, int row, int col, const QColor & color = Qt::black, int align = Qt::AlignLeft, bool edit = FALSE)

Deletes the contents of the cell at row row and column col and replaces it with a cell with text text, pixmap pixmap. This pixmap is placed to the left of the text. The text color can be specified by color, the alignment of the text-pixmap pair is determined by align. The following three alignments are possible: AlignLeft, AlignCenter, and AlignRight.

If the boolean edit is TRUE the cell is editable by the user. If edit is FALSE the cell cannot be altered by the user of the table (It can still be altered from within the program).

See also:
cell().

void QdbtTabular::changeCell (const char * text, int row, int col, const QColor & color = Qt::black, int align = Qt::AlignLeft, bool edit = FALSE)

Deletes the contents of the cell at row row and column col and replaces it with a cell with text text and no pixmap. The text color can be specified by color, the alignment of text is determined by align. The following three alignments are possible: AlignLeft, AlignCenter, and AlignRight.

If the boolean edit</em> is TRUE the cell is editable by the user. If edit is FALSE the cell cannot be altered by the user of the table (It can however still be altered from within the program).

See also:
cell().

void QdbtTabular::changeCell (const QPixmap * pixmap, int row, int col, int align = Qt::AlignLeft)

Deletes the contents of the cell at row row and column col and replaces it with a cell with pixmap pixmap and no text. The alignment of the pixmap is determined by align.

See also:
cell().

void QdbtTabular::showHeader ()

Shows the table's header whenever the table is visible. This is the default behavior. The header consists of a number of sections, one for each column. Each section is a button with a text. Pressing the button will emit a signal. Each section is separated by a divider. If the column is resizable the user can click the left mouse button and drag the divider to resize the column. Pressing the middle mouse button on a divider will resize the column so all cells fit in the column.

See also:
hideHeader(), headerVisible(), sectionClicked() and changeSection().
Examples:
example1.cpp.

void QdbtTabular::hideHeader ()

Hides the header normally visible above the table. The columns are no longer resizable by the user.

See also:
showHeader(), headerVisible().
Examples:
example1.cpp, and example2.cpp.

bool QdbtTabular::headerVisible () const

Returns TRUE if the table's header is currently visible, and FALSE if the header is currently not visible.

See also:
showHeader(), hideHeader().

int QdbtTabular::columnWidth (int col) const

Returns the width in pixels of the column at index col.

See also:
rowHeight() and columnWidthHint().

int QdbtTabular::rowHeight (int row) const

Returns the height in pixels of the row at index row.

See also:
columnWidth().

int QdbtTabular::columnWidthHint (int col) const

Returns the minimal width that is required to fully display all cells in the column at index col including the header.

See also:
fitAll().
Examples:
example1.cpp, and example4.cpp.

const QdbtTableCell * QdbtTabular::cell (int row, int col)

Returns a pointer to the cell-object at location (row,\e col) in the table.

See also:
changeCell().
Examples:
example2.cpp.

bool QdbtTabular::rowSelected (int row) const

Returns TRUE if the row at index index is currently selected. Notice that this function only returns useful values if selection by row is enabled.

See also:
setRowSelected() and selectByRow().
Examples:
example1.cpp.

void QdbtTabular::setRowSelected (int row, bool status)

Sets the select state of the row at index index to status. If status is TRUE the row will be highlighted (selected). If status is FALSE the row will not be highlighted (unselected).

See also:
rowSelected().
Examples:
example2.cpp.

void QdbtTabular::setAutoUpdate (bool state)

Sets the auto-update option of the table view to enable.

If enable is TRUE (this is the default) then the table updates it self automatically whenever it has changed in some way (for example when a flag is changed).

If enable is FALSE, the table does NOT repaint itself, or update its internal state variables itself when it is changed. This can be useful to avoid flicker during large changes, and is singularly useless otherwise: Disable auto-update, do the changes, re-enable auto-update, and call update().

Warning:
Do not leave the view in this state for a long time (i.e. between events ). If, for example, the user interacts with the table when auto-update is off, strange things can happen.

Setting auto-update to TRUE does not repaint the view, you must call update() to do this.

See also:
autoUpdate() and update().
Examples:
example1.cpp.

bool QdbtTabular::autoUpdate () const

Returns TRUE if the view updates itself automatically whenever it is changed in some way.

See also:
setAutoUpdate().

void QdbtTabular::update ()

Updates the widget unless updates are disabled or the widget is hidden.

Updating the widget will redraw each cell that is exposed. Cells erase themselves when they are redrawn, thus minimizing the amount of flickering.

Notice, that this function repaints the table correctly in all cases, whereas repaint() does not.

Reimplemented from QWidget.

Examples:
example1.cpp.

QSize QdbtTabular::sizeHint () const

Returns the preferred size of the table. The size is chosen so that all cells fit without the need for scrollbars.

Notice, that if there are many or large cells in the table, the returned size may be very large.

See also:
fitAll().

Reimplemented from QWidget.

Examples:
example2.cpp.

void QdbtTabular::enableTooltips ()

Enables dynamic tooltips for cells whose text is truncated. The tooltip shows the complete text. Default this feature is enabled.

See also:
disableTooltips().

void QdbtTabular::disableTooltips ()

Disables tooltips for cells whose text is truncated.

See also:
enableTooltips().
Examples:
example2.cpp.

void QdbtTabular::selectByRow (bool enable)

This function determines how cells are selected. If enable is set to TRUE the user can select cells one row at a time. This is the default behavior. Only the rows that are selectable (see setRowSelectable()) can be selected by the user.

If enable is set to FALSE the user can select individual cells. Only cells that are set to be selectable (see QdbtTableCell::setSelectable()) can be selected by the user.

See also:
setRowSelectable().
Examples:
example3.cpp, and example4.cpp.

bool QdbtTabular::rowSelectable (int row) const

This function returns TRUE if the user is allowed to change the highlight of the row at index index in the table.

See also:
setRowSelectable().

void QdbtTabular::setRowSelectable (int row, bool enable)

Sets whether or not the row at index index may be selected by the user.

If enable is TRUE selection is allowed. This is the default.

If enable is FALSE selection is denied. This function only has effect when selection by row is enabled.

See also:
selectByRow() and rowSelectable().
Examples:
example2.cpp.

void QdbtTabular::editCell (int row, int col, bool traverse = FALSE)

Sets the edit focus on the cell at location (row, col) in the table. Normally, the user is allowed to edit cells by clicking the middle mouse button those cells that are enabled for editing (see QdbtTableCell::setEditable()). This function can force the editing of a certain cell regardless of the edit state of the cell.

The traverse flag may be set to TRUE, if the hilighted cell shall be moved to this position, too.

Examples:
example4.cpp.

void QdbtTabular::exposeCell (int row, int col)

Scrolls the table so that the cell at (row, col), in such a way that the cell is visible for the largest part possible. The amount of scrolling is minimized. It is 0 if the cell is already completely visible.

void QdbtTabular::fitAll ()

Resizes the table's columns so that all cells fit (are not truncated).

See also:
sizeHint() and columnWidthHint().
Examples:
example2.cpp, and example3.cpp.

void QdbtTabular::showCascade ()

This function ensures that that cascaded headers are visible.

Examples:
example1.cpp.

void QdbtTabular::hideCascade ()

Cascaded headers are hidden by this function.

Examples:
example1.cpp.

void QdbtTabular::setCascadeText (int col, const QString & text)

The text of a cascaed headed is set using this function. Please keep in mind that using this function may have no effect unless using the setCascadeMode() function to set the correct mode of the cell.

This function does not initiate an automatic redraw of the cascaded header.

Examples:
example1.cpp.

void QdbtTabular::setCascadeMode (int col, const int mode)

Set the mode of a single cascade-cell. Currently only two modes are supported: End-Cell-Mode (0) or Continue-Cell-Mode (1).

In End-Cell-Mode a sequence of cascaded continue-mode cells 'ends' displaying the text set for the end-cell.

In Continue-Cell-Mode the cells is not displayed as an indivual cells. I adds its space to the following cells (which if it is another continue-cell adds this iteratively to its successor a.s.o.) A sequence of Continue-Cells is terminated by one End-Cell or the last column of the tabular.

This function does not initiate an automatic redraw of the cascaded header.

Examples:
example1.cpp.

void QdbtTabular::setCascadeAlignment (int col, const int align)

Select the alignment (in terms of Qt, meaning e.g. Qt::AlignCenter) of an indivual cell. Useless unless cells is and End-Cell.

This function does not initiate an automatic redraw of the cascaded header.

Examples:
example1.cpp.

void QdbtTabular::setCascadeFont (const QFont & font)

Select the font, in which the cascaded cells are displayed.

This function does not initiate an automatic redraw of the cascaded header.

Examples:
example1.cpp.

void QdbtTabular::redrawHeader ()

This function draws the header. It should not be used unless absolutely necessary since redraws are normally done automatically.

Examples:
example1.cpp.

void QdbtTabular::redrawCascade ()

This function draws the cascaded header. It should not be used unless absolutely necessary since redraws are normally done automatically.

void QdbtTabular::setHeaderCursor (const QCursor newCursor)

In order to acompish a consistend look-and-feel with the other Qt-Widgets (which may change) it may be neccessary to override the cursor shape when resizing the header or the tabular widget.

void QdbtTabular::setHeaderAppearance (int header_mode)

The tabular widget by default fills the remaining space in the header bar with a beveled box. The header_mode may be one of the following modes:

Examples:
example1.cpp.

int QdbtTabular::headerAppearance ()

This function answers the mode, in which the tabular widget's header is currently being displayed (or would be displayed, if it is hidden). This mode may be one of the following:

void QdbtTabular::sectionClicked (int index) [signal]

This signal is emitted if the user clicks on a section button. A section represents the header above a column. The index of the column is passed as an argument.

void QdbtTabular::selected (int index, bool state) [signal]

This signal is emitted whenever the highlight status of a row is changed. The index of the row and the new state are passed as arguments. If the value of state is TRUE the row is currently highlighted.

Notice that this signal is only emitted if selection by row is enabled.

See also:
selectByRow() and cellSelected().

void QdbtTabular::activated (int row) [signal]

This signal is emitted whenever the user double clicks on a row. The index of the row is passed as an argument.

Notice that this signal is only emitted if selection by row is enabled.

See also:
selectByRow() and cellActivated().
Examples:
example2.cpp.

void QdbtTabular::cellEdited (int row, int col) [signal]

This signal is emitted when the user has finished editing a cell and the contents of the cell has changed. The location (row, col) of the cell in the table is passed as an argument.

void QdbtTabular::cellSelected (int row, int col, bool state) [signal]

This signal is emitted whenever the highlight status of a cell is changed. The location of the cell and the new state are passed as arguments. If the value of state is TRUE the cell is currently highlighted.

Notice that this signal is only emitted if selection by row is disabled.

See also:
selectByRow() and selected().

void QdbtTabular::cellActivated (int row, int col) [signal]

This signal is emitted whenever the user double clicks on a cell. The location of the cell is passed as an argument.

Notice that this signal is only emitted if selection by row is disabled.

See also:
selectByRow() and activated().

void QdbtTabular::resizeEvent (QResizeEvent * e) [protected, virtual]

A virtual function that handles the resize events for the table.

Does not do anything at the moment.

Reimplemented from QWidget.

void QdbtTabular::drawContents (QPainter *) [protected, virtual]

A virtual function that handles the repaint function of the table.

Reimplemented from QFrame.

void QdbtTabular::enterTableEvent (QEvent *) [protected, virtual]

A virtual function that handles the mouse enter events of the table excluding the header.

Does not do anything at the moment.

void QdbtTabular::leaveTableEvent (QEvent *) [protected, virtual]

A virtual function that handles the mouse leave events of the table excluding the header.

Does not do anything at the moment.

void QdbtTabular::setPalette (const QPalette & p) [protected, virtual]

Sets the color palette to p.

Reimplemented from QWidget.

Examples:
example4.cpp.

QSize QdbtTabular::cellSize (int row, int col) const [protected]

Returns the current size of the cell at location (row,\a col) in the table. The cells themselves are not aware of their size.

QPoint QdbtTabular::cellOffset (int row, int col) const [protected]

Returns the offset in pixels of the cell at location (row,\a col) in the table.

The offset is based on the scrollable part of the table (excluding the header). Therefore, it includes parts of the table that are not visible because of scrolling.

int QdbtTabular::xOffset () const [protected]

Returns the x coordinate in table coordinates of the pixel which is currently on the left edge of the view.

See also:
yOffset().

int QdbtTabular::yOffset () const [protected]

Returns the y coordinate in table coordinates of the pixel which is currently on the top edge of the view.

See also:
xOffset().

int QdbtTabular::findRow (int yPos) const [protected]

Returns the index of the row at position yPos, where yPos is in widget coordinates. Returns -1 if yPos is outside the valid range.

See also:
findCol() and headerHeight().
Examples:
example2.cpp, and example4.cpp.

int QdbtTabular::findCol (int xPos) const [protected]

Returns the index of the column at position xPos, where xPos is in widget coordinates. Returns -1 if xPos is outside the valid range. \sa: findRow().

Examples:
example2.cpp, and example4.cpp.

int QdbtTabular::headerHeight () const [protected]

Returns the height of the header in pixels. If the header is currently invisible 0 is returned.


The documentation for this class was generated from the following files:
Generated 11:09, 1999/10/02 for QdbtTabular by doxygen  written by Dimitri van Heesch, © 1997-1998