252 return p->fragmentMap().position(fragment) + 1;
270 return p->fragmentMap().position(
f);
341 d->blockFragmentUpdates =
true;
344 d->cells.append(
d->fragment_start);
347 for (
int i = 1;
i < rows*cols; ++
i) {
357 d->blockFragmentUpdates =
false;
375 return helper.fragmentMap.position(fragment) <
helper.pos;
380 return helper.pos <
helper.fragmentMap.position(fragment);
438 nCols =
q->format().columns();
464 if (
r + rowspan >
nRows) {
470 for (
int ii = 0; ii < rowspan; ++ii) {
471 for (
int jj = 0; jj < colspan; ++jj) {
610 auto it = std::lower_bound(
d->cells.begin(),
d->cells.end(),
helper);
611 if (
it !=
d->cells.begin())
642 int nRows = this->
rows();
645 if (rows == nRows && cols == nCols)
648 d->pieceTable->beginEditBlock();
652 else if (nCols > cols)
657 else if (nRows >
rows)
660 d->pieceTable->endEditBlock();
688 int insert_before = 0;
689 if (
pos > 0 && pos < d->nRows) {
691 for (
int i = 0;
i <
d->nCols; ++
i) {
692 int cell =
d->grid[
pos*
d->nCols +
i];
693 if (cell ==
d->grid[(
pos-1)*
d->nCols+
i]) {
695 if (cell != lastCell) {
699 p->setCharFormat(
it.position(), 1, fmt);
702 }
else if (!insert_before) {
703 insert_before = cell;
708 insert_before = (
pos == 0 ?
d->grid[0] :
d->fragment_end);
710 if (extended < d->nCols) {
717 int pos =
it.position();
718 int cfmt =
p->formatCollection()->indexForFormat(fmt);
721 for (
int i = 0;
i <
num*(
d->nCols-extended); ++
i)
754 for (
int i = 0;
i <
d->nRows; ++
i) {
756 if (
i ==
d->nRows - 1 &&
pos ==
d->nCols) {
757 cell =
d->fragment_end;
759 int logicalGridIndexBeforePosition =
pos > 0
760 ?
d->findCellIndex(
d->grid[
i*
d->nCols +
pos - 1])
766 int logicalGridIndex;
767 int gridArrayOffset =
i*
d->nCols +
pos;
769 cell =
d->grid[gridArrayOffset];
770 logicalGridIndex =
d->findCellIndex(cell);
772 }
while (logicalGridIndex < logicalGridIndexBeforePosition
773 && gridArrayOffset < d->nRows*
d->nCols);
775 if (logicalGridIndex < logicalGridIndexBeforePosition
776 && gridArrayOffset ==
d->nRows*
d->nCols)
777 cell =
d->fragment_end;
780 if (
pos > 0 && pos < d->nCols && cell ==
d->grid[
i*
d->nCols +
pos - 1]) {
782 if (!extendedSpans.
contains(cell)) {
786 p->setCharFormat(
it.position(), 1, fmt);
788 extendedSpans << cell;
793 if (
i > 0 && pos < d->nCols && cell ==
d->grid[(
i-1) *
d->nCols +
pos]) {
794 int gridIndex =
i*
d->nCols +
pos;
795 const int gridEnd =
d->nRows *
d->nCols - 1;
796 while (gridIndex < gridEnd && cell == d->grid[gridIndex]) {
799 if (gridIndex == gridEnd)
800 cell =
d->fragment_end;
802 cell =
d->grid[gridIndex];
810 int cfmt =
p->formatCollection()->indexForFormat(fmt);
812 for (
int i = 0;
i <
num; ++
i)
820 if (! columnWidths.
isEmpty()) {
821 for (
int i =
num;
i > 0; --
i)
879 if (
pos == 0 &&
num ==
d->nRows) {
880 const int pos =
p->fragmentMap().position(
d->fragment_start);
881 p->remove(
pos,
p->fragmentMap().position(
d->fragment_end) -
pos + 1);
890 for (
int c = 0;
c <
d->nCols; ++
c) {
891 int cell =
d->grid[
r*
d->nCols +
c];
894 touchedCells << cell;
900 p->setCharFormat(
it.position(), 1, fmt);
903 int index =
d->cells.indexOf(cell) + 1;
904 int f_end =
index <
d->cells.size() ?
d->cells.at(
index) :
d->fragment_end;
905 p->remove(
it.position(),
p->fragmentMap().position(f_end) -
it.position());
941 if (
pos == 0 &&
num ==
d->nCols) {
942 const int pos =
p->fragmentMap().position(
d->fragment_start);
943 p->remove(
pos,
p->fragmentMap().position(
d->fragment_end) -
pos + 1);
951 for (
int r = 0;
r <
d->nRows; ++
r) {
953 int cell =
d->grid[
r*
d->nCols +
c];
959 touchedCells << cell;
963 p->setCharFormat(
it.position(), 1, fmt);
966 int index =
d->cells.indexOf(cell) + 1;
967 int f_end =
index <
d->cells.size() ?
d->cells.at(
index) :
d->fragment_end;
968 p->remove(
it.position(),
p->fragmentMap().position(f_end) -
it.position());
1014 numRows = qMin(numRows,
rows() - cell.
row());
1018 if (numRows < rowSpan || numCols < colSpan)
1022 for (
int r =
row;
r <
row + numRows; ++
r) {
1036 p->beginEditBlock();
1040 const int cellFragment =
d->grid[
row *
d->nCols +
column];
1044 const auto begin =
d->cells.cbegin();
1045 const auto it = std::lower_bound(
begin,
d->cells.cend(),
helper);
1049 const int insertCellIndex =
it -
begin;
1050 int insertFragment =
d->cells.value(insertCellIndex + 1,
d->fragment_end);
1051 uint insertPos =
p->fragmentMap().position(insertFragment);
1053 d->blockFragmentUpdates =
true;
1056 bool needsParagraph = rowHasText && colSpan == numCols;
1059 for (
int r =
row;
r <
row + numRows; ++
r) {
1063 int firstCellIndex =
r ==
row ? insertCellIndex + 1 : -1;
1064 int cellIndex = firstCellIndex;
1066 for (
int c = firstColumn;
c <
column + numCols; ++
c) {
1067 const int fragment =
d->grid[
r *
d->nCols +
c];
1070 if (fragment == cellFragment)
1076 if (firstCellIndex == -1) {
1078 const auto begin =
d->cells.cbegin();
1079 const auto it = std::lower_bound(
begin,
d->cells.cend(),
helper);
1083 firstCellIndex = cellIndex =
it -
begin;
1094 for (
int i =
r;
i <
r + cellRowSpan; ++
i)
1095 for (
int j =
c;
j <
c + cellColSpan; ++
j)
1096 d->grid[
i *
d->nCols +
j] = cellFragment;
1101 const int nextFragment =
d->cells.value(cellIndex,
d->fragment_end);
1102 const uint nextPos =
p->fragmentMap().position(nextFragment);
1107 if (nextPos >
pos) {
1108 if (needsParagraph) {
1109 needsParagraph =
false;
1111 p->move(
pos + 1, insertPos, nextPos -
pos);
1112 }
else if (rowHasText) {
1114 p->move(
pos + 1, insertPos, nextPos -
pos);
1116 p->move(
pos, insertPos, nextPos -
pos);
1119 insertPos += nextPos -
pos;
1125 needsParagraph =
true;
1130 if (firstCellIndex >= 0) {
1131 d->cellIndices.remove(firstCellIndex, cellIndex - firstCellIndex);
1132 d->cells.erase(
d->cells.begin() + firstCellIndex,
d->cells.begin() + cellIndex);
1136 d->fragment_start =
d->cells.constFirst();
1140 p->setCharFormat(origCellPosition, 1, fmt);
1142 d->blockFragmentUpdates =
false;
1158 if (!
cursor.hasComplexSelection())
1161 int firstRow, numRows, firstColumn, numColumns;
1162 cursor.selectedTableCells(&firstRow, &numRows, &firstColumn, &numColumns);
1163 mergeCells(firstRow, firstColumn, numRows, numColumns);
1198 if (numRows > rowSpan || numCols > colSpan)
1201 p->beginEditBlock();
1209 for (
int r =
row + 1;
r <
row + rowSpan; ++
r) {
1211 int gridIndex =
r *
d->nCols +
column;
1212 const auto begin =
d->cellIndices.cbegin();
1213 const auto it = std::upper_bound(
begin,
d->cellIndices.cend(), gridIndex);
1214 int fragment =
d->cells.value(
it -
begin,
d->fragment_end);
1215 rowPositions[
r -
row] =
p->fragmentMap().position(fragment);
1220 const int fmtIndex =
c->indexForFormat(fmt);
1221 const int blockIndex =
p->blockMap().find(cell.
lastPosition())->format;
1223 int insertAdjustement = 0;
1224 for (
int i = 0;
i < numRows; ++
i) {
1225 for (
int c = 0;
c < colSpan - numCols; ++
c)
1227 insertAdjustement += colSpan - numCols;
1230 for (
int i = numRows;
i < rowSpan; ++
i) {
1231 for (
int c = 0;
c < colSpan; ++
c)
1233 insertAdjustement += colSpan;
1238 p->setCharFormat(origCellPosition, 1, fmt);
1307 int row = cell.
row() + 1;
1308 int fragment =
row <
d->nRows ?
d->grid[
row*
d->nCols] :
d->fragment_end;
1339 #include "moc_qtexttable.cpp"
small capitals from c petite p scientific i
[1]
The QChar class provides a 16-bit Unicode character.
bool operator<(const QElapsedTimer &lhs, const QElapsedTimer &rhs) noexcept
uint position(uint node, uint field=0) const
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal.
qsizetype size() const noexcept
bool isEmpty() const noexcept
iterator insert(qsizetype i, parameter_type t)
const_reference at(qsizetype i) const noexcept
T value(qsizetype i) const
const_iterator constBegin() const noexcept
void remove(qsizetype i, qsizetype n=1)
qsizetype removeAll(const AT &t)
qsizetype count() const noexcept
void resize(qsizetype size)
const_iterator constEnd() const noexcept
The QTextBlockFormat class provides formatting information for blocks of text in a QTextDocument....
The QTextCharFormat class provides formatting information for characters in a QTextDocument....
int tableCellColumnSpan() const
void setTableCellColumnSpan(int tableCellColumnSpan)
int tableCellRowSpan() const
void setTableCellRowSpan(int tableCellRowSpan)
The QTextCursor class offers an API to access and modify QTextDocuments.
void insertText(const QString &text)
static QTextCursor fromPosition(QTextDocumentPrivate *d, int pos)
The QTextDocument class holds formatted text.
int insertBlock(int pos, int blockFormat, int charFormat, QTextUndoCommand::Operation=QTextUndoCommand::MoveCursor)
QTextFormatCollection * formatCollection()
QTextObject * createObject(const QTextFormat &newFormat, int objectIndex=-1)
FragmentMap::ConstIterator FragmentIterator
@ SetFormatAndPreserveObjectIndices
static const QTextDocumentPrivate * get(const QTextDocument *document)
const FragmentMap & fragmentMap() const
int indexForFormat(const QTextFormat &f)
QTextCharFormat charFormat(int index) const
void setObjectType(int type)
void setObjectIndex(int object)
void clearProperty(int propertyId)
The iterator class provides an iterator for reading the contents of a QTextFrame.
The QTextFrame class represents a frame in a QTextDocument. \inmodule QtGui.
int firstPosition() const
virtual void fragmentRemoved(QChar type, uint fragment)
virtual void fragmentAdded(QChar type, uint fragment)
void setFormat(const QTextFormat &format)
QTextDocumentPrivate * pieceTable
The QTextTableCell class represents the properties of a cell in a QTextTable. \inmodule QtGui.
QTextCharFormat format() const
int firstPosition() const
QTextFrame::iterator end() const
QTextCursor firstCursorPosition() const
void setFormat(const QTextCharFormat &format)
QTextCursor lastCursorPosition() const
int tableCellFormatIndex() const
QTextFrame::iterator begin() const
The QTextTableFormat class provides formatting information for tables in a QTextDocument....
QList< QTextLength > columnWidthConstraints() const
void setColumnWidthConstraints(const QList< QTextLength > &constraints)
void setColumns(int columns)
The QTextTable class represents a table in a QTextDocument. \inmodule QtGui.
void removeRows(int pos, int num)
QTextTableFormat format() const
QTextCursor rowStart(const QTextCursor &c) const
friend class QTextTableCell
void appendRows(int count)
void removeColumns(int pos, int num)
void insertRows(int pos, int num)
void splitCell(int row, int col, int numRows, int numCols)
QTextTable(QTextDocument *doc)
void appendColumns(int count)
QTextCursor rowEnd(const QTextCursor &c) const
void setFormat(const QTextTableFormat &format)
void insertColumns(int pos, int num)
QTextTableCell cellAt(int row, int col) const
void mergeCells(int row, int col, int numRows, int numCols)
void resize(int rows, int cols)
static QTextTable * createTable(QTextDocumentPrivate *, int pos, int rows, int cols, const QTextTableFormat &tableFormat)
void fragmentRemoved(QChar type, uint fragment) override
int findCellIndex(int fragment) const
void fragmentAdded(QChar type, uint fragment) override
bool blockFragmentUpdates
QMap< QString, QString > map
[6]
QHighDpiScaling::Point position(T, QHighDpiScaling::Point::Kind)
GLboolean GLboolean GLboolean b
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum format
GLenum GLenum GLsizei void GLsizei void * column
GLdouble GLdouble GLdouble GLdouble q
GLenum GLenum GLsizei void * row
GLenum GLenum GLsizei void GLsizei void void * span
GLenum GLenum GLsizei void * table
#define QTextBeginningOfFrame
QFragmentFindHelper(int _pos, const QTextDocumentPrivate::FragmentMap &map)
const QTextDocumentPrivate::FragmentMap & fragmentMap
qsizetype indexOf(const AT &t, qsizetype from=0) const noexcept
bool contains(const AT &t) const noexcept