42 #include <private/qtools_p.h> 61 #define PMDEBUG if(0) qDebug 64 #if !defined(Q_CC_DIAB) 65 # define QT_INIT_TEXTUNDOCOMMAND(c, a1, a2, a3, a4, a5, a6, a7, a8) \ 66 QTextUndoCommand c = { a1, a2, 0, 0, quint8(a3), a4, quint32(a5), quint32(a6), { int(a7) }, quint32(a8) } 68 # define QT_INIT_TEXTUNDOCOMMAND(c, a1, a2, a3, a4, a5, a6, a7, a8) \ 69 QTextUndoCommand c = { a1, a2, 0, 0, a3, a4, a5, a6 }; c.blockFormat = a7; c.revision = a8 150 if (command == Inserted
151 && (pos + length == other.
pos)
152 && (strPos + length == other.
strPos)
160 if (command == Removed
162 && (strPos + length == other.
strPos)
170 if (command == Removed
186 : wasUndoAvailable(false),
187 wasRedoAvailable(false),
188 docChangeOldLength(0),
192 initialBlockCharFormatIndex(-1)
280 q->contentsChange(0, len, 0);
305 const bool firstLayout = !
lout;
313 emit q->documentLayoutChanged();
343 frame->d_func()->fragmentAdded(
text.
at(strPos), x);
370 if (key != block_pos) {
374 size += oldSize - (block_pos-
key);
388 frame->d_func()->fragmentAdded(
text.
at(strPos), x);
410 bool atBlockEnd =
true;
411 bool atBlockStart =
true;
427 op, charFormat, strPos, pos, blockFormat,
566 #if !defined(QT_NO_DEBUG) 570 if (child == possibleAncestor)
587 const bool needsInsert = to != -1;
589 #if !defined(QT_NO_DEBUG) 590 const bool startAndEndInSameFrame = (
frameAt(pos) ==
frameAt(pos + length - 1));
595 const bool startIsStartOfFrameAndEndIsEndOfFrameWithCommonParent
603 Q_ASSERT(startAndEndInSameFrame || endIsEndOfChildFrame || startIsStartOfFrameAndEndIsEndOfFrameWithCommonParent || isFirstTableCell);
652 cInsert.blockFormat =
c.blockFormat;
677 move(pos, -1, length, op);
693 int newFormatIdx = -1;
705 format.
merge(newFormat);
720 const int startPos = pos;
721 const int endPos = pos +
length;
726 while (pos < endPos) {
734 int offset = pos - it.position();
735 int length =
qMin(endPos - pos,
int(fragment->size_array[0] - offset));
736 int oldFormat = fragment->format;
740 format.
merge(newFormat);
748 fragment->format = newFormatIdx;
756 Q_ASSERT(pos == (
int)(it.position() + fragment->size_array[0]) || pos >= endPos);
770 endIt = endIt.
next();
771 for (; blockIt.
isValid() && blockIt != endIt; blockIt = blockIt.
next())
788 int newFormatIdx = -1;
798 for (; it !=
end; it = it.next()) {
803 format.
merge(newFormat);
812 0, it.position(), 1, 0);
815 if (group != oldGroup) {
891 int resetBlockRevision = c.
pos;
905 if (editPos != (
int)c.
pos)
925 resetBlockRevision += 1;
930 if (editPos != (
int)c.
pos)
936 resetBlockRevision = -1;
941 int oldFormat = it.value()->format;
944 if (editPos != (
int)c.
pos)
951 resetBlockRevision = -1;
961 if (group != oldGroup) {
974 resetBlockRevision = -1;
975 PMDEBUG(
" group format change");
988 resetBlockRevision = -1;
999 if (resetBlockRevision >= 0) {
1020 int newCursorPos = -1;
1023 newCursorPos = editPos + editLength;
1031 return newCursorPos;
1102 bool undoCommandsAvailable =
undoState != 0;
1116 && redoCommandsAvailable) {
1134 if (emitSignals && undoCommandsAvailable)
1136 if (emitSignals && redoCommandsAvailable)
1145 emit q->undoAvailable(available);
1154 emit q->redoAvailable(available);
1243 foreach (
const QTextCursor &cursor, changedCursors)
1244 emit q->cursorPositionChanged(cursor);
1299 if (addedOrRemoved > 0) {
1312 int added =
qMax(0, addedOrRemoved);
1313 int removed =
qMax(0, -addedOrRemoved);
1323 int removedInside =
qMax(0, overlap_end - overlap_start);
1324 removed -= removedInside;
1362 if (position ==
length()-1)
1368 if (position == end)
1381 if (position == start)
1410 b->d_func()->markBlocksDirty();
1428 int last = children.
size() - 1;
1429 while (first <= last) {
1430 int mid = (first + last) / 2;
1434 else if (pos < c->firstPosition())
1494 Q_ASSERT(frame->d_func()->fragment_start ==
it.n || frame->d_func()->fragment_start == 0);
1501 Q_ASSERT(frame->d_func()->fragment_end ==
it.n || frame->d_func()->fragment_end == 0);
1505 Q_ASSERT(frame->d_func()->fragment_start ==
it.n || frame->d_func()->fragment_start == 0);
1506 Q_ASSERT(frame->d_func()->fragment_end ==
it.n || frame->d_func()->fragment_end == 0);
1528 if (start < c->firstPosition() && end > c->
lastPosition()) {
1550 Q_ASSERT(start <= end || end == -1);
1569 frame->d_func()->fragment_start =
find(start).n;
1570 frame->d_func()->fragment_end =
find(end).n;
1600 if (objectIndex < 0)
1637 const int objIdx =
object->d_func()->objectIndex;
1654 emit q->contentsChanged();
1662 const uint garbageCollectionThreshold = 96 * 1024;
1678 it->stringPosition = newLen;
1679 newTextPtr +=
it->size_array[0];
1680 newLen +=
it->size_array[0];
void appendUndoItem(QAbstractUndoItem *)
Appends a custom undo item to the undo stack.
int objectIndex() const
Returns the index of the format object, or -1 if the format object is invalid.
T qobject_cast(QObject *object)
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
QTextCharFormat charFormat(int index) const
QTextEngine * engine() const
QTextObject * objectForIndex(int objectIndex) const
int objectFormatIndex(int objectIndex) const
bool ensureMaximumBlockCount()
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
int remove_block(int pos, int *blockformat, int command, QTextUndoCommand::Operation op)
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
#define QT_END_NAMESPACE
This macro expands to.
FragmentIterator end() const
QTextFormatCollection formats
static QTextFrame * findChildFrame(QTextFrame *f, int pos)
const QChar at(int i) const
Returns the character at the given index position in the string.
void remove(int i)
Removes the element at index position i.
void remove(int pos, int length, QTextUndoCommand::Operation=QTextUndoCommand::MoveCursor)
#define it(className, varName)
QAbstractTextDocumentLayout * lout
The QTextFrame class represents a frame in a QTextDocument.
void deleteObject(QTextObject *object)
void emitUndoAvailable(bool available)
int selectionEnd() const
Returns the end of the selection or position() if the cursor doesn't have a selection.
void chop(int n)
Removes n characters from the end of the string.
int length() const
Returns the number of characters in this string.
void setBlockCharFormat(const QTextCharFormat &format)
Sets the block char format of the current block (or all blocks that are contained in the selection) t...
QList< QTextCursorPrivate * > cursors
void insert_string(int pos, uint strPos, uint length, int format, QTextUndoCommand::Operation op)
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
int createObjectIndex(const QTextFormat &f)
void insert(int i, const T &t)
Inserts value at index position i in the list.
int nextCursorPosition(int oldPos, CursorMode mode=SkipCharacters) const
Returns the next valid cursor position after oldPos that respects the given cursor mode...
static bool noBlockInString(const QString &str)
void removeFrame(QTextFrame *frame)
bool isValid() const
Returns true if this block format is valid; otherwise returns false.
int count(const T &t) const
Returns the number of occurrences of value in the list.
#define QTextBeginningOfFrame
void setBlockFormat(const QTextBlock &from, const QTextBlock &to, const QTextBlockFormat &newFormat, FormatChangeMode mode=SetFormat)
QAbstractTextDocumentLayout * layout() const
void setLayout(QAbstractTextDocumentLayout *layout)
bool isRedoAvailable() const
The QString class provides a Unicode character string.
QTextFormat format(int idx) const
bool isValid() const
Returns true if this character format is valid; otherwise returns false.
QTextFormat objectFormat(int objectIndex) const
QString plainText() const
void setSize(uint node, int new_size, uint field=0)
int firstPosition() const
Returns the first document position inside the frame.
uint insert_single(int key, uint length)
int blockCharFormatIndex(int node) const
uint erase_single(uint f)
void aboutToRemoveCell(int from, int to)
The QChar class provides a 16-bit Unicode character.
QChar * data()
Returns a pointer to the data stored in the QString.
int insertBlock(int pos, int blockFormat, int charFormat, QTextUndoCommand::Operation=QTextUndoCommand::MoveCursor)
QTextOption defaultTextOption
void insert(int pos, const QString &text, int format)
FragmentMap::ConstIterator FragmentIterator
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
void resize(int size)
Sets the size of the vector to size.
void documentChange(int from, int length)
QTextBlock next() const
Returns the text block in the document after this block, or an empty text block if this is the last o...
int position() const
Returns the index of the block's first character within the document.
int leftCursorPosition(int position) const
void adjustDocumentChangesAndCursors(int from, int addedOrRemoved, QTextUndoCommand::Operation op)
static void clearFrame(QTextFrame *f)
bool setPosition(int newPosition)
static bool isValidBlockSeparator(const QChar &ch)
int type() const
Returns the type of this format.
void append(const T &t)
Inserts value at the end of the list.
void clearUndoRedoStacks(QTextDocument::Stacks stacksToClear, bool emitSignals=false)
#define QT_BEGIN_NAMESPACE
This macro expands to.
FragmentIterator find(int pos) const
int objectIndex() const
Returns the object index of this object.
QTextFrame * frameAt(int pos) const
int lastPosition() const
Returns the last document position inside the frame.
uint blockCursorAdjustment
int size() const
Returns the number of characters in this string.
const QChar * unicode() const
Returns a '\0'-terminated Unicode representation of the string.
The QTextFormat class provides formatting information for a QTextDocument.
QTextFrame * parentFrame() const
Returns the frame's parent frame.
The QTextCursor class offers an API to access and modify QTextDocuments.
QTextFrame * rootFrame() const
bool isUndoAvailable() const
static bool isAncestorFrame(QTextFrame *possibleAncestor, QTextFrame *child)
void enableUndoRedo(bool enable)
const T value(const Key &key) const
Returns the value associated with the key key.
void changeObjectFormat(QTextObject *group, int format)
void insert_frame(QTextFrame *f)
const T & at(int i) const
Returns the item at index position i in the list.
QTextObject * objectForFormat(int formatIndex) const
QTextObject * createObject(const QTextFormat &newFormat, int objectIndex=-1)
QAbstractUndoItem * custom
void append(const T &t)
Inserts value at the end of the vector.
QMap< QUrl, QVariant > cachedResources
uint needsEnsureMaximumBlockCount
int length(uint field=0) const
The QTextBlock class provides a container for text fragments in a QTextDocument.
static const char * data(const QByteArray &arr)
#define QT_INIT_TEXTUNDOCOMMAND(c, a1, a2, a3, a4, a5, a6, a7, a8)
uint position(uint node, uint field=0) const
void undoCommandAdded()
This signal is emitted every time a new level of undo is added to the QTextDocument.
static const QTextBlockData * block(const QTextBlock &it)
void clear()
Removes all items from the list.
int length() const
Returns the length of the block in characters.
void joinPreviousEditBlock()
QTextBlockFormat blockFormat(int index) const
The QTextTable class represents a table in a QTextDocument.
void emitRedoAvailable(bool available)
void squeeze()
Releases any memory not required to store the character data.
void removeSelectedText()
If there is a selection, its content is deleted; otherwise does nothing.
int rightCursorPosition(int position) const
virtual void blockInserted(const QTextBlock &block)
Appends the given block to the end of the group.
uint size(uint node, uint field=0) const
virtual QTextObject * createObject(const QTextFormat &f)
Creates and returns a new document object (a QTextObject), based on the given format.
QTextCharFormat blockCharFormat() const
Returns the block character format of the block the cursor is in.
Iterator find(int k, uint field=0)
iterator begin()
Returns an STL-style iterator pointing to the first item in the map.
void resize(int size)
Sets the size of the string to size characters.
void setObjectFormatIndex(int objectIndex, int formatIndex)
QList< QTextFrame * > childFrames() const
Returns a (possibly empty) list of the frame's child frames.
Fragment * fragment(uint index)
int remove(const Key &key)
Removes all the items that have the key key from the map.
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
virtual void blockRemoved(const QTextBlock &block)
Removes the given block from the group; the block itself is not deleted, it simply isn't a member of ...
int previousCursorPosition(int position, QTextLayout::CursorMode mode) const
QString & append(QChar c)
The QMap::iterator class provides an STL-style non-const iterator for QMap and QMultiMap.
void merge(const QTextFormat &other)
Merges the other format with this format; where there are conflicts the other format takes precedence...
int capacity() const
Returns the maximum number of characters that can be stored in the string without forcing a reallocat...
int nextCursorPosition(int position, QTextLayout::CursorMode mode) const
FragmentIterator begin() const
The QTextBlockGroup class provides a container for text blocks within a QTextDocument.
void clear()
Clears the contents of the string and makes it empty.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the map...
uint previous(uint n) const
AdjustResult adjustPosition(int positionOfChange, int charsAddedOrRemoved, QTextUndoCommand::Operation op)
uint findNode(int k, uint field=0) const
int editBlockCursorPosition
bool isBlockFormat() const
Returns true if this text format is a BlockFormat; otherwise returns false.
The QTextFrameFormat class provides formatting information for frames in a QTextDocument.
int size() const
Returns the number of items in the list.
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)
QTextDocumentPrivate * priv
int rightCursorPosition(int oldPos) const
Returns the cursor position to the right of oldPos, next to it.
int remove_string(int pos, uint length, QTextUndoCommand::Operation op)
bool isCharFormat() const
Returns true if this text format is a CharFormat; otherwise returns false.
QVector< QTextUndoCommand > undoStack
int insert_block(int pos, uint strPos, int format, int blockformat, QTextUndoCommand::Operation op, int command)
bool movePosition(MoveOperation op, MoveMode=MoveAnchor, int n=1)
Moves the cursor by performing the given operation n times, using the specified mode, and returns true if all operations were completed successfully; otherwise returns false.
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
bool isValid() const
Returns true if this text block is valid; otherwise returns false.
iterator erase(iterator it)
Removes the (key, value) pair pointed to by the iterator pos from the map, and returns an iterator to...
void scan_frames(int pos, int charsRemoved, int charsAdded)
void setMargin(qreal margin)
Sets the frame's margin in pixels.
void setWrapMode(WrapMode wrap)
Sets the option's text wrap mode to the given mode.
Qt::CursorMoveStyle defaultCursorMoveStyle
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 leftCursorPosition(int oldPos) const
Returns the cursor position to the left of oldPos, next to it.
QTextFrame * insertFrame(int start, int end, const QTextFrameFormat &format)
virtual void blockFormatChanged(const QTextBlock &block)
This function is called whenever the specified block of text is changed.
QTextBlock blocksFind(int pos) const
void setCharFormat(int pos, int length, const QTextCharFormat &newFormat, FormatChangeMode mode=SetFormat)
void setObjectIndex(int object)
Sets the format object's object index.
bool tryMerge(const QTextUndoCommand &other)
The QTextObject class is a base class for different kinds of objects that can group parts of a QTextD...
int previousCursorPosition(int oldPos, CursorMode mode=SkipCharacters) const
Returns the first valid cursor position before oldPos that respects the given cursor mode...
uint unreachableCharacterCount
int indexForFormat(const QTextFormat &f)
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
int size() const
Returns the number of items in the vector.
int initialBlockCharFormatIndex
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...
const QChar * constData() const
Returns a pointer to the data stored in the QString.
QMap< int, QTextObject * > objects
void clear()
Removes all items from the map.
int selectionStart() const
Returns the start of the selection or position() if the cursor doesn't have a selection.
void setTabStop(qreal tabStop)
Sets the default distance in device units between tab stops to the value specified by tabStop...
virtual void documentChanged(int from, int charsRemoved, int charsAdded)=0
This function is called whenever the contents of the document change.
QTextDocument * document()
The QList class is a template class that provides lists.
void compressPieceTable()
The QAbstractTextDocumentLayout class is an abstract base class used to implement custom layouts for ...
void removeAt(int i)
Removes the item at index position i.
QTextLayout * layout() const
Returns the QTextLayout that is used to lay out and display the block's contents. ...