Qt 4.8
Public Functions | Private Functions | Properties | Friends | List of all members
QTextTableCell Class Reference

The QTextTableCell class represents the properties of a cell in a QTextTable. More...

#include <qtexttable.h>

Public Functions

QTextFrame::iterator begin () const
 Returns a frame iterator pointing to the beginning of the table's cell. More...
 
int column () const
 Returns the number of the column in the table that contains this cell. More...
 
int columnSpan () const
 Returns the number of columns this cell spans. More...
 
QTextFrame::iterator end () const
 Returns a frame iterator pointing to the end of the table's cell. More...
 
QTextCursor firstCursorPosition () const
 Returns the first valid cursor position in this cell. More...
 
int firstPosition () const
 Returns the first valid position in the document occupied by this cell. More...
 
QTextCharFormat format () const
 Returns the cell's character format. More...
 
bool isValid () const
 Returns true if this is a valid table cell; otherwise returns false. More...
 
QTextCursor lastCursorPosition () const
 Returns the last valid cursor position in this cell. More...
 
int lastPosition () const
 Returns the last valid position in the document occupied by this cell. More...
 
bool operator!= (const QTextTableCell &other) const
 Returns true if this cell object and the other cell object describe different cells; otherwise returns false. More...
 
QTextTableCelloperator= (const QTextTableCell &o)
 Assigns the other table cell to this table cell. More...
 
bool operator== (const QTextTableCell &other) const
 Returns true if this cell object and the other cell object describe the same cell; otherwise returns false. More...
 
 QTextTableCell ()
 Constructs an invalid table cell. More...
 
 QTextTableCell (const QTextTableCell &o)
 Copy constructor. More...
 
int row () const
 Returns the number of the row in the table that contains this cell. More...
 
int rowSpan () const
 Returns the number of rows this cell spans. More...
 
void setFormat (const QTextCharFormat &format)
 Sets the cell's character format to format. More...
 
int tableCellFormatIndex () const
 Returns the index of the tableCell's format in the document's internal list of formats. More...
 
 ~QTextTableCell ()
 Destroys the table cell. More...
 

Private Functions

 QTextTableCell (const QTextTable *t, int f)
 

Properties

int fragment
 
const QTextTabletable
 

Friends

class QTextTable
 

Detailed Description

The QTextTableCell class represents the properties of a cell in a QTextTable.

Note
This class or function is reentrant.

Table cells are pieces of document structure that belong to a table. The table orders cells into particular rows and columns; cells can also span multiple columns and rows.

Cells are usually created when a table is inserted into a document with QTextCursor::insertTable(), but they are also created and destroyed when a table is resized.

Cells contain information about their location in a table; you can obtain the row() and column() numbers of a cell, and its rowSpan() and columnSpan().

The format() of a cell describes the default character format of its contents. The firstCursorPosition() and lastCursorPosition() functions are used to obtain the extent of the cell in the document.

See also
QTextTable QTextTableFormat

Definition at line 59 of file qtexttable.h.

Constructors and Destructors

◆ QTextTableCell() [1/3]

QTextTableCell::QTextTableCell ( )
inline

Constructs an invalid table cell.

See also
isValid()

Definition at line 62 of file qtexttable.h.

62 : table(0) {}
const QTextTable * table
Definition: qtexttable.h:99

◆ ~QTextTableCell()

QTextTableCell::~QTextTableCell ( )
inline

Destroys the table cell.

Definition at line 63 of file qtexttable.h.

63 {}

◆ QTextTableCell() [2/3]

QTextTableCell::QTextTableCell ( const QTextTableCell other)
inline

Copy constructor.

Creates a new QTextTableCell object based on the other cell.

Definition at line 64 of file qtexttable.h.

64 : table(o.table), fragment(o.fragment) {}
const QTextTable * table
Definition: qtexttable.h:99

◆ QTextTableCell() [3/3]

QTextTableCell::QTextTableCell ( const QTextTable t,
int  f 
)
inlineprivate

Definition at line 96 of file qtexttable.h.

97  : table(t), fragment(f) {}
const QTextTable * table
Definition: qtexttable.h:99

Functions

◆ begin()

QTextFrame::iterator QTextTableCell::begin ( ) const

Returns a frame iterator pointing to the beginning of the table's cell.

See also
end()

Definition at line 306 of file qtexttable.cpp.

Referenced by QTextDocumentLayoutPrivate::drawTableCell(), QTextHtmlExporter::emitTable(), QTextDocumentLayoutPrivate::hitTest(), QTextDocumentLayoutPrivate::layoutCell(), and QTextDocumentLayoutPrivate::layoutTable().

307 {
309  int b = p->blockMap().findNode(firstPosition());
310  int e = p->blockMap().findNode(lastPosition()+1);
311  return QTextFrame::iterator(const_cast<QTextTable *>(table), b, b, e);
312 }
QTextDocumentPrivate * docHandle() const
const QTextTable * table
Definition: qtexttable.h:99
const BlockMap & blockMap() const
int firstPosition() const
Returns the first valid position in the document occupied by this cell.
Definition: qtexttable.cpp:273
uint findNode(int k, uint field=0) const
int lastPosition() const
Returns the last valid position in the document occupied by this cell.
Definition: qtexttable.cpp:287
friend class iterator
Definition: qtextobject.h:175

◆ column()

int QTextTableCell::column ( ) const

Returns the number of the column in the table that contains this cell.

See also
row()

Definition at line 201 of file qtexttable.cpp.

Referenced by QTextCursorPrivate::aboutToRemoveCell(), QTextCursorPrivate::adjustCursor(), QTextTableData::cellPosition(), QTextTableData::cellRect(), QTextCopyHelper::copy(), QTextDocumentLayoutPrivate::drawTableCell(), QTextHtmlExporter::emitTable(), QTextControlPrivate::gotoNextTableCell(), QTextControlPrivate::gotoPreviousTableCell(), QTextDocumentLayoutPrivate::hitTest(), QTextDocumentLayoutPrivate::layoutCell(), QTextDocumentLayoutPrivate::layoutTable(), QTextTable::mergeCells(), QTextCursorPrivate::movePosition(), QTextCursorPrivate::selectedTableCells(), QTextCursor::selectedText(), QTextCursorPrivate::setBlockCharFormat(), QTextCursorPrivate::setBlockFormat(), QTextCursorPrivate::setCharFormat(), and QTextTable::splitCell().

202 {
203  const QTextTablePrivate *tp = table->d_func();
204  if (tp->dirty)
205  tp->update();
206 
207  int idx = tp->findCellIndex(fragment);
208  if (idx == -1)
209  return idx;
210  return tp->cellIndices.at(idx) % tp->nCols;
211 }
void update() const
/fn void QTextTablePrivate::update() const
Definition: qtexttable.cpp:478
QVector< int > cellIndices
Definition: qtexttable_p.h:79
const QTextTable * table
Definition: qtexttable.h:99
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
int findCellIndex(int fragment) const
Definition: qtexttable.cpp:426

◆ columnSpan()

int QTextTableCell::columnSpan ( ) const

◆ end()

QTextFrame::iterator QTextTableCell::end ( ) const

Returns a frame iterator pointing to the end of the table's cell.

See also
begin()

Definition at line 319 of file qtexttable.cpp.

320 {
322  int b = p->blockMap().findNode(firstPosition());
323  int e = p->blockMap().findNode(lastPosition()+1);
324  return QTextFrame::iterator(const_cast<QTextTable *>(table), e, b, e);
325 }
QTextDocumentPrivate * docHandle() const
const QTextTable * table
Definition: qtexttable.h:99
const BlockMap & blockMap() const
int firstPosition() const
Returns the first valid position in the document occupied by this cell.
Definition: qtexttable.cpp:273
uint findNode(int k, uint field=0) const
int lastPosition() const
Returns the last valid position in the document occupied by this cell.
Definition: qtexttable.cpp:287
friend class iterator
Definition: qtextobject.h:175

◆ firstCursorPosition()

QTextCursor QTextTableCell::firstCursorPosition ( ) const

Returns the first valid cursor position in this cell.

See also
lastCursorPosition()

Definition at line 249 of file qtexttable.cpp.

Referenced by QTextControlPrivate::gotoNextTableCell(), QTextControlPrivate::gotoPreviousTableCell(), and QTextTable::mergeCells().

250 {
251  return QTextCursor(table->d_func()->pieceTable, firstPosition());
252 }
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
const QTextTable * table
Definition: qtexttable.h:99
int firstPosition() const
Returns the first valid position in the document occupied by this cell.
Definition: qtexttable.cpp:273

◆ firstPosition()

int QTextTableCell::firstPosition ( ) const

◆ format()

QTextCharFormat QTextTableCell::format ( ) const

Returns the cell's character format.

Definition at line 153 of file qtexttable.cpp.

Referenced by QTextTableData::cellPosition(), columnSpan(), QTextCopyHelper::copy(), QTextDocumentLayoutPrivate::drawTableCell(), QTextHtmlExporter::emitTable(), QTextDocumentLayoutPrivate::layoutCell(), QTextDocumentLayoutPrivate::layoutTable(), QTextTable::mergeCells(), QTextHtmlImporter::processBlockNode(), rowSpan(), setFormat(), QTextTable::splitCell(), and QTextOdfWriter::writeFrame().

154 {
157 
160  return fmt;
161 }
QTextCharFormat charFormat(int index) const
Definition: qtextformat_p.h:85
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
Definition: qtextformat.h:372
unsigned char c[8]
Definition: qnumeric_p.h:62
QTextFormatCollection * formatCollection()
QTextDocumentPrivate * docHandle() const
const QTextTable * table
Definition: qtexttable.h:99
void setObjectType(int type)
Sets the text format&#39;s object type to type.
Definition: qtextformat.h:367
int tableCellFormatIndex() const
Returns the index of the tableCell&#39;s format in the document&#39;s internal list of formats.
Definition: qtexttable.cpp:173

◆ isValid()

bool QTextTableCell::isValid ( ) const
inline

◆ lastCursorPosition()

QTextCursor QTextTableCell::lastCursorPosition ( ) const

Returns the last valid cursor position in this cell.

See also
firstCursorPosition()

Definition at line 259 of file qtexttable.cpp.

Referenced by QTextHtmlImporter::closeTag().

260 {
261  return QTextCursor(table->d_func()->pieceTable, lastPosition());
262 }
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
const QTextTable * table
Definition: qtexttable.h:99
int lastPosition() const
Returns the last valid position in the document occupied by this cell.
Definition: qtexttable.cpp:287

◆ lastPosition()

int QTextTableCell::lastPosition ( ) const

Returns the last valid position in the document occupied by this cell.

Warning
This function is not part of the public interface.

Definition at line 287 of file qtexttable.cpp.

Referenced by adjustContextSelectionsForCell(), QTextCursorPrivate::adjustCursor(), begin(), QTextCursorPrivate::clearCells(), QTextCopyHelper::copy(), end(), QTextDocumentLayoutPrivate::hitTest(), lastCursorPosition(), QTextCursorPrivate::movePosition(), QTextTable::removeColumns(), QTextTable::removeRows(), QTextCursor::selectedText(), QTextCursorPrivate::setBlockCharFormat(), QTextCursorPrivate::setBlockFormat(), QTextCursorPrivate::setCharFormat(), and QTextTable::splitCell().

288 {
290  const QTextTablePrivate *td = table->d_func();
291  int index = table->d_func()->findCellIndex(fragment);
292  int f;
293  if (index != -1)
294  f = td->cells.value(index + 1, td->fragment_end);
295  else
296  f = td->fragment_end;
297  return p->fragmentMap().position(f);
298 }
QTextDocumentPrivate * docHandle() const
uint position(uint node, uint field=0) const
const QTextTable * table
Definition: qtexttable.h:99
T value(int i) const
Returns the value at index position i in the list.
Definition: qlist.h:661
QList< int > cells
Definition: qtexttable_p.h:76
quint16 index
const FragmentMap & fragmentMap() const

◆ operator!=()

QTextCursor QTextTableCell::operator!= ( const QTextTableCell other) const
inline

Returns true if this cell object and the other cell object describe different cells; otherwise returns false.

Definition at line 86 of file qtexttable.h.

87  { return !operator==(other); }
bool operator==(const QTextTableCell &other) const
Returns true if this cell object and the other cell object describe the same cell; otherwise returns ...
Definition: qtexttable.h:84

◆ operator=()

QTextTableCell & QTextTableCell::operator= ( const QTextTableCell o)
inline

Assigns the other table cell to this table cell.

Definition at line 65 of file qtexttable.h.

66  { table = o.table; fragment = o.fragment; return *this; }
const QTextTable * table
Definition: qtexttable.h:99

◆ operator==()

QTextCursor QTextTableCell::operator== ( const QTextTableCell other) const
inline

Returns true if this cell object and the other cell object describe the same cell; otherwise returns false.

Definition at line 84 of file qtexttable.h.

85  { return table == other.table && fragment == other.fragment; }
const QTextTable * table
Definition: qtexttable.h:99

◆ row()

int QTextTableCell::row ( ) const

Returns the number of the row in the table that contains this cell.

See also
column()

Definition at line 184 of file qtexttable.cpp.

Referenced by QTextCursorPrivate::aboutToRemoveCell(), QTextCursorPrivate::adjustCursor(), QTextTableData::cellPosition(), QTextTableData::cellRect(), QTextCopyHelper::copy(), QTextDocumentLayoutPrivate::drawFrame(), QTextDocumentLayoutPrivate::drawTableCell(), QTextHtmlExporter::emitTable(), QTextControlPrivate::gotoNextTableCell(), QTextControlPrivate::gotoPreviousTableCell(), QTextDocumentLayoutPrivate::hitTest(), QTextDocumentLayoutPrivate::layoutCell(), QTextDocumentLayoutPrivate::layoutTable(), QTextTable::mergeCells(), QTextCursorPrivate::movePosition(), QTextTable::rowEnd(), QTextTable::rowStart(), QTextCursorPrivate::selectedTableCells(), QTextCursor::selectedText(), QTextCursorPrivate::setBlockCharFormat(), QTextCursorPrivate::setBlockFormat(), QTextCursorPrivate::setCharFormat(), QTextTable::splitCell(), and QTextOdfWriter::writeFrame().

185 {
186  const QTextTablePrivate *tp = table->d_func();
187  if (tp->dirty)
188  tp->update();
189 
190  int idx = tp->findCellIndex(fragment);
191  if (idx == -1)
192  return idx;
193  return tp->cellIndices.at(idx) / tp->nCols;
194 }
void update() const
/fn void QTextTablePrivate::update() const
Definition: qtexttable.cpp:478
QVector< int > cellIndices
Definition: qtexttable_p.h:79
const QTextTable * table
Definition: qtexttable.h:99
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
int findCellIndex(int fragment) const
Definition: qtexttable.cpp:426

◆ rowSpan()

int QTextTableCell::rowSpan ( ) const

Returns the number of rows this cell spans.

The default is 1.

See also
columnSpan()

Definition at line 218 of file qtexttable.cpp.

Referenced by QTextTableData::cellRect(), QTextCopyHelper::copy(), QTextDocumentLayoutPrivate::drawTableCell(), QTextHtmlExporter::emitTable(), QTextDocumentLayoutPrivate::layoutTable(), QTextCursorPrivate::movePosition(), QTextCursorPrivate::selectedTableCells(), QTextCursor::selectedText(), QTextCursorPrivate::setBlockCharFormat(), QTextCursorPrivate::setBlockFormat(), QTextCursorPrivate::setCharFormat(), and QTextOdfWriter::writeFrame().

219 {
220  return format().tableCellRowSpan();
221 }
QTextCharFormat format() const
Returns the cell&#39;s character format.
Definition: qtexttable.cpp:153
int tableCellRowSpan() const
If this character format is applied to characters in a table cell, this function returns the number o...
Definition: qtextformat.h:518

◆ setFormat()

void QTextTableCell::setFormat ( const QTextCharFormat format)

Sets the cell's character format to format.

Since
4.2

This can for example be used to change the background color of the entire cell:

QTextTableCell cell = table->cellAt(2, 3); QTextCharFormat format = cell.format(); format.setBackground(Qt::blue); cell.setFormat(format);

Note that the cell's row or column span cannot be changed through this function. You have to use QTextTable::mergeCells and QTextTable::splitCell instead.

See also
format()

Definition at line 134 of file qtexttable.cpp.

Referenced by QTextHtmlImporter::processBlockNode().

135 {
136  QTextCharFormat fmt = format;
141 
143  QTextCharFormat oldFormat = c->charFormat(frag->format);
144  fmt.setTableCellRowSpan(oldFormat.tableCellRowSpan());
146 
148 }
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
Definition: qtextformat.h:372
unsigned char c[8]
Definition: qnumeric_p.h:62
void setTableCellRowSpan(int tableCellRowSpan)
If this character format is applied to characters in a table cell, the cell will span tableCellRowSpa...
Definition: qtextformat.h:529
FragmentMap::ConstIterator FragmentIterator
void setTableCellColumnSpan(int tableCellColumnSpan)
If this character format is applied to characters in a table cell, the cell will span tableCellColumn...
Definition: qtextformat.h:537
QTextCharFormat format() const
Returns the cell&#39;s character format.
Definition: qtexttable.cpp:153
QTextFormatCollection * formatCollection()
QTextDocumentPrivate * docHandle() const
const QTextTable * table
Definition: qtexttable.h:99
void setObjectType(int type)
Sets the text format&#39;s object type to type.
Definition: qtextformat.h:367
int tableCellRowSpan() const
If this character format is applied to characters in a table cell, this function returns the number o...
Definition: qtextformat.h:518
int tableCellColumnSpan() const
If this character format is applied to characters in a table cell, this function returns the number o...
Definition: qtextformat.h:521
void clearProperty(int propertyId)
Clears the value of the property given by propertyId.
void setCharFormat(int pos, int length, const QTextCharFormat &newFormat, FormatChangeMode mode=SetFormat)
const FragmentMap & fragmentMap() const

◆ tableCellFormatIndex()

int QTextTableCell::tableCellFormatIndex ( ) const

Returns the index of the tableCell's format in the document's internal list of formats.

Since
4.5
See also
QTextDocument::allFormats()

Definition at line 173 of file qtexttable.cpp.

Referenced by format(), and QTextOdfWriter::writeFrame().

174 {
177 }
FragmentMap::ConstIterator FragmentIterator
QTextDocumentPrivate * docHandle() const
const QTextTable * table
Definition: qtexttable.h:99
const FragmentMap & fragmentMap() const

Friends and Related Functions

◆ QTextTable

friend class QTextTable
friend

Definition at line 95 of file qtexttable.h.

Properties

◆ fragment

int QTextTableCell::fragment
private

◆ table

const QTextTable* QTextTableCell::table
private

The documentation for this class was generated from the following files: