com.trolltech.qt.gui
Class QTextTable

java.lang.Object
  extended by com.trolltech.qt.internal.QSignalEmitterInternal
      extended by com.trolltech.qt.QSignalEmitter
          extended by com.trolltech.qt.QtJambiObject
              extended by com.trolltech.qt.core.QObject
                  extended by com.trolltech.qt.gui.QTextObject
                      extended by com.trolltech.qt.gui.QTextFrame
                          extended by com.trolltech.qt.gui.QTextTable
All Implemented Interfaces:
QtJambiInterface

public class QTextTable
extends QTextFrame

The QTextTable class represents a table in a QTextDocument. A table is a group of cells ordered into rows and columns. Each table contains at least one row and one column. Each cell contains a block, and is surrounded by a frame.

Tables are usually created and inserted into a document with the QTextCursor::insertTable() function. For example, we can insert a table with three rows and two columns at the current cursor position in an editor using the following lines of code:

        QTextCursor cursor = new QTextCursor(editor.textCursor());

        cursor.movePosition(QTextCursor.MoveOperation.Start);
    
QTextTable table = cursor.insertTable(rows, columns, tableFormat);
The table format is either defined when the table is created or changed later with setFormat().

The table currently being edited by the cursor is found with QTextCursor::currentTable(). This allows its format or dimensions to be changed after it has been inserted into a document.

A table's size can be changed with resize(), or by using insertRows(), insertColumns(), removeRows(), or removeColumns(). Use cellAt() to retrieve table cells.

The starting and ending positions of table rows can be found by moving a cursor within a table, and using the rowStart() and rowEnd() functions to obtain cursors at the start and end of each row.

Rows and columns within a QTextTable can be merged and split using the mergeCells() and splitCell() functions. However, only cells that span multiple rows or columns can be split. (Merging or splitting does not increase or decrease the number of rows and columns.)



Suppose we have a 2x3 table of names and addresses. To merge both columns in the first row we invoke mergeCells() with row = 0, column = 0, numRows = 1 and numColumns = 2.
        table.mergeCells(0, 0, 1, 2);
    


This gives us the following table. To split the first row of the table back into two cells, we invoke the splitCell() function with numRows and numCols = 1.
        table.splitCell(0, 0, 1, 1);
    


This results in the original table.

See also:
QTextTableFormat.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
QSignalEmitter.AbstractSignal, QSignalEmitter.PrivateSignal0, QSignalEmitter.PrivateSignal1, QSignalEmitter.PrivateSignal2, QSignalEmitter.PrivateSignal3, QSignalEmitter.PrivateSignal4, QSignalEmitter.PrivateSignal5, QSignalEmitter.PrivateSignal6, QSignalEmitter.PrivateSignal7, QSignalEmitter.PrivateSignal8, QSignalEmitter.PrivateSignal9, QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9
 
Nested classes/interfaces inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
com.trolltech.qt.internal.QSignalEmitterInternal.AbstractSignalInternal
 
Field Summary
 
Fields inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
currentSender
 
Method Summary
 void appendColumns(int count)
          Appends count columns at the right side of the table.
 void appendRows(int count)
          Appends count rows at the bottom of the table.
 QTextTableCell cellAt(int position)
          This is an overloaded member function, provided for convenience.
 QTextTableCell cellAt(int row, int col)
          Returns the table cell at the given row and column in the table.
 QTextTableCell cellAt(QTextCursor c)
          This is an overloaded member function, provided for convenience.
 int columns()
          Returns the number of columns in the table.
 void insertColumns(int pos, int num)
          Inserts a number of columns before the column with the specified index.
 void insertRows(int pos, int num)
          Inserts a number of rows before the row with the specified index.
 void mergeCells(int row, int col, int numRows, int numCols)
          Merges the cell at the specified row and column with the adjacent cells into one cell.
 void mergeCells(QTextCursor cursor)
          This is an overloaded member function, provided for convenience.
 void removeColumns(int pos, int num)
          Removes a number of columns starting with the column at the specified index.
 void removeRows(int pos, int num)
          Removes a number of rows starting with the row at the specified index.
 void resize(int rows, int cols)
          Resizes the table to contain the required number of rows and columns.
 QTextCursor rowEnd(QTextCursor c)
          Returns a cursor pointing to the end of the row that contains the given cursor.
 int rows()
          Returns the number of rows in the table.
 QTextCursor rowStart(QTextCursor c)
          Returns a cursor pointing to the start of the row that contains the given cursor.
 void setFormat(QTextTableFormat format)
          Sets the table's format.
 void splitCell(int row, int col, int numRows, int numCols)
          Splits the specified cell at row and column into an array of multiple cells with dimensions specified by numRows and numCols.
 QTextTableFormat tableFormat()
          Returns the table's format.
 
Methods inherited from class com.trolltech.qt.gui.QTextFrame
begin, childFrames, end, firstCursorPosition, firstPosition, frameFormat, lastCursorPosition, lastPosition, parentFrame, setFrameFormat
 
Methods inherited from class com.trolltech.qt.gui.QTextObject
document, format, formatIndex, objectIndex, setFormat
 
Methods inherited from class com.trolltech.qt.core.QObject
childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, indexOfProperty, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, properties, property, removeEventFilter, setObjectName, setParent, setProperty, startTimer, timerEvent, toString, userProperty
 
Methods inherited from class com.trolltech.qt.QtJambiObject
dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread
 
Methods inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
__qt_signalInitialization
 
Methods inherited from class java.lang.Object
clone, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 

Method Detail

appendColumns

public final void appendColumns(int count)
Appends count columns at the right side of the table.

See also:
insertColumns(), insertRows(), resize(), removeRows(), removeColumns(), and appendRows().


appendRows

public final void appendRows(int count)
Appends count rows at the bottom of the table.

See also:
insertColumns(), insertRows(), resize(), removeRows(), removeColumns(), and appendColumns().


cellAt

public final QTextTableCell cellAt(QTextCursor c)
This is an overloaded member function, provided for convenience.

Returns the table cell containing the given cursor.


cellAt

public final QTextTableCell cellAt(int position)
This is an overloaded member function, provided for convenience.

Returns the table cell that contains the character at the given position in the document.


cellAt

public final QTextTableCell cellAt(int row,
                                   int col)
Returns the table cell at the given row and column in the table.

See also:
columns(), and rows().


columns

public final int columns()
Returns the number of columns in the table.

See also:
rows().


tableFormat

public final QTextTableFormat tableFormat()
Returns the table's format.

See also:
setFormat().


insertColumns

public final void insertColumns(int pos,
                                int num)
Inserts a number of columns before the column with the specified index.

See also:
insertRows(), resize(), removeRows(), removeColumns(), appendRows(), and appendColumns().


insertRows

public final void insertRows(int pos,
                             int num)
Inserts a number of rows before the row with the specified index.

See also:
resize(), insertColumns(), removeRows(), removeColumns(), appendRows(), and appendColumns().


mergeCells

public final void mergeCells(QTextCursor cursor)
This is an overloaded member function, provided for convenience.

Merges the cells selected by the provided cursor.

See also:
splitCell().


mergeCells

public final void mergeCells(int row,
                             int col,
                             int numRows,
                             int numCols)
Merges the cell at the specified row and column with the adjacent cells into one cell. The new cell will span numRows rows and numCols columns. If numRows or numCols is less than the current number of rows or columns the cell spans then this method does nothing.

See also:
splitCell().


removeColumns

public final void removeColumns(int pos,
                                int num)
Removes a number of columns starting with the column at the specified index.

See also:
insertRows(), insertColumns(), removeRows(), resize(), appendRows(), and appendColumns().


removeRows

public final void removeRows(int pos,
                             int num)
Removes a number of rows starting with the row at the specified index.

See also:
insertRows(), insertColumns(), resize(), removeColumns(), appendRows(), and appendColumns().


resize

public final void resize(int rows,
                         int cols)
Resizes the table to contain the required number of rows and columns.

See also:
insertRows(), insertColumns(), removeRows(), and removeColumns().


rowEnd

public final QTextCursor rowEnd(QTextCursor c)
Returns a cursor pointing to the end of the row that contains the given cursor.

See also:
rowStart().


rowStart

public final QTextCursor rowStart(QTextCursor c)
Returns a cursor pointing to the start of the row that contains the given cursor.

See also:
rowEnd().


rows

public final int rows()
Returns the number of rows in the table.

See also:
columns().


setFormat

public final void setFormat(QTextTableFormat format)
Sets the table's format.

See also:
format().


splitCell

public final void splitCell(int row,
                            int col,
                            int numRows,
                            int numCols)
Splits the specified cell at row and column into an array of multiple cells with dimensions specified by numRows and numCols.

Note: It is only possible to split cells that span multiple rows or columns, such as rows that have been merged using mergeCells().

See also:
mergeCells().