48 #include "private/qfunctions_p.h" 390 for (
int i = 1; i < rows*cols; ++i) {
411 : pos(_pos), fragmentMap(map) {}
429 pieceTable->fragmentMap());
431 if (it == cells.end())
433 return it - cells.begin();
439 if (blockFragmentUpdates)
442 Q_ASSERT(cells.indexOf(fragment) == -1);
443 const uint pos = pieceTable->fragmentMap().position(fragment);
446 cells.insert(it, fragment);
447 if (!fragment_start || pos < pieceTable->fragmentMap().
position(fragment_start))
457 if (blockFragmentUpdates)
460 Q_ASSERT(cells.indexOf(fragment) != -1);
461 cells.removeAll(fragment);
462 if (fragment_start == fragment && cells.size()) {
463 fragment_start = cells.at(0);
465 if (fragment_start != fragment)
481 nCols = q->format().columns();
482 nRows = (cells.size() + nCols-1)/nCols;
485 grid =
q_check_ptr((
int *)realloc(grid, nRows*nCols*
sizeof(
int)));
486 memset(grid, 0, nRows*nCols*
sizeof(
int));
491 cellIndices.resize(cells.size());
494 for (
int i = 0; i < cells.size(); ++i) {
501 while (cell < nRows*nCols && grid[cell])
506 cellIndices[i] = cell;
508 if (r + rowspan > nRows) {
509 grid =
q_check_ptr((
int *)realloc(grid,
sizeof(
int)*(r + rowspan)*nCols));
510 memset(grid + (nRows*nCols), 0,
sizeof(
int)*(r+rowspan-nRows)*nCols);
515 for (
int ii = 0; ii < rowspan; ++ii) {
516 for (
int jj = 0; jj < colspan; ++jj) {
517 Q_ASSERT(grid[(r+ii)*nCols + c+jj] == 0);
518 grid[(r+ii)*nCols + c+jj] = fragment;
636 if (row < 0 || row >=
d->nRows || col < 0 || col >=
d->nCols)
659 if (position < 0 || map.
position(
d->fragment_start) >= pos || map.
position(
d->fragment_end) < pos)
664 if (it !=
d->cells.begin())
701 int nRows = this->
rows();
704 if (rows == nRows && cols == nCols)
707 d->pieceTable->beginEditBlock();
711 else if (nCols > cols)
716 else if (nRows > rows)
719 d->pieceTable->endEditBlock();
741 if (pos >
d->nRows || pos < 0)
750 int insert_before = 0;
751 if (pos > 0 && pos < d->nRows) {
752 for (
int i = 0; i <
d->nCols; ++i) {
753 int cell =
d->grid[pos*
d->nCols + i];
754 if (cell ==
d->grid[(pos-1)*
d->nCols+i]) {
761 }
else if (!insert_before) {
762 insert_before = cell;
766 insert_before = (pos == 0 ?
d->grid[0] :
d->fragment_end);
768 if (extended < d->nCols) {
773 fmt.setTableCellColumnSpan(1);
775 int pos =
it.position();
779 for (
int i = 0; i < num*(
d->nCols-extended); ++i)
806 if (pos >
d->nCols || pos < 0)
815 for (
int i = 0; i <
d->nRows; ++i) {
817 if (i ==
d->nRows - 1 && pos ==
d->nCols) {
818 cell =
d->fragment_end;
820 int logicalGridIndexBeforePosition = pos > 0
821 ?
d->findCellIndex(
d->grid[i*
d->nCols + pos - 1])
827 int logicalGridIndex;
828 int gridArrayOffset = i*
d->nCols + pos;
830 cell =
d->grid[gridArrayOffset];
831 logicalGridIndex =
d->findCellIndex(cell);
833 }
while (logicalGridIndex < logicalGridIndexBeforePosition
834 && gridArrayOffset < d->nRows*
d->nCols);
836 if (logicalGridIndex < logicalGridIndexBeforePosition
837 && gridArrayOffset ==
d->nRows*
d->nCols)
838 cell =
d->fragment_end;
841 if (pos > 0 && pos < d->nCols && cell ==
d->grid[i*
d->nCols + pos - 1]) {
843 if (!extendedSpans.
contains(cell)) {
849 extendedSpans << cell;
854 if (i > 0 && pos < d->nCols && cell ==
d->grid[(i-1) *
d->nCols + pos]) {
855 int gridIndex = i*
d->nCols + pos;
856 const int gridEnd =
d->nRows *
d->nCols - 1;
857 while (gridIndex < gridEnd && cell == d->grid[gridIndex]) {
860 if (gridIndex == gridEnd)
861 cell =
d->fragment_end;
863 cell =
d->grid[gridIndex];
868 fmt.setTableCellColumnSpan(1);
873 for (
int i = 0; i < num; ++i)
881 if (! columnWidths.
isEmpty()) {
882 for (
int i = num; i > 0; --i)
883 columnWidths.
insert(pos, columnWidths[
qMax(0, pos-1)]);
935 if (num <= 0 || pos < 0)
941 if (pos+num >
d->nRows)
942 num =
d->nRows - pos;
949 if (pos == 0 && num ==
d->nRows) {
959 for (
int r = pos; r < pos + num; ++r) {
960 for (
int c = 0;
c <
d->nCols; ++
c) {
961 int cell =
d->grid[r*
d->nCols +
c];
964 touchedCells << cell;
969 fmt.setTableCellRowSpan(span - 1);
973 int index =
d->cells.indexOf(cell) + 1;
974 int f_end = index <
d->cells.size() ?
d->cells.at(index) :
d->fragment_end;
1000 if (num <= 0 || pos < 0)
1004 if (pos >=
d->nCols)
1006 if (pos + num >
d->nCols)
1007 pos =
d->nCols - num;
1014 if (pos == 0 && num ==
d->nCols) {
1024 for (
int r = 0; r <
d->nRows; ++r) {
1025 for (
int c = pos;
c < pos + num; ++
c) {
1026 int cell =
d->grid[r*
d->nCols +
c];
1030 if (touchedCells.
contains(cell) && span <= 1)
1032 touchedCells << cell;
1035 fmt.setTableCellColumnSpan(span - 1);
1039 int index =
d->cells.indexOf(cell) + 1;
1040 int f_end = index <
d->cells.size() ?
d->cells.at(index) :
d->fragment_end;
1049 if (columnWidths.
count() > pos) {
1050 columnWidths.
remove(pos, num);
1094 if (numRows < rowSpan || numCols < colSpan)
1098 for (
int r = row; r < row + numRows; ++r) {
1101 if (
cellAt(r, column + numCols) ==
cellAt(r, column + numCols - 1))
1105 for (
int c = column;
c < column + numCols; ++
c) {
1116 const int cellFragment =
d->grid[row *
d->nCols + column];
1123 const int insertCellIndex = it -
d->cells.begin();
1124 int insertFragment =
d->cells.value(insertCellIndex + 1,
d->fragment_end);
1127 d->blockFragmentUpdates =
true;
1130 bool needsParagraph = rowHasText && colSpan == numCols;
1133 for (
int r = row; r < row + numRows; ++r) {
1134 int firstColumn = r < row + rowSpan ? column + colSpan : column;
1137 int firstCellIndex = r == row ? insertCellIndex + 1 : -1;
1138 int cellIndex = firstCellIndex;
1140 for (
int c = firstColumn;
c < column + numCols; ++
c) {
1141 const int fragment =
d->grid[r *
d->nCols +
c];
1144 if (fragment == cellFragment)
1148 uint pos = it.position();
1150 if (firstCellIndex == -1) {
1155 firstCellIndex = cellIndex = it -
d->cells.begin();
1166 for (
int i = r; i < r + cellRowSpan; ++i)
1167 for (
int j =
c; j <
c + cellColSpan; ++j)
1168 d->grid[i *
d->nCols + j] = cellFragment;
1173 const int nextFragment =
d->cells.value(cellIndex,
d->fragment_end);
1179 if (nextPos > pos) {
1180 if (needsParagraph) {
1181 needsParagraph =
false;
1183 p->
move(pos + 1, insertPos, nextPos - pos);
1184 }
else if (rowHasText) {
1186 p->
move(pos + 1, insertPos, nextPos - pos);
1188 p->
move(pos, insertPos, nextPos - pos);
1191 insertPos += nextPos - pos;
1197 needsParagraph =
true;
1202 if (firstCellIndex >= 0) {
1203 d->cellIndices.remove(firstCellIndex, cellIndex - firstCellIndex);
1204 d->cells.erase(
d->cells.begin() + firstCellIndex,
d->cells.begin() + cellIndex);
1208 d->fragment_start =
d->cells.first();
1214 d->blockFragmentUpdates =
false;
1236 int firstRow, numRows, firstColumn, numColumns;
1238 mergeCells(firstRow, firstColumn, numRows, numColumns);
1276 if (numRows > rowSpan || numCols > colSpan)
1287 for (
int r = row + 1; r < row + rowSpan; ++r) {
1289 int gridIndex = r *
d->nCols + column;
1291 int cellIndex = it -
d->cellIndices.begin();
1292 int fragment =
d->cells.value(cellIndex,
d->fragment_end);
1301 int insertAdjustement = 0;
1302 for (
int i = 0; i < numRows; ++i) {
1303 for (
int c = 0; c < colSpan - numCols; ++
c)
1305 insertAdjustement += colSpan - numCols;
1308 for (
int i = numRows; i < rowSpan; ++i) {
1309 for (
int c = 0; c < colSpan; ++
c)
1311 insertAdjustement += colSpan;
1373 int row = cell.
row();
1397 int row = cell.
row() + 1;
1398 int fragment = row <
d->nRows ?
d->grid[row*
d->nCols] :
d->fragment_end;
QTextCursor rowStart(const QTextCursor &c) const
Returns a cursor pointing to the start of the row that contains the given cursor. ...
T qobject_cast(QObject *object)
int columns() const
Returns the number of columns in the table.
QTextCharFormat charFormat(int index) const
Q_OUTOFLINE_TEMPLATE RandomAccessIterator qUpperBound(RandomAccessIterator begin, RandomAccessIterator end, const T &value)
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
#define QT_END_NAMESPACE
This macro expands to.
int columns() const
Returns the number of columns specified by the table format.
void remove(int i)
Removes the element at index position i.
void fragmentAdded(const QChar &type, uint fragment)
void remove(int pos, int length, QTextUndoCommand::Operation=QTextUndoCommand::MoveCursor)
#define it(className, varName)
int count(const T &t) const
Returns the number of occurrences of value in the vector.
The QTextFrame class represents a frame in a QTextDocument.
QTextFrame::iterator begin() const
Returns a frame iterator pointing to the beginning of the table's cell.
void insertRows(int pos, int num)
Inserts a number of rows before the row with the specified index.
Q_STATIC_GLOBAL_INLINE_OPERATOR bool operator<(int fragment, const QFragmentFindHelper &helper)
void update() const
/fn void QTextTablePrivate::update() const
void fragmentRemoved(const QChar &type, uint fragment)
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
QTextCursor rowEnd(const QTextCursor &c) const
Returns a cursor pointing to the end of the row that contains the given cursor.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
#define Q_STATIC_GLOBAL_INLINE_OPERATOR
Q_OUTOFLINE_TEMPLATE RandomAccessIterator qBinaryFind(RandomAccessIterator begin, RandomAccessIterator end, const T &value)
#define QTextBeginningOfFrame
QVector< int > cellIndices
void setTableCellRowSpan(int tableCellRowSpan)
If this character format is applied to characters in a table cell, the cell will span tableCellRowSpa...
QTextTable(QTextDocument *doc)
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 appendRows(int count)
Appends count rows at the bottom of the table.
The QVector class is a template class that provides a dynamic array.
int firstPosition() const
Returns the first document position inside the frame.
QTextCursor lastCursorPosition() const
Returns the last valid cursor position in this cell.
void removeRows(int pos, int num)
Removes a number of rows starting with the row at the specified index.
The QChar class provides a 16-bit Unicode character.
int insertBlock(int pos, int blockFormat, int charFormat, QTextUndoCommand::Operation=QTextUndoCommand::MoveCursor)
void insertText(const QString &text)
Inserts text at the current position, using the current character format.
void insertColumns(int pos, int num)
Inserts a number of columns before the column with the specified index.
FragmentMap::ConstIterator FragmentIterator
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
void setColumnWidthConstraints(const QVector< QTextLength > &constraints)
Sets the column width constraints for the table.
int rowSpan() const
Returns the number of rows this cell spans.
void removeColumns(int pos, int num)
Removes a number of columns starting with the column at the specified index.
void setTableCellColumnSpan(int tableCellColumnSpan)
If this character format is applied to characters in a table cell, the cell will span tableCellColumn...
void selectedTableCells(int *firstRow, int *numRows, int *firstColumn, int *numColumns) const
If the selection spans over table cells, firstRow is populated with the number of the first row in th...
QTextTableCell cellAt(int row, int col) const
Returns the table cell at the given row and column in the table.
void append(const T &t)
Inserts value at the end of the list.
#define QT_BEGIN_NAMESPACE
This macro expands to.
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
QTextCharFormat format() const
Returns the cell's character format.
QTextTableFormat format() const
Returns the table's format.
virtual void fragmentAdded(const QChar &type, uint fragment)
int column() const
Returns the number of the column in the table that contains this cell.
int objectIndex() const
Returns the object index of this object.
The QTextCursor class offers an API to access and modify QTextDocuments.
void resize(int rows, int cols)
Resizes the table to contain the required number of rows and columns.
QTextFormatCollection * formatCollection()
QTextDocumentPrivate * docHandle() const
QTextObject * createObject(const QTextFormat &newFormat, int objectIndex=-1)
void setFormat(const QTextCharFormat &format)
Sets the cell's character format to format.
void appendColumns(int count)
Appends count columns at the right side of the table.
uint position(uint node, uint field=0) const
int row() const
Returns the number of the row in the table that contains this cell.
T value(int i) const
Returns the value at index position i in the list.
int position() const
Returns the absolute position of the cursor within the document.
int length() const
Returns the length of the block in characters.
The QTextTable class represents a table in a QTextDocument.
bool blockFragmentUpdates
const BlockMap & blockMap() const
void setObjectType(int type)
Sets the text format's object type to type.
QTextBlock block() const
Returns the block that contains the cursor.
const T & at(int i) const
Returns the item at index position i in the vector.
int tableCellRowSpan() const
If this character format is applied to characters in a table cell, this function returns the number o...
Iterator find(int k, uint field=0)
The iterator class provides an iterator for reading the contents of a QTextFrame. ...
const QTextDocumentPrivate::FragmentMap & fragmentMap
void insertBlock()
Inserts a new empty block at the cursor position() with the current blockFormat() and charFormat()...
void setColumns(int columns)
Sets the number of columns required by the table format.
void insert(int i, const T &t)
Inserts value at index position i in the vector.
Q_OUTOFLINE_TEMPLATE RandomAccessIterator qLowerBound(RandomAccessIterator begin, RandomAccessIterator end, const T &value)
void setFormat(const QTextTableFormat &format)
Sets the table's format.
void setFormat(const QTextFormat &format)
Sets the text object's format.
int firstPosition() const
Returns the first valid position in the document occupied by this cell.
static QTextTable * createTable(QTextDocumentPrivate *, int pos, int rows, int cols, const QTextTableFormat &tableFormat)
QTextFrame::iterator end() const
Returns a frame iterator pointing to the end of the table's cell.
uint findNode(int k, uint field=0) const
QFragmentFindHelper(int _pos, const QTextDocumentPrivate::FragmentMap &map)
int rows() const
Returns the number of rows in the table.
int tableCellColumnSpan() const
If this character format is applied to characters in a table cell, this function returns the number o...
The QTextTableCell class represents the properties of a cell in a QTextTable.
bool hasComplexSelection() const
Returns true if the cursor contains a selection that is not simply a range from selectionStart() to s...
The QTextBlockFormat class provides formatting information for blocks of text in a QTextDocument...
void move(int from, int to, int length, QTextUndoCommand::Operation=QTextUndoCommand::MoveCursor)
int lastPosition() const
Returns the last valid position in the document occupied by this cell.
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...
QTextCursor firstCursorPosition() const
Returns the first valid cursor position in this cell.
bool isValid() const
Returns true if this is a valid table cell; otherwise returns false.
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
int tableCellFormatIndex() const
Returns the index of the tableCell's format in the document's internal list of formats.
The QTextTableFormat class provides formatting information for tables in a QTextDocument.
friend class QTextTableCell
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
void clearProperty(int propertyId)
Clears the value of the property given by propertyId.
int columnSpan() const
Returns the number of columns this cell spans.
virtual void fragmentRemoved(const QChar &type, uint fragment)
void setCharFormat(int pos, int length, const QTextCharFormat &newFormat, FormatChangeMode mode=SetFormat)
void setObjectIndex(int object)
Sets the format object's object index.
const FragmentMap & fragmentMap() const
int indexForFormat(const QTextFormat &f)
void aboutToRemoveCell(int cursorFrom, int cursorEnd)
This method is called from QTextTable when it is about to remove a table-cell to allow cursors to upd...
int findCellIndex(int fragment) const
QVector< QTextLength > columnWidthConstraints() const
Returns a list of constraints used by this table format to control the appearance of columns in a tab...
The QList class is a template class that provides lists.