QTextDocumentPrivate Class Reference

#include <qtextdocument_p.h>

Inheritance diagram for QTextDocumentPrivate:

Inheritance graph
[legend]
Collaboration diagram for QTextDocumentPrivate:

Collaboration graph
[legend]
List of all members.

Detailed Description

Definition at line 135 of file qtextdocument_p.h.

Public Types

enum  FormatChangeMode
typedef QFragmentMap< QTextFragmentDataFragmentMap
typedef FragmentMap::ConstIterator FragmentIterator
typedef QFragmentMap< QTextBlockDataBlockMap

Public Member Functions

 QTextDocumentPrivate ()
 ~QTextDocumentPrivate ()
void init ()
void clear ()
void setLayout (QAbstractTextDocumentLayout *layout)
void insert (int pos, const QString &text, int format)
void insert (int pos, int strPos, int strLength, int format)
int insertBlock (int pos, int blockFormat, int charFormat, QTextUndoCommand::Operation=QTextUndoCommand::MoveCursor)
int insertBlock (const QChar &blockSeparator, int pos, int blockFormat, int charFormat, QTextUndoCommand::Operation op=QTextUndoCommand::MoveCursor)
void remove (int pos, int length, QTextUndoCommand::Operation=QTextUndoCommand::MoveCursor)
QTextFrameinsertFrame (int start, int end, const QTextFrameFormat &format)
void removeFrame (QTextFrame *frame)
void setCharFormat (int pos, int length, const QTextCharFormat &newFormat, FormatChangeMode mode=SetFormat)
void setBlockFormat (const QTextBlock &from, const QTextBlock &to, const QTextBlockFormat &newFormat, FormatChangeMode mode=SetFormat)
int undoRedo (bool undo)
void undo ()
void redo ()
void appendUndoItem (QAbstractUndoItem *)
void beginEditBlock ()
void joinPreviousEditBlock ()
void endEditBlock ()
void enableUndoRedo (bool enable)
bool isUndoRedoEnabled () const
bool isUndoAvailable () const
bool isRedoAvailable () const
QString buffer () const
QString plainText () const
int length () const
QTextFormatCollectionformatCollection ()
const QTextFormatCollectionformatCollection () const
QAbstractTextDocumentLayoutlayout () const
FragmentIterator find (int pos) const
FragmentIterator begin () const
FragmentIterator end () const
QTextBlock blocksBegin () const
QTextBlock blocksEnd () const
QTextBlock blocksFind (int pos) const
int blockCharFormatIndex (int node) const
int numBlocks () const
const BlockMapblockMap () const
const FragmentMapfragmentMap () const
int nextCursorPosition (int position, QTextLayout::CursorMode mode) const
int previousCursorPosition (int position, QTextLayout::CursorMode mode) const
void changeObjectFormat (QTextObject *group, int format)
void setModified (bool m)
bool isModified () const
QFont defaultFont () const
void setDefaultFont (const QFont &f)
void documentChange (int from, int length)
void addCursor (QTextCursorPrivate *c)
void removeCursor (QTextCursorPrivate *c)
QTextFrameframeAt (int pos) const
QTextFramerootFrame () const
QTextObjectobjectForIndex (int objectIndex) const
QTextObjectobjectForFormat (int formatIndex) const
QTextObjectobjectForFormat (const QTextFormat &f) const
QTextObjectcreateObject (const QTextFormat &newFormat, int objectIndex=-1)
void deleteObject (QTextObject *object)
QTextDocumentdocument ()
const QTextDocumentdocument () const
void ensureMaximumBlockCount ()

Static Public Member Functions

static const QTextBlockDatablock (const QTextBlock &it)

Public Attributes

QCss::StyleSheet parsedDefaultStyleSheet
int maximumBlockCount
bool inContentsChange
QSizeF pageSize
QString title

Private Member Functions

bool split (int pos)
bool unite (uint f)
void truncateUndoStack ()
void insert_string (int pos, uint strPos, uint length, int format, QTextUndoCommand::Operation op)
int insert_block (int pos, uint strPos, int format, int blockformat, QTextUndoCommand::Operation op, int command)
int remove_string (int pos, uint length, QTextUndoCommand::Operation op)
int remove_block (int pos, int *blockformat, int command, QTextUndoCommand::Operation op)
void insert_frame (QTextFrame *f)
void scan_frames (int pos, int charsRemoved, int charsAdded)
void adjustDocumentChangesAndCursors (int from, int addedOrRemoved, QTextUndoCommand::Operation op)
 QTextDocumentPrivate (const QTextDocumentPrivate &m)
QTextDocumentPrivateoperator= (const QTextDocumentPrivate &m)
void appendUndoItem (const QTextUndoCommand &c)
void contentsChanged ()

Static Private Member Functions

static void clearFrame (QTextFrame *f)

Private Attributes

QString text
QVector< QTextUndoCommandundoStack
bool undoEnabled
int undoState
int modifiedState
bool modified
int editBlock
int docChangeFrom
int docChangeOldLength
int docChangeLength
bool framesDirty
QTextFormatCollection formats
QTextFramertFrame
QAbstractTextDocumentLayoutlout
FragmentMap fragments
BlockMap blocks
int initialBlockCharFormatIndex
QList< QTextCursorPrivate * > cursors
QList< QTextCursorPrivate * > changedCursors
QMap< int, QTextObject * > objects
QMap< QUrl, QVariantresources
QMap< QUrl, QVariantcachedResources
QString defaultStyleSheet
bool useDesignMetrics


Member Typedef Documentation

typedef QFragmentMap<QTextFragmentData> QTextDocumentPrivate::FragmentMap

Definition at line 139 of file qtextdocument_p.h.

typedef FragmentMap::ConstIterator QTextDocumentPrivate::FragmentIterator

Definition at line 140 of file qtextdocument_p.h.

typedef QFragmentMap<QTextBlockData> QTextDocumentPrivate::BlockMap

Definition at line 141 of file qtextdocument_p.h.


Member Enumeration Documentation

enum QTextDocumentPrivate::FormatChangeMode

Definition at line 162 of file qtextdocument_p.h.


Constructor & Destructor Documentation

QTextDocumentPrivate::QTextDocumentPrivate (  ) 

Definition at line 157 of file qtextdocument_p.cpp.

References docChangeFrom, editBlock, inContentsChange, lout, maximumBlockCount, modified, modifiedState, undoEnabled, undoState, and useDesignMetrics.

00158 {
00159     editBlock = 0;
00160     docChangeFrom = -1;
00161 
00162     undoState = 0;
00163 
00164     lout = 0;
00165 
00166     modified = false;
00167     modifiedState = 0;
00168 
00169     undoEnabled = true;
00170     inContentsChange = false;
00171 
00172     useDesignMetrics = false;
00173     maximumBlockCount = 0;
00174 }

QTextDocumentPrivate::~QTextDocumentPrivate (  ) 

Definition at line 234 of file qtextdocument_p.cpp.

References QList< T >::at(), QList< T >::clear(), QList< T >::count(), cursors, i, QTextCursorPrivate::priv, truncateUndoStack(), undoEnabled, and undoState.

00235 {
00236     for (int i = 0; i < cursors.count(); ++i)
00237         cursors.at(i)->priv = 0;
00238     cursors.clear();
00239     undoState = 0;
00240     undoEnabled = true;
00241     truncateUndoStack();
00242 }

Here is the call graph for this function:

QTextDocumentPrivate::QTextDocumentPrivate ( const QTextDocumentPrivate m  )  [private]


Member Function Documentation

void QTextDocumentPrivate::init (  ) 

Definition at line 176 of file qtextdocument_p.cpp.

References formats, framesDirty, QTextFormatCollection::indexForFormat(), initialBlockCharFormatIndex, insertBlock(), modified, modifiedState, rtFrame, undoEnabled, and undoState.

Referenced by clear().

00177 {
00178     rtFrame = 0;
00179     framesDirty = false;
00180 
00181     bool undoState = undoEnabled;
00182     undoEnabled = false;
00183     initialBlockCharFormatIndex = formats.indexForFormat(QTextCharFormat());
00184     insertBlock(0, formats.indexForFormat(QTextBlockFormat()), formats.indexForFormat(QTextCharFormat()));
00185     undoEnabled = undoState;
00186     modified = false;
00187     modifiedState = 0;
00188 }

Here is the call graph for this function:

void QTextDocumentPrivate::clear (  ) 

Definition at line 190 of file qtextdocument_p.cpp.

References QTextCursorPrivate::anchor, QList< T >::at(), QMap< Key, T >::begin(), blocks, cachedResources, changedCursors, QFragmentMap< T >::clear(), QMap< Key, T >::clear(), QString::clear(), QList< T >::clear(), QList< T >::count(), cursors, QAbstractTextDocumentLayout::documentChanged(), QMap< Key, T >::end(), QMap< Key, T >::erase(), formats, fragments, i, init(), len, QFragmentMap< T >::length(), lout, modified, modifiedState, objects, rtFrame, QTextCursorPrivate::setPosition(), text, title, truncateUndoStack(), and undoState.

00191 {
00192     Q_Q(QTextDocument);
00193     for (int i = 0; i < cursors.count(); ++i) {
00194         cursors.at(i)->setPosition(0);
00195         cursors.at(i)->anchor = 0;
00196     }
00197 
00198     QList<QTextCursorPrivate *>oldCursors = cursors;
00199     cursors.clear();
00200     changedCursors.clear();
00201 
00202     QMap<int, QTextObject *>::Iterator objectIt = objects.begin();
00203     while (objectIt != objects.end()) {
00204         if (*objectIt != rtFrame) {
00205             delete *objectIt;
00206             objectIt = objects.erase(objectIt);
00207         } else {
00208             ++objectIt;
00209         }
00210     }
00211     // also clear out the remaining root frame pointer
00212     // (we're going to delete the object further down)
00213     objects.clear();
00214 
00215     title.clear();
00216     undoState = 0;
00217     truncateUndoStack();
00218     text = QString();
00219     modifiedState = 0;
00220     modified = false;
00221     formats = QTextFormatCollection();
00222     int len = fragments.length();
00223     fragments.clear();
00224     blocks.clear();
00225     cachedResources.clear();
00226     q->contentsChange(0, len, 0);
00227     if (lout)
00228         lout->documentChanged(0, len, 0);
00229     delete rtFrame;
00230     init();
00231     cursors = oldCursors;
00232 }

Here is the call graph for this function:

void QTextDocumentPrivate::setLayout ( QAbstractTextDocumentLayout layout  ) 

Definition at line 244 of file qtextdocument_p.cpp.

References QFragmentMap< T >::begin(), blocks, QAbstractTextDocumentLayout::documentChanged(), emit, layout(), length(), and lout.

00245 {
00246     Q_Q(QTextDocument);
00247     if (lout == layout)
00248         return;
00249     delete lout;
00250     lout = layout;
00251 
00252     for (BlockMap::Iterator it = blocks.begin(); !it.atEnd(); ++it)
00253         it->free();
00254 
00255     emit q->contentsChange(0, 0, length());
00256     if (lout)
00257         lout->documentChanged(0, 0, length());
00258 }

Here is the call graph for this function:

void QTextDocumentPrivate::insert ( int  pos,
const QString text,
int  format 
)

Definition at line 389 of file qtextdocument_p.cpp.

References QString::append(), QString::length(), noBlockInString(), QString::size(), and text.

Referenced by QTextCopyHelper::appendFragment().

00390 {
00391     if (str.size() == 0)
00392         return;
00393 
00394     Q_ASSERT(noBlockInString(str));
00395 
00396     int strPos = text.length();
00397     text.append(str);
00398     insert(pos, strPos, str.length(), format);
00399 }

Here is the call graph for this function:

void QTextDocumentPrivate::insert ( int  pos,
int  strPos,
int  strLength,
int  format 
)

Definition at line 369 of file qtextdocument_p.cpp.

References appendUndoItem(), beginEditBlock(), c, endEditBlock(), QTextFormatCollection::format(), formats, fragments, insert_string(), QTextUndoCommand::Inserted, QTextFormat::isCharFormat(), QFragmentMap< T >::length(), QTextUndoCommand::MoveCursor, QVector< T >::size(), undoStack, and undoState.

00370 {
00371     if (strLength <= 0)
00372         return;
00373 
00374     Q_ASSERT(pos >= 0 && pos < fragments.length());
00375     Q_ASSERT(formats.format(format).isCharFormat());
00376 
00377     insert_string(pos, strPos, strLength, format, QTextUndoCommand::MoveCursor);
00378 
00379     beginEditBlock();
00380 
00381     QTextUndoCommand c = { QTextUndoCommand::Inserted, true,
00382                       QTextUndoCommand::MoveCursor, format, strPos, pos, { strLength } };
00383     appendUndoItem(c);
00384     Q_ASSERT(undoState == undoStack.size());
00385 
00386     endEditBlock();
00387 }

Here is the call graph for this function:

int QTextDocumentPrivate::insertBlock ( int  pos,
int  blockFormat,
int  charFormat,
QTextUndoCommand::Operation  = QTextUndoCommand::MoveCursor 
)

Definition at line 364 of file qtextdocument_p.cpp.

References QChar::ParagraphSeparator.

Referenced by QTextCopyHelper::appendFragment(), QTextCopyHelper::copy(), QTextTablePrivate::createTable(), init(), QTextCursorPrivate::insertBlock(), and insertFrame().

00365 {
00366     return insertBlock(QChar::ParagraphSeparator, pos, blockFormat, charFormat, op);
00367 }

int QTextDocumentPrivate::insertBlock ( const QChar blockSeparator,
int  pos,
int  blockFormat,
int  charFormat,
QTextUndoCommand::Operation  op = QTextUndoCommand::MoveCursor 
)

Definition at line 335 of file qtextdocument_p.cpp.

References QString::append(), appendUndoItem(), beginEditBlock(), QTextUndoCommand::BlockInserted, QTextUndoCommand::BlockRemoved, blocks, c, QTextFormatCollection::charFormat(), endEditBlock(), ensureMaximumBlockCount(), QTextFormatCollection::format(), formats, fragments, insert_block(), QTextFormat::isBlockFormat(), QTextFormat::isCharFormat(), isValidBlockSeparator(), QString::length(), QFragmentMap< T >::length(), QTextFormat::objectIndex(), QVector< T >::size(), text, undoStack, and undoState.

00337 {
00338     Q_ASSERT(formats.format(blockFormat).isBlockFormat());
00339     Q_ASSERT(formats.format(charFormat).isCharFormat());
00340     Q_ASSERT(pos >= 0 && (pos < fragments.length() || (pos == 0 && fragments.length() == 0)));
00341     Q_ASSERT(isValidBlockSeparator(blockSeparator));
00342 
00343     beginEditBlock();
00344 
00345     int strPos = text.length();
00346     text.append(blockSeparator);
00347     const int fragment = insert_block(pos, strPos, charFormat, blockFormat, op, QTextUndoCommand::BlockRemoved);
00348 
00349     Q_ASSERT(blocks.length() == fragments.length());
00350 
00351     QTextUndoCommand c = { QTextUndoCommand::BlockInserted, true,
00352                       op, charFormat, strPos, pos, { blockFormat } };
00353 
00354     appendUndoItem(c);
00355     Q_ASSERT(undoState == undoStack.size());
00356 
00357     if (formats.charFormat(charFormat).objectIndex() == -1)
00358         ensureMaximumBlockCount();
00359 
00360     endEditBlock();
00361     return fragment;
00362 }

Here is the call graph for this function:

void QTextDocumentPrivate::remove ( int  pos,
int  length,
QTextUndoCommand::Operation  = QTextUndoCommand::MoveCursor 
)

Definition at line 487 of file qtextdocument_p.cpp.

References appendUndoItem(), QString::at(), b, beginEditBlock(), QTextUndoCommand::BlockAdded, QTextUndoCommand::BlockDeleted, QTextUndoCommand::BlockRemoved, blocks, c, end(), endEditBlock(), find(), QFragmentMap< T >::findNode(), QFragmentMap< T >::fragment(), fragments, frameAt(), isAncestorFrame(), isValidBlockSeparator(), key, QFragmentMap< T >::length(), QString::mid(), n, QFragmentMap< T >::next(), noBlockInString(), QTextFrame::parentFrame(), QFragmentMap< T >::position(), QFragmentMap< T >::previous(), QTextBeginningOfFrame, QTextEndOfFrame, remove_block(), remove_string(), QTextUndoCommand::Removed, QFragmentMap< T >::size(), split(), text, unite(), w, X, and x.

Referenced by QTextCursorPrivate::clearCells(), QTextCursorPrivate::remove(), removeFrame(), and undoRedo().

00488 {
00489     Q_ASSERT(pos >= 0 && pos+length <= fragments.length());
00490     Q_ASSERT(blocks.length() == fragments.length());
00491 
00492 #if !defined(QT_NO_DEBUG)
00493     const bool startAndEndInSameFrame = (frameAt(pos) == frameAt(pos + length - 1));
00494 
00495     const bool endIsEndOfChildFrame = (isAncestorFrame(frameAt(pos), frameAt(pos + length - 1))
00496                                        && text.at(find(pos + length - 1)->stringPosition) == QTextEndOfFrame);
00497 
00498     const bool startIsStartOfFrameAndEndIsEndOfFrameWithCommonParent
00499                = (text.at(find(pos)->stringPosition) == QTextBeginningOfFrame
00500                   && text.at(find(pos + length - 1)->stringPosition) == QTextEndOfFrame
00501                   && frameAt(pos)->parentFrame() == frameAt(pos + length - 1)->parentFrame());
00502 
00503     Q_ASSERT(startAndEndInSameFrame || endIsEndOfChildFrame || startIsStartOfFrameAndEndIsEndOfFrameWithCommonParent);
00504 #endif
00505 
00506     beginEditBlock();
00507 
00508     split(pos);
00509     split(pos+length);
00510 
00511     uint x = fragments.findNode(pos);
00512     uint end = fragments.findNode(pos+length);
00513 
00514     uint w = 0;
00515     while (x != end) {
00516         uint n = fragments.next(x);
00517 
00518         uint key = fragments.position(x);
00519         uint b = blocks.findNode(key+1);
00520 
00521         QTextFragmentData *X = fragments.fragment(x);
00522         QTextUndoCommand c = { QTextUndoCommand::Removed, true,
00523                           op, X->format, X->stringPosition, key, { X->size } };
00524 
00525         if (key+1 != blocks.position(b)) {
00526 //      qDebug("remove_string from %d length %d", key, X->size);
00527             Q_ASSERT(noBlockInString(text.mid(X->stringPosition, X->size)));
00528             w = remove_string(key, X->size, op);
00529         } else {
00530 //      qDebug("remove_block at %d", key);
00531             Q_ASSERT(X->size == 1 && isValidBlockSeparator(text.at(X->stringPosition)));
00532             b = blocks.previous(b);
00533             c.command = blocks.size(b) == 1 ? QTextUndoCommand::BlockDeleted : QTextUndoCommand::BlockRemoved;
00534             w = remove_block(key, &c.blockFormat, QTextUndoCommand::BlockAdded, op);
00535         }
00536         appendUndoItem(c);
00537         x = n;
00538 
00539     }
00540     if (w)
00541         unite(w);
00542 
00543     Q_ASSERT(blocks.length() == fragments.length());
00544 
00545     endEditBlock();
00546 }

Here is the call graph for this function:

QTextFrame * QTextDocumentPrivate::insertFrame ( int  start,
int  end,
const QTextFrameFormat format 
)

Definition at line 1228 of file qtextdocument_p.cpp.

References beginEditBlock(), createObject(), endEditBlock(), find(), formats, frameAt(), QTextFormatCollection::indexForFormat(), insert_frame(), insertBlock(), QTextUndoCommand::KeepCursor, length(), QTextUndoCommand::MoveCursor, QFragmentMap< T >::ConstIterator::n, QTextObject::objectIndex(), QTextBeginningOfFrame, QTextEndOfFrame, and QTextFormat::setObjectIndex().

01229 {
01230     Q_ASSERT(start >= 0 && start < length());
01231     Q_ASSERT(end >= 0 && end < length());
01232     Q_ASSERT(start <= end || end == -1);
01233 
01234     if (start != end && frameAt(start) != frameAt(end))
01235         return 0;
01236 
01237     beginEditBlock();
01238 
01239     QTextFrame *frame = qobject_cast<QTextFrame *>(createObject(format));
01240     Q_ASSERT(frame);
01241 
01242     // #### using the default block and char format below might be wrong
01243     int idx = formats.indexForFormat(QTextBlockFormat());
01244     QTextCharFormat cfmt;
01245     cfmt.setObjectIndex(frame->objectIndex());
01246     int charIdx = formats.indexForFormat(cfmt);
01247 
01248     insertBlock(QTextBeginningOfFrame, start, idx, charIdx, QTextUndoCommand::MoveCursor);
01249     insertBlock(QTextEndOfFrame, ++end, idx, charIdx, QTextUndoCommand::KeepCursor);
01250 
01251     frame->d_func()->fragment_start = find(start).n;
01252     frame->d_func()->fragment_end = find(end).n;
01253 
01254     insert_frame(frame);
01255 
01256     endEditBlock();
01257 
01258     return frame;
01259 }

Here is the call graph for this function:

void QTextDocumentPrivate::removeFrame ( QTextFrame frame  ) 

Definition at line 1261 of file qtextdocument_p.cpp.

References beginEditBlock(), end(), endEditBlock(), QTextFrame::firstPosition(), QTextFrame::lastPosition(), QObjectData::parent, QTextFrame::parentFrame(), remove(), and start.

01262 {
01263     QTextFrame *parent = frame->d_func()->parentFrame;
01264     if (!parent)
01265         return;
01266 
01267     int start = frame->firstPosition();
01268     int end = frame->lastPosition();
01269     Q_ASSERT(end >= start);
01270 
01271     beginEditBlock();
01272 
01273     // remove already removes the frames from the tree
01274     remove(end, 1);
01275     remove(start-1, 1);
01276 
01277     endEditBlock();
01278 }

Here is the call graph for this function:

void QTextDocumentPrivate::setCharFormat ( int  pos,
int  length,
const QTextCharFormat newFormat,
FormatChangeMode  mode = SetFormat 
)

Definition at line 548 of file qtextdocument_p.cpp.

References appendUndoItem(), QFragmentMap< T >::Iterator::atEnd(), beginEditBlock(), block(), blocksFind(), c, QTextFormat::CharFormat, QTextUndoCommand::CharFormatChanged, QTextFormat::clearProperty(), documentChange(), endEditBlock(), QFragmentMap< T >::find(), QFragmentMap< T >::findNode(), QTextFormatCollection::format(), formats, fragments, QTextFormatCollection::indexForFormat(), initialBlockCharFormatIndex, QTextBlockData::invalidate(), QTextCharFormat::isValid(), QTextBlock::isValid(), MergeFormat, QTextUndoCommand::MoveCursor, n, QTextBlock::next(), QTextFormat::objectIndex(), QTextFormat::ObjectIndex, QFragmentMap< T >::Iterator::position(), qMin(), SetFormat, SetFormatAndPreserveObjectIndices, QTextFormat::setObjectIndex(), split(), QTextFormat::type(), unite(), and QFragmentMap< T >::Iterator::value().

Referenced by QTextCopyHelper::appendFragment(), QTextCursorPrivate::setCharFormat(), and undoRedo().

00549 {
00550     beginEditBlock();
00551 
00552     Q_ASSERT(newFormat.isValid());
00553 
00554     int newFormatIdx = -1;
00555     if (mode == SetFormatAndPreserveObjectIndices) {
00556         QTextCharFormat cleanFormat = newFormat;
00557         cleanFormat.clearProperty(QTextFormat::ObjectIndex);
00558         newFormatIdx = formats.indexForFormat(cleanFormat);
00559     } else if (mode == SetFormat) {
00560         newFormatIdx = formats.indexForFormat(newFormat);
00561     }
00562 
00563     if (pos == -1) {
00564         if (mode == MergeFormat) {
00565             QTextFormat format = formats.format(initialBlockCharFormatIndex);
00566             format.merge(newFormat);
00567             initialBlockCharFormatIndex = formats.indexForFormat(format);
00568         } else if (mode == SetFormatAndPreserveObjectIndices
00569                    && formats.format(initialBlockCharFormatIndex).objectIndex() != -1) {
00570             QTextCharFormat f = newFormat;
00571             f.setObjectIndex(formats.format(initialBlockCharFormatIndex).objectIndex());
00572             initialBlockCharFormatIndex = formats.indexForFormat(f);
00573         } else {
00574             initialBlockCharFormatIndex = newFormatIdx;
00575         }
00576 
00577         ++pos;
00578         --length;
00579     }
00580 
00581     const int startPos = pos;
00582     const int endPos = pos + length;
00583 
00584     split(startPos);
00585     split(endPos);
00586 
00587     while (pos < endPos) {
00588         FragmentMap::Iterator it = fragments.find(pos);
00589         Q_ASSERT(!it.atEnd());
00590 
00591         QTextFragmentData *fragment = it.value();
00592 
00593         Q_ASSERT(formats.format(fragment->format).type() == QTextFormat::CharFormat);
00594 
00595         int offset = pos - it.position();
00596         int length = qMin(endPos - pos, int(fragment->size - offset));
00597         int oldFormat = fragment->format;
00598 
00599         if (mode == MergeFormat) {
00600             QTextFormat format = formats.format(fragment->format);
00601             format.merge(newFormat);
00602             fragment->format = formats.indexForFormat(format);
00603         } else if (mode == SetFormatAndPreserveObjectIndices
00604                    && formats.format(oldFormat).objectIndex() != -1) {
00605             QTextCharFormat f = newFormat;
00606             f.setObjectIndex(formats.format(oldFormat).objectIndex());
00607             fragment->format = formats.indexForFormat(f);
00608         } else {
00609             fragment->format = newFormatIdx;
00610         }
00611 
00612         QTextUndoCommand c = { QTextUndoCommand::CharFormatChanged, true, QTextUndoCommand::MoveCursor, oldFormat,
00613                           0, pos, { length } };
00614         appendUndoItem(c);
00615 
00616         pos += length;
00617         Q_ASSERT(pos == (int)(it.position() + fragment->size) || pos >= endPos);
00618     }
00619 
00620     int n = fragments.findNode(startPos - 1);
00621     if (n)
00622         unite(n);
00623 
00624     n = fragments.findNode(endPos);
00625     if (n)
00626         unite(n);
00627 
00628     QTextBlock blockIt = blocksFind(startPos);
00629     QTextBlock endIt = blocksFind(endPos);
00630     if (endIt.isValid())
00631         endIt = endIt.next();
00632     for (; blockIt.isValid() && blockIt != endIt; blockIt = blockIt.next())
00633         QTextDocumentPrivate::block(blockIt)->invalidate();
00634 
00635     documentChange(startPos, length);
00636 
00637     endEditBlock();
00638 }

Here is the call graph for this function:

void QTextDocumentPrivate::setBlockFormat ( const QTextBlock from,
const QTextBlock to,
const QTextBlockFormat newFormat,
FormatChangeMode  mode = SetFormat 
)

Definition at line 640 of file qtextdocument_p.cpp.

References appendUndoItem(), beginEditBlock(), block(), QTextFormatCollection::blockFormat(), QTextUndoCommand::BlockFormatChanged, QTextBlockGroup::blockFormatChanged(), QTextBlockGroup::blockInserted(), c, documentChange(), end(), endEditBlock(), QTextBlockData::format, formats, QTextFormatCollection::indexForFormat(), QTextBlockData::invalidate(), QTextBlockFormat::isValid(), QTextBlock::length(), MergeFormat, QTextUndoCommand::MoveCursor, objectForFormat(), QTextBlock::position(), SetFormat, and SetFormatAndPreserveObjectIndices.

Referenced by QTextList::add(), QTextCopyHelper::appendFragment(), QTextList::remove(), and QTextCursorPrivate::setBlockFormat().

00642 {
00643     beginEditBlock();
00644 
00645     Q_ASSERT(mode != SetFormatAndPreserveObjectIndices); // only implemented for setCharFormat
00646 
00647     Q_ASSERT(newFormat.isValid());
00648 
00649     int newFormatIdx = -1;
00650     if (mode == SetFormat)
00651         newFormatIdx = formats.indexForFormat(newFormat);
00652     QTextBlockGroup *group = qobject_cast<QTextBlockGroup *>(objectForFormat(newFormat));
00653 
00654     QTextBlock it = from;
00655     QTextBlock end = to;
00656     if (end.isValid())
00657   end = end.next();
00658 
00659     for (; it != end; it = it.next()) {
00660         int oldFormat = block(it)->format;
00661         QTextBlockFormat format = formats.blockFormat(oldFormat);
00662         QTextBlockGroup *oldGroup = qobject_cast<QTextBlockGroup *>(objectForFormat(format));
00663         if (mode == MergeFormat) {
00664             format.merge(newFormat);
00665             newFormatIdx = formats.indexForFormat(format);
00666             group = qobject_cast<QTextBlockGroup *>(objectForFormat(format));
00667         }
00668         block(it)->format = newFormatIdx;
00669 
00670         block(it)->invalidate();
00671 
00672         QTextUndoCommand c = { QTextUndoCommand::BlockFormatChanged, true, QTextUndoCommand::MoveCursor, oldFormat,
00673                               0, it.position(), { 1 } };
00674         appendUndoItem(c);
00675 
00676         if (group != oldGroup) {
00677             if (oldGroup)
00678                 oldGroup->blockRemoved(it);
00679             if (group)
00680                 group->blockInserted(it);
00681         } else if (group) {
00682       group->blockFormatChanged(it);
00683   }
00684     }
00685 
00686     documentChange(from.position(), to.position() + to.length() - from.position());
00687 
00688     endEditBlock();
00689 }

Here is the call graph for this function:

int QTextDocumentPrivate::undoRedo ( bool  undo  ) 

Definition at line 738 of file qtextdocument_p.cpp.

References QFragmentMap< T >::ConstIterator::atEnd(), beginEditBlock(), block(), QTextUndoCommand::BlockAdded, QTextUndoCommand::BlockDeleted, QTextFormatCollection::blockFormat(), QTextUndoCommand::BlockFormatChanged, QTextBlockGroup::blockFormatChanged(), QTextBlockGroup::blockInserted(), QTextUndoCommand::BlockInserted, QTextUndoCommand::BlockRemoved, blocksFind(), c, changeObjectFormat(), QTextFormatCollection::charFormat(), QTextUndoCommand::CharFormatChanged, QTextUndoCommand::Custom, docChangeFrom, docChangeLength, documentChange(), emit, endEditBlock(), find(), QTextBlockData::format, formats, QTextUndoCommand::GroupFormatChange, insert_block(), insert_string(), QTextUndoCommand::Inserted, isRedoAvailable(), isUndoAvailable(), QTextBlock::isValid(), QTextBlock::length(), length(), object, objectForFormat(), objectForIndex(), QTextFormatCollection::objectFormatIndex(), PMDEBUG, QTextBlock::position(), qMin(), remove(), remove_block(), QTextUndoCommand::Removed, setCharFormat(), QVector< T >::size(), undoEnabled, undoStack, undoState, and QFragmentMap< T >::ConstIterator::value().

00739 {
00740     PMDEBUG("%s, undoState=%d, undoStack size=%d", undo ? "undo:" : "redo:", undoState, undoStack.size());
00741     if (!undoEnabled || (undo && undoState == 0) || (!undo && undoState == undoStack.size()))
00742         return -1;
00743 
00744     undoEnabled = false;
00745     beginEditBlock();
00746     while (1) {
00747         if (undo)
00748             --undoState;
00749         QTextUndoCommand &c = undoStack[undoState];
00750 
00751   switch(c.command) {
00752         case QTextUndoCommand::Inserted:
00753             remove(c.pos, c.length, (QTextUndoCommand::Operation)c.operation);
00754             PMDEBUG("   erase: from %d, length %d", c.pos, c.length);
00755             c.command = QTextUndoCommand::Removed;
00756       break;
00757         case QTextUndoCommand::Removed:
00758             PMDEBUG("   insert: format %d (from %d, length %d, strpos=%d)", c.format, c.pos, c.length, c.strPos);
00759             insert_string(c.pos, c.strPos, c.length, c.format, (QTextUndoCommand::Operation)c.operation);
00760             c.command = QTextUndoCommand::Inserted;
00761       break;
00762   case QTextUndoCommand::BlockInserted:
00763   case QTextUndoCommand::BlockAdded:
00764             remove_block(c.pos, &c.blockFormat, c.command, (QTextUndoCommand::Operation)c.operation);
00765             PMDEBUG("   blockremove: from %d", c.pos);
00766       if (c.command == QTextUndoCommand::BlockInserted)
00767     c.command = QTextUndoCommand::BlockRemoved;
00768       else
00769     c.command = QTextUndoCommand::BlockDeleted;
00770       break;
00771   case QTextUndoCommand::BlockRemoved:
00772   case QTextUndoCommand::BlockDeleted:
00773             PMDEBUG("   blockinsert: charformat %d blockformat %d (pos %d, strpos=%d)", c.format, c.blockFormat, c.pos, c.strPos);
00774             insert_block(c.pos, c.strPos, c.format, c.blockFormat, (QTextUndoCommand::Operation)c.operation, c.command);
00775       if (c.command == QTextUndoCommand::BlockRemoved)
00776     c.command = QTextUndoCommand::BlockInserted;
00777       else
00778     c.command = QTextUndoCommand::BlockAdded;
00779       break;
00780   case QTextUndoCommand::CharFormatChanged: {
00781             PMDEBUG("   charFormat: format %d (from %d, length %d)", c.format, c.pos, c.length);
00782             FragmentIterator it = find(c.pos);
00783             Q_ASSERT(!it.atEnd());
00784 
00785             int oldFormat = it.value()->format;
00786             setCharFormat(c.pos, c.length, formats.charFormat(c.format));
00787             c.format = oldFormat;
00788       break;
00789   }
00790   case QTextUndoCommand::BlockFormatChanged: {
00791             PMDEBUG("   blockformat: format %d pos %d", c.format, c.pos);
00792             QTextBlock it = blocksFind(c.pos);
00793             Q_ASSERT(it.isValid());
00794 
00795             int oldFormat = block(it)->format;
00796             block(it)->format = c.format;
00797             QTextBlockGroup *oldGroup = qobject_cast<QTextBlockGroup *>(objectForFormat(formats.blockFormat(oldFormat)));
00798             QTextBlockGroup *group = qobject_cast<QTextBlockGroup *>(objectForFormat(formats.blockFormat(c.format)));
00799             c.format = oldFormat;
00800             if (group != oldGroup) {
00801                 if (oldGroup)
00802                     oldGroup->blockRemoved(it);
00803                 if (group)
00804                     group->blockInserted(it);
00805             } else if (group) {
00806                 group->blockFormatChanged(it);
00807             }
00808             documentChange(it.position(), it.length());
00809       break;
00810   }
00811   case QTextUndoCommand::GroupFormatChange: {
00812             PMDEBUG("   group format change");
00813             QTextObject *object = objectForIndex(c.objectIndex);
00814             int oldFormat = formats.objectFormatIndex(c.objectIndex);
00815             changeObjectFormat(object, c.format);
00816             c.format = oldFormat;
00817       break;
00818   }
00819   case QTextUndoCommand::Custom:
00820             if (undo)
00821                 c.custom->undo();
00822             else
00823                 c.custom->redo();
00824       break;
00825   default:
00826       Q_ASSERT(false);
00827         }
00828         if (undo) {
00829             if (undoState == 0 || !undoStack[undoState-1].block)
00830                 break;
00831         } else {
00832             ++undoState;
00833             if (undoState == undoStack.size() || !undoStack[undoState-1].block)
00834                 break;
00835         }
00836     }
00837     undoEnabled = true;
00838     int editPos = -1;
00839     if (docChangeFrom >= 0) {
00840         editPos = qMin(docChangeFrom + docChangeLength, length() - 1);
00841     }
00842     endEditBlock();
00843     Q_Q(QTextDocument);
00844     emit q->undoAvailable(isUndoAvailable());
00845     emit q->redoAvailable(isRedoAvailable());
00846     return editPos;
00847 }

Here is the call graph for this function:

void QTextDocumentPrivate::undo (  )  [inline]

Definition at line 169 of file qtextdocument_p.h.

00169 { undoRedo(true); }

void QTextDocumentPrivate::redo (  )  [inline]

Definition at line 170 of file qtextdocument_p.h.

00170 { undoRedo(false); }

void QTextDocumentPrivate::appendUndoItem ( QAbstractUndoItem item  ) 

Appends a custom undo item to the undo stack.

Definition at line 852 of file qtextdocument_p.cpp.

References c, QTextUndoCommand::Custom, editBlock, QTextUndoCommand::MoveCursor, and undoEnabled.

Referenced by changeObjectFormat(), insert(), insertBlock(), remove(), setBlockFormat(), and setCharFormat().

00853 {
00854     if (!undoEnabled) {
00855         delete item;
00856         return;
00857     }
00858 
00859     QTextUndoCommand c;
00860     c.command = QTextUndoCommand::Custom;
00861     c.block = editBlock != 0;
00862     c.operation = QTextUndoCommand::MoveCursor;
00863     c.format = 0;
00864     c.strPos = 0;
00865     c.pos = 0;
00866     c.blockFormat = 0;
00867 
00868     c.custom = item;
00869     appendUndoItem(c);
00870 }

void QTextDocumentPrivate::beginEditBlock (  )  [inline]

Definition at line 172 of file qtextdocument_p.h.

Referenced by changeObjectFormat(), QTextCursorPrivate::clearCells(), QTextTablePrivate::createTable(), ensureMaximumBlockCount(), insert(), QTextDocumentFragmentPrivate::insert(), insertBlock(), insertFrame(), joinPreviousEditBlock(), QTextDocumentFragmentPrivate::QTextDocumentFragmentPrivate(), QTextCursorPrivate::remove(), remove(), removeFrame(), QTextCursorPrivate::setBlockCharFormat(), QTextCursorPrivate::setBlockFormat(), setBlockFormat(), QTextCursorPrivate::setCharFormat(), setCharFormat(), and undoRedo().

00172 { editBlock++; }

void QTextDocumentPrivate::joinPreviousEditBlock (  ) 

Definition at line 926 of file qtextdocument_p.cpp.

References beginEditBlock(), undoEnabled, undoStack, and undoState.

00927 {
00928     beginEditBlock();
00929 
00930     if (undoEnabled && undoState)
00931         undoStack[undoState - 1].block = true;
00932 }

Here is the call graph for this function:

void QTextDocumentPrivate::endEditBlock (  ) 

Definition at line 934 of file qtextdocument_p.cpp.

References changedCursors, contentsChanged(), docChangeFrom, docChangeLength, docChangeOldLength, QAbstractTextDocumentLayout::documentChanged(), editBlock, emit, framesDirty, inContentsChange, QList< T >::isEmpty(), lout, scan_frames(), QList< T >::takeFirst(), undoEnabled, undoStack, and undoState.

Referenced by changeObjectFormat(), QTextCursorPrivate::clearCells(), QTextTablePrivate::createTable(), ensureMaximumBlockCount(), insert(), QTextDocumentFragmentPrivate::insert(), insertBlock(), insertFrame(), QTextCursorPrivate::remove(), remove(), removeFrame(), QTextCursorPrivate::setBlockCharFormat(), QTextCursorPrivate::setBlockFormat(), setBlockFormat(), QTextCursorPrivate::setCharFormat(), setCharFormat(), and undoRedo().

00935 {
00936     Q_Q(QTextDocument);
00937     if (--editBlock)
00938         return;
00939 
00940     if (undoEnabled && undoState > 0)
00941         undoStack[undoState - 1].block = false;
00942 
00943     if (framesDirty)
00944         scan_frames(docChangeFrom, docChangeOldLength, docChangeLength);
00945 
00946     if (lout && docChangeFrom >= 0) {
00947         if (!inContentsChange) {
00948             inContentsChange = true;
00949             emit q->contentsChange(docChangeFrom, docChangeOldLength, docChangeLength);
00950             inContentsChange = false;
00951         }
00952         lout->documentChanged(docChangeFrom, docChangeOldLength, docChangeLength);
00953     }
00954 
00955     docChangeFrom = -1;
00956 
00957     while (!changedCursors.isEmpty()) {
00958         QTextCursorPrivate *curs = changedCursors.takeFirst();
00959         emit q->cursorPositionChanged(QTextCursor(curs));
00960     }
00961 
00962     contentsChanged();
00963 }

Here is the call graph for this function:

void QTextDocumentPrivate::enableUndoRedo ( bool  enable  ) 

Definition at line 913 of file qtextdocument_p.cpp.

References emit, modified, modifiedState, truncateUndoStack(), undoEnabled, and undoState.

00914 {
00915     Q_Q(QTextDocument);
00916     if (!enable) {
00917         undoState = 0;
00918         truncateUndoStack();
00919         emit q->undoAvailable(false);
00920         emit q->redoAvailable(false);
00921     }
00922     modifiedState = modified ? -1 : undoState;
00923     undoEnabled = enable;
00924 }

Here is the call graph for this function:

bool QTextDocumentPrivate::isUndoRedoEnabled (  )  const [inline]

Definition at line 176 of file qtextdocument_p.h.

00176 { return undoEnabled; }

bool QTextDocumentPrivate::isUndoAvailable (  )  const [inline]

Definition at line 178 of file qtextdocument_p.h.

Referenced by undoRedo().

00178 { return undoEnabled && undoState > 0; }

bool QTextDocumentPrivate::isRedoAvailable (  )  const [inline]

Definition at line 179 of file qtextdocument_p.h.

Referenced by undoRedo().

00179 { return undoEnabled && undoState < undoStack.size(); }

QString QTextDocumentPrivate::buffer (  )  const [inline]

Definition at line 181 of file qtextdocument_p.h.

Referenced by QTextHtmlExporter::emitBlock(), QTextFragment::text(), and QTextBlock::text().

00181 { return text; }

QString QTextDocumentPrivate::plainText (  )  const

Definition at line 1036 of file qtextdocument_p.cpp.

References begin(), QString::chop(), end(), QString::fromRawData(), length(), QString::reserve(), text, and QString::unicode().

01037 {
01038     QString result;
01039     result.reserve(length());
01040     for (QTextDocumentPrivate::FragmentIterator it = begin(); it != end(); ++it) {
01041         const QTextFragmentData *f = *it;
01042         result += QString::fromRawData(text.unicode() + f->stringPosition, f->size);
01043     }
01044     // remove trailing block separator
01045     result.chop(1);
01046     return result;
01047 }

Here is the call graph for this function:

int QTextDocumentPrivate::length (  )  const [inline]

Definition at line 183 of file qtextdocument_p.h.

Referenced by QTextDocumentLayout::documentChanged(), QTextHtmlExporter::emitBlock(), insertFrame(), QTextDocumentFragment::isEmpty(), QTextDocumentLayout::layoutStatus(), QTextCursorPrivate::movePosition(), nextCursorPosition(), plainText(), setLayout(), QTextHtmlExporter::toHtml(), and undoRedo().

00183 { return fragments.length(); }

QTextFormatCollection* QTextDocumentPrivate::formatCollection (  )  [inline]

Definition at line 185 of file qtextdocument_p.h.

Referenced by QAbstractTextDocumentLayout::anchorAt(), QTextCopyHelper::appendFragment(), QTextBlock::blockFormat(), QTextCursorPrivate::canDelete(), QTextFragment::charFormat(), QTextBlock::charFormat(), QTextCopyHelper::convertFormat(), QTextCopyHelper::convertFormatIndex(), QTextCopyHelper::copy(), QTextTablePrivate::createTable(), QAbstractTextDocumentLayout::format(), and QTextCursorPrivate::insertBlock().

00185 { return &formats; }

const QTextFormatCollection* QTextDocumentPrivate::formatCollection (  )  const [inline]

Definition at line 186 of file qtextdocument_p.h.

00186 { return &formats; }

QAbstractTextDocumentLayout* QTextDocumentPrivate::layout (  )  const [inline]

Definition at line 187 of file qtextdocument_p.h.

Referenced by QTextEngine::font(), QTextEngine::fontEngine(), QScriptLine::setDefaultHeight(), and setLayout().

00187 { return lout; }

FragmentIterator QTextDocumentPrivate::find ( int  pos  )  const [inline]

Definition at line 189 of file qtextdocument_p.h.

Referenced by QAbstractTextDocumentLayout::anchorAt(), QTextCopyHelper::appendFragment(), QTextCursorPrivate::canDelete(), QTextHtmlExporter::emitBlock(), QAbstractTextDocumentLayout::format(), QAbstractTextDocumentLayout::formatIndex(), insertFrame(), remove(), QTextBlock::text(), and undoRedo().

00189 { return fragments.find(pos); }

FragmentIterator QTextDocumentPrivate::begin (  )  const [inline]

Definition at line 190 of file qtextdocument_p.h.

Referenced by plainText(), and scan_frames().

00190 { return fragments.begin(); }

FragmentIterator QTextDocumentPrivate::end (  )  const [inline]

Definition at line 191 of file qtextdocument_p.h.

Referenced by documentChange(), insert_frame(), nextCursorPosition(), plainText(), remove(), removeFrame(), scan_frames(), and setBlockFormat().

00191 { return fragments.end(); }

QTextBlock QTextDocumentPrivate::blocksBegin (  )  const [inline]

Definition at line 193 of file qtextdocument_p.h.

Referenced by QTextCopyHelper::appendFragment(), and QTextCursorPrivate::movePosition().

00193 { return QTextBlock(const_cast<QTextDocumentPrivate *>(this), blocks.firstNode()); }

QTextBlock QTextDocumentPrivate::blocksEnd (  )  const [inline]

Definition at line 194 of file qtextdocument_p.h.

Referenced by QTextCursorPrivate::movePosition().

00194 { return QTextBlock(const_cast<QTextDocumentPrivate *>(this), 0); }

QTextBlock QTextDocumentPrivate::blocksFind ( int  pos  )  const [inline]

Definition at line 195 of file qtextdocument_p.h.

Referenced by QTextCopyHelper::appendFragment(), QTextCopyHelper::copy(), QTextCursorPrivate::movePosition(), nextCursorPosition(), previousCursorPosition(), QTextCursorPrivate::setBlockFormat(), setCharFormat(), QTextCursorPrivate::setX(), and undoRedo().

00195 { return QTextBlock(const_cast<QTextDocumentPrivate *>(this), blocks.findNode(pos)); }

int QTextDocumentPrivate::blockCharFormatIndex ( int  node  )  const

Definition at line 1049 of file qtextdocument_p.cpp.

References blocks, QFragmentMap< T >::find(), fragments, initialBlockCharFormatIndex, and QFragmentMap< T >::position().

Referenced by QTextBlock::charFormatIndex().

01050 {
01051     int pos = blocks.position(node);
01052     if (pos == 0)
01053         return initialBlockCharFormatIndex;
01054 
01055     return fragments.find(pos - 1)->format;
01056 }

Here is the call graph for this function:

int QTextDocumentPrivate::numBlocks (  )  const [inline]

Definition at line 198 of file qtextdocument_p.h.

00198 { return blocks.numNodes(); }

const BlockMap& QTextDocumentPrivate::blockMap (  )  const [inline]

Definition at line 200 of file qtextdocument_p.h.

Referenced by QTextCursorPrivate::block(), QTextBlock::blockFormat(), QTextBlock::blockFormatIndex(), QTextBlock::contains(), QTextDocumentLayoutPrivate::frameIteratorForTextPosition(), QTextBlock::layout(), QTextBlock::length(), QTextBlock::next(), QTextBlock::position(), QTextBlock::previous(), QTextBlock::setUserData(), QTextBlock::setUserState(), QTextBlock::userData(), and QTextBlock::userState().

00200 { return blocks; }

const FragmentMap& QTextDocumentPrivate::fragmentMap (  )  const [inline]

Definition at line 201 of file qtextdocument_p.h.

Referenced by QTextBlock::begin(), QTextFragment::charFormat(), QTextFragment::charFormatIndex(), QTextBlock::end(), QTextTablePrivate::findCellIndex(), QTextBlock::iterator::fragment(), QTextTablePrivate::fragmentAdded(), QTextFragment::length(), QTextBlock::iterator::operator++(), QTextBlock::iterator::operator--(), QTextFragment::position(), and QTextFragment::text().

00201 { return fragments; }

static const QTextBlockData* QTextDocumentPrivate::block ( const QTextBlock it  )  [inline, static]

Definition at line 203 of file qtextdocument_p.h.

References blocks, QFragmentMap< T >::fragment(), QTextBlock::n, and QTextBlock::p.

Referenced by changeObjectFormat(), setBlockFormat(), setCharFormat(), and undoRedo().

00203 { return it.p->blocks.fragment(it.n); }

Here is the call graph for this function:

int QTextDocumentPrivate::nextCursorPosition ( int  position,
QTextLayout::CursorMode  mode 
) const

Definition at line 1058 of file qtextdocument_p.cpp.

References blocksFind(), end(), QTextBlock::layout(), QTextBlock::length(), length(), QTextLayout::nextCursorPosition(), QTextBlock::position(), and start.

Referenced by QTextCursorPrivate::movePosition().

01059 {
01060     if (position == length()-1)
01061         return position;
01062 
01063     QTextBlock it = blocksFind(position);
01064     int start = it.position();
01065     int end = start + it.length() - 1;
01066     if (position == end)
01067         return end + 1;
01068 
01069     return it.layout()->nextCursorPosition(position-start, mode) + start;
01070 }

Here is the call graph for this function:

int QTextDocumentPrivate::previousCursorPosition ( int  position,
QTextLayout::CursorMode  mode 
) const

Definition at line 1072 of file qtextdocument_p.cpp.

References blocksFind(), QTextBlock::layout(), QTextBlock::position(), QTextLayout::previousCursorPosition(), and start.

Referenced by QTextCursorPrivate::movePosition().

01073 {
01074     if (position == 0)
01075         return position;
01076 
01077     QTextBlock it = blocksFind(position);
01078     int start = it.position();
01079     if (position == start)
01080         return start - 1;
01081 
01082     return it.layout()->previousCursorPosition(position-start, mode) + start;
01083 }

Here is the call graph for this function:

void QTextDocumentPrivate::changeObjectFormat ( QTextObject group,
int  format 
)

Definition at line 1085 of file qtextdocument_p.cpp.

References appendUndoItem(), b, beginEditBlock(), block(), blocks, c, documentChange(), endEditBlock(), formats, QTextUndoCommand::GroupFormatChange, i, QTextUndoCommand::MoveCursor, QTextFormatCollection::objectFormatIndex(), QTextObject::objectIndex(), QTextFormatCollection::setObjectFormatIndex(), and QFragmentMap< T >::size().

Referenced by undoRedo().

01086 {
01087     beginEditBlock();
01088     int objectIndex = obj->objectIndex();
01089     int oldFormatIndex = formats.objectFormatIndex(objectIndex);
01090     formats.setObjectFormatIndex(objectIndex, format);
01091 
01092     QTextBlockGroup *b = qobject_cast<QTextBlockGroup *>(obj);
01093     if (b) {
01094         QList<QTextBlock> blocks = b->blockList();
01095         for (int i = 0; i < blocks.size(); ++i) {
01096             // invalidate blocks and tell layout
01097             const QTextBlock &block = blocks.at(i);
01098             documentChange(block.position(), block.length());
01099         }
01100     }
01101     QTextFrame *f = qobject_cast<QTextFrame *>(obj);
01102     if (f)
01103         documentChange(f->firstPosition(), f->lastPosition() - f->firstPosition());
01104 
01105     QTextUndoCommand c = { QTextUndoCommand::GroupFormatChange, true, QTextUndoCommand::MoveCursor, oldFormatIndex,
01106                       0, 0, { obj->d_func()->objectIndex } };
01107     appendUndoItem(c);
01108 
01109     endEditBlock();
01110 }

Here is the call graph for this function:

void QTextDocumentPrivate::setModified ( bool  m  ) 

Definition at line 1340 of file qtextdocument_p.cpp.

References emit, modified, modifiedState, and undoState.

Referenced by QTextDocument::setModified().

01341 {
01342     Q_Q(QTextDocument);
01343     if (m == modified)
01344         return;
01345 
01346     modified = m;
01347     if (!modified)
01348         modifiedState = undoState;
01349     else
01350         modifiedState = -1;
01351 
01352     emit q->modificationChanged(modified);
01353 }

bool QTextDocumentPrivate::isModified (  )  const [inline]

Definition at line 211 of file qtextdocument_p.h.

Referenced by QTextDocument::isModified().

00211 { return modified; }

QFont QTextDocumentPrivate::defaultFont (  )  const [inline]

Definition at line 213 of file qtextdocument_p.h.

00213 { return formats.defaultFont(); }

void QTextDocumentPrivate::setDefaultFont ( const QFont f  )  [inline]

Definition at line 214 of file qtextdocument_p.h.

00214 { formats.setDefaultFont(f); }

bool QTextDocumentPrivate::split ( int  pos  )  [private]

Definition at line 692 of file qtextdocument_p.cpp.

References QFragmentMap< T >::findNode(), QFragmentMap< T >::fragment(), fragments, QFragmentMap< T >::insert_single(), N, n, QFragmentMap< T >::position(), QFragmentMap< T >::setSize(), X, and x.

Referenced by insert_block(), insert_string(), remove(), and setCharFormat().

00693 {
00694     uint x = fragments.findNode(pos);
00695     if (x) {
00696         int k = fragments.position(x);
00697 //          qDebug("found fragment with key %d, size_left=%d, size=%d to split at %d",
00698 //                k, (*it)->size_left, (*it)->size, pos);
00699         if (k != pos) {
00700             Q_ASSERT(k <= pos);
00701             // need to resize the first fragment and add a new one
00702             QTextFragmentData *X = fragments.fragment(x);
00703             int oldsize = X->size;
00704             fragments.setSize(x, pos-k);
00705             uint n = fragments.insert_single(pos, oldsize-(pos-k));
00706             X = fragments.fragment(x);
00707             QTextFragmentData *N = fragments.fragment(n);
00708             N->stringPosition = X->stringPosition + pos-k;
00709             N->format = X->format;
00710             return true;
00711         }
00712     }
00713     return false;
00714 }

Here is the call graph for this function:

bool QTextDocumentPrivate::unite ( uint  f  )  [private]

Definition at line 716 of file qtextdocument_p.cpp.

References QString::at(), QFragmentMap< T >::erase_single(), QTextFragmentData::format, QFragmentMap< T >::fragment(), fragments, isValidBlockSeparator(), n, QFragmentMap< T >::next(), QFragmentMap< T >::setSize(), QFragment::size, QTextFragmentData::stringPosition, and text.

Referenced by insert_string(), remove(), and setCharFormat().

00717 {
00718     uint n = fragments.next(f);
00719     if (!n)
00720         return false;
00721 
00722     QTextFragmentData *ff = fragments.fragment(f);
00723     QTextFragmentData *nf = fragments.fragment(n);
00724 
00725     if (nf->format == ff->format && (ff->stringPosition + (int)ff->size == nf->stringPosition)) {
00726         if (isValidBlockSeparator(text.at(ff->stringPosition))
00727             || isValidBlockSeparator(text.at(nf->stringPosition)))
00728             return false;
00729 
00730         fragments.setSize(f, ff->size + nf->size);
00731         fragments.erase_single(n);
00732         return true;
00733     }
00734     return false;
00735 }

Here is the call graph for this function:

void QTextDocumentPrivate::truncateUndoStack (  )  [private]

Definition at line 892 of file qtextdocument_p.cpp.

References c, QTextUndoCommand::Custom, i, QTextUndoCommand::Removed, QVector< T >::resize(), QVector< T >::size(), undoStack, and undoState.

Referenced by appendUndoItem(), clear(), enableUndoRedo(), and ~QTextDocumentPrivate().

00892                                              {
00893     if (undoState == undoStack.size())
00894         return;
00895 
00896     for (int i = undoState; i < undoStack.size(); ++i) {
00897         QTextUndoCommand c = undoStack[i];
00898         if (c.command & QTextUndoCommand::Removed) {
00899             // ########
00900 //             QTextFragment *f = c.fragment_list;
00901 //             while (f) {
00902 //                 QTextFragment *n = f->right;
00903 //                 delete f;
00904 //                 f = n;
00905 //             }
00906         } else if (c.command & QTextUndoCommand::Custom) {
00907             delete c.custom;
00908         }
00909     }
00910     undoStack.resize(undoState);
00911 }

Here is the call graph for this function:

void QTextDocumentPrivate::insert_string ( int  pos,
uint  strPos,
uint  length,
int  format,
QTextUndoCommand::Operation  op 
) [private]

Definition at line 261 of file qtextdocument_p.cpp.

References adjustDocumentChangesAndCursors(), QString::at(), b, blocks, QFragmentMap< T >::findNode(), QFragmentMap< T >::fragment(), fragments, framesDirty, QFragmentMap< T >::insert_single(), QFragmentMap< T >::length(), QString::mid(), noBlockInString(), objectForFormat(), QFragmentMap< T >::previous(), QFragmentMap< T >::setSize(), QFragmentMap< T >::size(), split(), text, unite(), w, X, and x.

Referenced by insert(), and undoRedo().

00262 {
00263     // ##### optimise when only appending to the fragment!
00264     Q_ASSERT(noBlockInString(text.mid(strPos, length)));
00265 
00266     split(pos);
00267     uint x = fragments.insert_single(pos, length);
00268     QTextFragmentData *X = fragments.fragment(x);
00269     X->format = format;
00270     X->stringPosition = strPos;
00271     uint w = fragments.previous(x);
00272     if (w)
00273         unite(w);
00274 
00275     int b = blocks.findNode(pos);
00276     blocks.setSize(b, blocks.size(b)+length);
00277 
00278     Q_ASSERT(blocks.length() == fragments.length());
00279 
00280     QTextFrame *frame = qobject_cast<QTextFrame *>(objectForFormat(format));
00281     if (frame) {
00282         frame->d_func()->fragmentAdded(text.at(strPos), x);
00283         framesDirty = true;
00284     }
00285 
00286     adjustDocumentChangesAndCursors(pos, length, op);
00287 }

Here is the call graph for this function:

int QTextDocumentPrivate::insert_block ( int  pos,
uint  strPos,
int  format,
int  blockformat,
QTextUndoCommand::Operation  op,
int  command 
) [private]

Definition at line 289 of file qtextdocument_p.cpp.

References adjustDocumentChangesAndCursors(), QString::at(), B, b, QTextUndoCommand::BlockRemoved, blocks, QFragmentMap< T >::findNode(), QTextFormatCollection::format(), formats, QFragmentMap< T >::fragment(), fragments, framesDirty, QFragmentMap< T >::insert_single(), isValidBlockSeparator(), key, QFragmentMap< T >::length(), n, objectForFormat(), QFragmentMap< T >::position(), QFragmentMap< T >::setSize(), QFragmentMap< T >::size(), size, split(), text, X, and x.

Referenced by insertBlock(), and undoRedo().

00290 {
00291     split(pos);
00292     uint x = fragments.insert_single(pos, 1);
00293     QTextFragmentData *X = fragments.fragment(x);
00294     X->format = format;
00295     X->stringPosition = strPos;
00296     // no need trying to unite, since paragraph separators are always in a fragment of their own
00297 
00298     Q_ASSERT(isValidBlockSeparator(text.at(strPos)));
00299     Q_ASSERT(blocks.length()+1 == fragments.length());
00300 
00301     int block_pos = pos;
00302     if (blocks.length() && command == QTextUndoCommand::BlockRemoved)
00303         ++block_pos;
00304     int size = 1;
00305     int n = blocks.findNode(block_pos);
00306     int key = n ? blocks.position(n) : blocks.length();
00307 
00308     Q_ASSERT(n || (!n && block_pos == blocks.length()));
00309     if (key != block_pos) {
00310         Q_ASSERT(key < block_pos);
00311         int oldSize = blocks.size(n);
00312         blocks.setSize(n, block_pos-key);
00313         size += oldSize - (block_pos-key);
00314     }
00315     int b = blocks.insert_single(block_pos, size);
00316     QTextBlockData *B = blocks.fragment(b);
00317     B->format = blockFormat;
00318 
00319     Q_ASSERT(blocks.length() == fragments.length());
00320 
00321     QTextBlockGroup *group = qobject_cast<QTextBlockGroup *>(objectForFormat(blockFormat));
00322     if (group)
00323         group->blockInserted(QTextBlock(this, b));
00324 
00325     QTextFrame *frame = qobject_cast<QTextFrame *>(objectForFormat(formats.format(format)));
00326     if (frame) {
00327         frame->d_func()->fragmentAdded(text.at(strPos), x);
00328         framesDirty = true;
00329     }
00330 
00331     adjustDocumentChangesAndCursors(pos, 1, op);
00332     return x;
00333 }

Here is the call graph for this function:

int QTextDocumentPrivate::remove_string ( int  pos,
uint  length,
QTextUndoCommand::Operation  op 
) [private]

Definition at line 401 of file qtextdocument_p.cpp.

References adjustDocumentChangesAndCursors(), QString::at(), b, blocks, QFragmentMap< T >::erase_single(), QFragmentMap< T >::findNode(), QFragmentMap< T >::fragment(), fragments, framesDirty, int, QFragmentMap< T >::length(), QString::mid(), noBlockInString(), objectForFormat(), QFragmentMap< T >::position(), QFragmentMap< T >::setSize(), QFragmentMap< T >::size(), text, w, and x.

Referenced by remove().

00402 {
00403     Q_ASSERT(pos >= 0);
00404     Q_ASSERT(blocks.length() == fragments.length());
00405     Q_ASSERT(blocks.length() >= pos+(int)length);
00406 
00407     int b = blocks.findNode(pos);
00408     uint x = fragments.findNode(pos);
00409 
00410     Q_ASSERT(blocks.size(b) > length);
00411     Q_ASSERT(x && fragments.position(x) == (uint)pos && fragments.size(x) == length);
00412     Q_ASSERT(noBlockInString(text.mid(fragments.fragment(x)->stringPosition, length)));
00413 
00414     blocks.setSize(b, blocks.size(b)-length);
00415 
00416     QTextFrame *frame = qobject_cast<QTextFrame *>(objectForFormat(fragments.fragment(x)->format));
00417     if (frame) {
00418         frame->d_func()->fragmentRemoved(text.at(fragments.fragment(x)->stringPosition), x);
00419         framesDirty = true;
00420     }
00421 
00422     const int w = fragments.erase_single(x);
00423 
00424     adjustDocumentChangesAndCursors(pos, -int(length), op);
00425 
00426     return w;
00427 }

Here is the call graph for this function:

int QTextDocumentPrivate::remove_block ( int  pos,
int *  blockformat,
int  command,
QTextUndoCommand::Operation  op 
) [private]

Definition at line 429 of file qtextdocument_p.cpp.

References adjustDocumentChangesAndCursors(), QString::at(), b, QTextUndoCommand::BlockAdded, QTextBlockGroup::blockRemoved(), blocks, QFragmentMap< T >::erase_single(), QFragmentMap< T >::findNode(), QFragmentMap< T >::fragment(), fragments, framesDirty, isValidBlockSeparator(), QFragmentMap< T >::length(), n, QFragmentMap< T >::next(), objectForFormat(), QFragmentMap< T >::position(), QFragmentMap< T >::setSize(), QFragmentMap< T >::size(), text, w, and x.

Referenced by remove(), and undoRedo().

00430 {
00431     Q_ASSERT(pos >= 0);
00432     Q_ASSERT(blocks.length() == fragments.length());
00433     Q_ASSERT(blocks.length() > pos);
00434 
00435     int b = blocks.findNode(pos);
00436     uint x = fragments.findNode(pos);
00437 
00438     Q_ASSERT(x && (int)fragments.position(x) == pos);
00439     Q_ASSERT(fragments.size(x) == 1);
00440     Q_ASSERT(isValidBlockSeparator(text.at(fragments.fragment(x)->stringPosition)));
00441     Q_ASSERT(b);
00442 
00443     if (blocks.size(b) == 1 && command == QTextUndoCommand::BlockAdded) {
00444   Q_ASSERT((int)blocks.position(b) == pos);
00445 //    qDebug("removing empty block");
00446   // empty block remove the block itself
00447     } else {
00448   // non empty block, merge with next one into this block
00449 //    qDebug("merging block with next");
00450   int n = blocks.next(b);
00451   Q_ASSERT((int)blocks.position(n) == pos + 1);
00452   blocks.setSize(b, blocks.size(b) + blocks.size(n) - 1);
00453   b = n;
00454     }
00455     *blockFormat = blocks.fragment(b)->format;
00456 
00457     QTextBlockGroup *group = qobject_cast<QTextBlockGroup *>(objectForFormat(blocks.fragment(b)->format));
00458     if (group)
00459         group->blockRemoved(QTextBlock(this, b));
00460 
00461     QTextFrame *frame = qobject_cast<QTextFrame *>(objectForFormat(fragments.fragment(x)->format));
00462     if (frame) {
00463         frame->d_func()->fragmentRemoved(text.at(fragments.fragment(x)->stringPosition), x);
00464         framesDirty = true;
00465     }
00466 
00467     blocks.erase_single(b);
00468     const int w = fragments.erase_single(x);
00469 
00470     adjustDocumentChangesAndCursors(pos, -1, op);
00471 
00472     return w;
00473 }

Here is the call graph for this function:

void QTextDocumentPrivate::insert_frame ( QTextFrame f  )  [private]

Definition at line 1199 of file qtextdocument_p.cpp.

References QList< T >::append(), c, QTextFrame::childFrames(), end(), QTextFrame::firstPosition(), frameAt(), i, QTextFrame::lastPosition(), QObjectData::parent, QTextFrame::parentFrame(), and start.

Referenced by insertFrame().

01200 {
01201     int start = f->firstPosition();
01202     int end = f->lastPosition();
01203     QTextFrame *parent = frameAt(start-1);
01204     Q_ASSERT(parent == frameAt(end+1));
01205 
01206     if (start != end) {
01207         // iterator over the parent and move all children contained in my frame to myself
01208         for (int i = 0; i < parent->d_func()->childFrames.size(); ++i) {
01209             QTextFrame *c = parent->d_func()->childFrames.at(i);
01210             if (start < c->firstPosition() && end > c->lastPosition()) {
01211                 parent->d_func()->childFrames.removeAt(i);
01212                 f->d_func()->childFrames.append(c);
01213                 c->d_func()->parentFrame = f;
01214             }
01215         }
01216     }
01217     // insert at the correct position
01218     int i = 0;
01219     for (; i < parent->d_func()->childFrames.size(); ++i) {
01220         QTextFrame *c = parent->d_func()->childFrames.at(i);
01221         if (c->firstPosition() > end)
01222             break;
01223     }
01224     parent->d_func()->childFrames.insert(i, f);
01225     f->d_func()->parentFrame = parent;
01226 }

Here is the call graph for this function:

void QTextDocumentPrivate::scan_frames ( int  pos,
int  charsRemoved,
int  charsAdded 
) [private]

Definition at line 1154 of file qtextdocument_p.cpp.

References QList< T >::append(), QString::at(), begin(), QTextFrame::childFrames(), clearFrame(), end(), framesDirty, objectForFormat(), QChar::ObjectReplacementCharacter, QTextFrame::parentFrame(), QTextBeginningOfFrame, QTextEndOfFrame, rootFrame(), rtFrame, and text.

Referenced by endEditBlock().

01155 {
01156     // ###### optimise
01157     Q_UNUSED(pos);
01158     Q_UNUSED(charsRemoved);
01159     Q_UNUSED(charsAdded);
01160 
01161     QTextFrame *f = rootFrame();
01162     clearFrame(f);
01163 
01164     for (FragmentIterator it = begin(); it != end(); ++it) {
01165         // QTextFormat fmt = formats.format(it->format);
01166         QTextFrame *frame = qobject_cast<QTextFrame *>(objectForFormat(it->format));
01167         if (!frame)
01168             continue;
01169 
01170         Q_ASSERT(it.size() == 1);
01171         QChar ch = text.at(it->stringPosition);
01172 
01173         if (ch == QTextBeginningOfFrame) {
01174             if (f != frame) {
01175                 // f == frame happens for tables
01176                 Q_ASSERT(frame->d_func()->fragment_start == it.n || frame->d_func()->fragment_start == 0);
01177                 frame->d_func()->parentFrame = f;
01178                 f->d_func()->childFrames.append(frame);
01179                 f = frame;
01180             }
01181         } else if (ch == QTextEndOfFrame) {
01182             Q_ASSERT(f == frame);
01183             Q_ASSERT(frame->d_func()->fragment_end == it.n || frame->d_func()->fragment_end == 0);
01184             f = frame->d_func()->parentFrame;
01185         } else if (ch == QChar::ObjectReplacementCharacter) {
01186             Q_ASSERT(f != frame);
01187             Q_ASSERT(frame->d_func()->fragment_start == it.n || frame->d_func()->fragment_start == 0);
01188             Q_ASSERT(frame->d_func()->fragment_end == it.n || frame->d_func()->fragment_end == 0);
01189             frame->d_func()->parentFrame = f;
01190             f->d_func()->childFrames.append(frame);
01191         } else {
01192             Q_ASSERT(false);
01193         }
01194     }
01195     Q_ASSERT(f == rtFrame);
01196     framesDirty = false;
01197 }

Here is the call graph for this function:

void QTextDocumentPrivate::clearFrame ( QTextFrame f  )  [static, private]

Definition at line 1146 of file qtextdocument_p.cpp.

References QList< T >::at(), QTextFrame::childFrames(), QList< T >::clear(), QList< T >::count(), i, and QTextFrame::parentFrame().

Referenced by scan_frames().

01147 {
01148     for (int i = 0; i < f->d_func()->childFrames.count(); ++i)
01149         clearFrame(f->d_func()->childFrames.at(i));
01150     f->d_func()->childFrames.clear();
01151     f->d_func()->parentFrame = 0;
01152 }

Here is the call graph for this function:

void QTextDocumentPrivate::adjustDocumentChangesAndCursors ( int  from,
int  addedOrRemoved,
QTextUndoCommand::Operation  op 
) [private]

Definition at line 982 of file qtextdocument_p.cpp.

References QList< T >::append(), QList< T >::at(), changedCursors, contentsChanged(), QTextCursorPrivate::CursorMoved, cursors, diff(), docChangeFrom, docChangeLength, docChangeOldLength, editBlock, emit, i, qMax(), qMin(), and QList< T >::size().

Referenced by insert_block(), insert_string(), remove_block(), and remove_string().

00983 {
00984     Q_Q(QTextDocument);
00985     for (int i = 0; i < cursors.size(); ++i) {
00986         QTextCursorPrivate *curs = cursors.at(i);
00987         if (curs->adjustPosition(from, addedOrRemoved, op) == QTextCursorPrivate::CursorMoved) {
00988             if (editBlock)
00989                 changedCursors.append(curs);
00990             else
00991                 emit q->cursorPositionChanged(QTextCursor(curs));
00992         }
00993     }
00994 
00995 //     qDebug("QTextDocumentPrivate::adjustDocumentChanges: from=%d,addedOrRemoved=%d", from, addedOrRemoved);
00996     if (docChangeFrom < 0) {
00997         docChangeFrom = from;
00998         if (addedOrRemoved > 0) {
00999             docChangeOldLength = 0;
01000             docChangeLength = addedOrRemoved;
01001         } else {
01002             docChangeOldLength = -addedOrRemoved;
01003             docChangeLength = 0;
01004         }
01005 //         qDebug("adjustDocumentChanges:");
01006 //         qDebug("    -> %d %d %d", docChangeFrom, docChangeOldLength, docChangeLength);
01007         contentsChanged();
01008         return;
01009     }
01010 
01011     // have to merge the new change with the already existing one.
01012     int added = qMax(0, addedOrRemoved);
01013     int removed = qMax(0, -addedOrRemoved);
01014 
01015     int diff = 0;
01016     if(from + removed < docChangeFrom)
01017         diff = docChangeFrom - from - removed;
01018     else if(from > docChangeFrom + docChangeLength)
01019         diff = from - (docChangeFrom + docChangeLength);
01020 
01021     int overlap_start = qMax(from, docChangeFrom);
01022     int overlap_end = qMin(from + removed, docChangeFrom + docChangeLength);
01023     int removedInside = qMax(0, overlap_end - overlap_start);
01024     removed -= removedInside;
01025 
01026 //     qDebug("adjustDocumentChanges: from=%d, addedOrRemoved=%d, diff=%d, removedInside=%d", from, addedOrRemoved, diff, removedInside);
01027     docChangeFrom = qMin(docChangeFrom, from);
01028     docChangeOldLength += removed + diff;
01029     docChangeLength += added - removedInside + diff;
01030 //     qDebug("    -> %d %d %d", docChangeFrom, docChangeOldLength, docChangeLength);
01031 
01032     contentsChanged();
01033 }

Here is the call graph for this function:

void QTextDocumentPrivate::documentChange ( int  from,
int  length 
)

Definition at line 965 of file qtextdocument_p.cpp.

References diff(), docChangeFrom, docChangeLength, docChangeOldLength, end(), qMax(), qMin(), and start.

Referenced by changeObjectFormat(), QTextLayout::setAdditionalFormats(), setBlockFormat(), setCharFormat(), QTextLayout::setPreeditArea(), and undoRedo().

00966 {
00967 //     qDebug("QTextDocumentPrivate::documentChange: from=%d,length=%d", from, length);
00968     if (docChangeFrom < 0) {
00969         docChangeFrom = from;
00970         docChangeOldLength = length;
00971         docChangeLength = length;
00972         return;
00973     }
00974     int start = qMin(from, docChangeFrom);
00975     int end = qMax(from + length, docChangeFrom + docChangeLength);
00976     int diff = qMax(0, end - start - docChangeLength);
00977     docChangeFrom = start;
00978     docChangeOldLength += diff;
00979     docChangeLength += diff;
00980 }

Here is the call graph for this function:

void QTextDocumentPrivate::addCursor ( QTextCursorPrivate c  )  [inline]

Definition at line 235 of file qtextdocument_p.h.

References c.

Referenced by QTextCursorPrivate::QTextCursorPrivate().

00235 { cursors.append(c); }

void QTextDocumentPrivate::removeCursor ( QTextCursorPrivate c  )  [inline]

Definition at line 236 of file qtextdocument_p.h.

References c.

Referenced by QTextCursorPrivate::~QTextCursorPrivate().

QTextFrame * QTextDocumentPrivate::frameAt ( int  pos  )  const

Definition at line 1134 of file qtextdocument_p.cpp.

References c, findChildFrame(), and rootFrame().

Referenced by QTextCursorPrivate::adjustCursor(), QTextCursorPrivate::complexSelectionTable(), QTextDocumentLayoutPrivate::frameIteratorForTextPosition(), insert_frame(), insertFrame(), QTextCursorPrivate::movePosition(), remove(), and QTextCursorPrivate::selectedTableCells().

01135 {
01136     QTextFrame *f = rootFrame();
01137 
01138     while (1) {
01139         QTextFrame *c = findChildFrame(f, pos);
01140         if (!c)
01141             return f;
01142         f = c;
01143     }
01144 }

Here is the call graph for this function:

QTextFrame * QTextDocumentPrivate::rootFrame (  )  const

Definition at line 1124 of file qtextdocument_p.cpp.

References createObject(), rtFrame, and QTextFrameFormat::setMargin().

Referenced by frameAt(), QTextDocumentLayoutPrivate::frameIteratorForTextPosition(), QTextDocumentLayoutPrivate::frameIteratorForYPosition(), and scan_frames().

01125 {
01126     if (!rtFrame) {
01127         QTextFrameFormat defaultRootFrameFormat;
01128         defaultRootFrameFormat.setMargin(2);
01129         rtFrame = qobject_cast<QTextFrame *>(const_cast<QTextDocumentPrivate *>(this)->createObject(defaultRootFrameFormat));
01130     }
01131     return rtFrame;
01132 }

Here is the call graph for this function:

QTextObject * QTextDocumentPrivate::objectForIndex ( int  objectIndex  )  const

Definition at line 1280 of file qtextdocument_p.cpp.

References createObject(), formats, object, QTextFormatCollection::objectFormat(), objects, and QMap< Key, T >::value().

Referenced by objectForFormat(), and undoRedo().

01281 {
01282     if (objectIndex < 0)
01283         return 0;
01284 
01285     QTextObject *object = objects.value(objectIndex, 0);
01286     if (!object) {
01287         QTextDocumentPrivate *that = const_cast<QTextDocumentPrivate *>(this);
01288         QTextFormat fmt = formats.objectFormat(objectIndex);
01289         object = that->createObject(fmt, objectIndex);
01290     }
01291     return object;
01292 }

Here is the call graph for this function:

QTextObject * QTextDocumentPrivate::objectForFormat ( int  formatIndex  )  const

Definition at line 1294 of file qtextdocument_p.cpp.

References QTextFormatCollection::format(), formats, objectForIndex(), and QTextFormat::objectIndex().

Referenced by insert_block(), insert_string(), remove_block(), remove_string(), scan_frames(), setBlockFormat(), and undoRedo().

01295 {
01296     int objectIndex = formats.format(formatIndex).objectIndex();
01297     return objectForIndex(objectIndex);
01298 }

Here is the call graph for this function:

QTextObject * QTextDocumentPrivate::objectForFormat ( const QTextFormat f  )  const

Definition at line 1300 of file qtextdocument_p.cpp.

References objectForIndex(), and QTextFormat::objectIndex().

01301 {
01302     return objectForIndex(f.objectIndex());
01303 }

Here is the call graph for this function:

QTextObject * QTextDocumentPrivate::createObject ( const QTextFormat newFormat,
int  objectIndex = -1 
)

Definition at line 1305 of file qtextdocument_p.cpp.

References QTextDocument::createObject(), QTextFormatCollection::createObjectIndex(), document(), formats, QTextObject::objectIndex(), and objects.

Referenced by QTextTablePrivate::createTable(), insertFrame(), objectForIndex(), and rootFrame().

01306 {
01307     QTextObject *obj = document()->createObject(f);
01308 
01309     if (obj) {
01310         obj->d_func()->pieceTable = this;
01311         obj->d_func()->objectIndex = objectIndex == -1 ? formats.createObjectIndex(f) : objectIndex;
01312         objects[obj->d_func()->objectIndex] = obj;
01313     }
01314 
01315     return obj;
01316 }

Here is the call graph for this function:

void QTextDocumentPrivate::deleteObject ( QTextObject object  ) 

Definition at line 1318 of file qtextdocument_p.cpp.

References object, objects, and QMap< Key, T >::remove().

Referenced by QTextBlockGroup::blockRemoved().

01319 {
01320     const int objIdx = object->d_func()->objectIndex;
01321     objects.remove(objIdx);
01322     delete object;
01323 }

Here is the call graph for this function:

QTextDocument* QTextDocumentPrivate::document (  )  [inline]

Definition at line 248 of file qtextdocument_p.h.

Referenced by createObject(), QTextBlock::document(), QTextDocumentFragmentPrivate::insert(), and QTextBlock::textList().

00248 { return q_func(); }

const QTextDocument* QTextDocumentPrivate::document (  )  const [inline]

Definition at line 249 of file qtextdocument_p.h.

00249 { return q_func(); }

void QTextDocumentPrivate::ensureMaximumBlockCount (  ) 

Definition at line 1355 of file qtextdocument_p.cpp.

References beginEditBlock(), QTextCursor::blockCharFormat(), blocks, endEditBlock(), QTextCursor::KeepAnchor, maximumBlockCount, QTextCursor::movePosition(), QTextCursor::NextBlock, QFragmentMap< T >::numNodes(), QTextCursor::removeSelectedText(), and QTextCursor::setBlockCharFormat().

Referenced by insertBlock().

01356 {
01357     if (maximumBlockCount <= 0)
01358         return;
01359     if (blocks.numNodes() <= maximumBlockCount)
01360         return;
01361 
01362     beginEditBlock();
01363 
01364     const int blocksToRemove = blocks.numNodes() - maximumBlockCount;
01365     QTextCursor cursor(this, 0);
01366     cursor.movePosition(QTextCursor::NextBlock, QTextCursor::KeepAnchor, blocksToRemove);
01367 
01368     // preserve the char format of the paragraph that is to become the new first one
01369     QTextCharFormat charFmt = cursor.blockCharFormat();
01370     cursor.removeSelectedText();
01371     cursor.setBlockCharFormat(charFmt);
01372 
01373     endEditBlock();
01374 }

Here is the call graph for this function:

QTextDocumentPrivate& QTextDocumentPrivate::operator= ( const QTextDocumentPrivate m  )  [private]

void QTextDocumentPrivate::appendUndoItem ( const QTextUndoCommand c  )  [private]

Definition at line 872 of file qtextdocument_p.cpp.

References QVector< T >::append(), c, emit, QVector< T >::isEmpty(), modified, PMDEBUG, QVector< T >::size(), truncateUndoStack(), undoEnabled, undoStack, and undoState.

00873 {
00874     Q_Q(QTextDocument);
00875     PMDEBUG("appendUndoItem, command=%d enabled=%d", c.command, undoEnabled);
00876     if (!undoEnabled)
00877         return;
00878     if (undoState < undoStack.size())
00879         truncateUndoStack();
00880 
00881     if (!undoStack.isEmpty() && modified) {
00882         QTextUndoCommand &last = undoStack[undoState - 1];
00883         if (last.tryMerge(c))
00884             return;
00885     }
00886     undoStack.append(c);
00887     undoState++;
00888     emit q->undoAvailable(true);
00889     emit q->redoAvailable(false);
00890 }

Here is the call graph for this function:

void QTextDocumentPrivate::contentsChanged (  )  [private]

Definition at line 1325 of file qtextdocument_p.cpp.

References editBlock, emit, m, modified, modifiedState, undoEnabled, and undoState.

Referenced by adjustDocumentChangesAndCursors(), and endEditBlock().

01326 {
01327     Q_Q(QTextDocument);
01328     if (editBlock)
01329         return;
01330 
01331     bool m = undoEnabled ? (modifiedState != undoState) : true;
01332     if (modified != m) {
01333         modified = m;
01334         emit q->modificationChanged(modified);
01335     }
01336 
01337     emit q->contentsChanged();
01338 }


Member Data Documentation

QString QTextDocumentPrivate::text [private]

Definition at line 261 of file qtextdocument_p.h.

Referenced by clear(), insert(), insert_block(), insert_string(), insertBlock(), plainText(), remove(), remove_block(), remove_string(), scan_frames(), and unite().

QVector<QTextUndoCommand> QTextDocumentPrivate::undoStack [private]

Definition at line 263 of file qtextdocument_p.h.

Referenced by appendUndoItem(), endEditBlock(), insert(), insertBlock(), joinPreviousEditBlock(), truncateUndoStack(), and undoRedo().

bool QTextDocumentPrivate::undoEnabled [private]

Definition at line 264 of file qtextdocument_p.h.

Referenced by appendUndoItem(), contentsChanged(), enableUndoRedo(), endEditBlock(), init(), joinPreviousEditBlock(), QTextDocumentPrivate(), undoRedo(), and ~QTextDocumentPrivate().

int QTextDocumentPrivate::undoState [private]

Definition at line 265 of file qtextdocument_p.h.

Referenced by appendUndoItem(), clear(), contentsChanged(), enableUndoRedo(), endEditBlock(), init(), insert(), insertBlock(), joinPreviousEditBlock(), QTextDocumentPrivate(), setModified(), truncateUndoStack(), undoRedo(), and ~QTextDocumentPrivate().

int QTextDocumentPrivate::modifiedState [private]

Definition at line 267 of file qtextdocument_p.h.

Referenced by clear(), contentsChanged(), enableUndoRedo(), init(), QTextDocumentPrivate(), and setModified().

bool QTextDocumentPrivate::modified [private]

Definition at line 268 of file qtextdocument_p.h.

Referenced by appendUndoItem(), clear(), contentsChanged(), enableUndoRedo(), init(), QTextDocumentPrivate(), and setModified().

int QTextDocumentPrivate::editBlock [private]

Definition at line 270 of file qtextdocument_p.h.

Referenced by adjustDocumentChangesAndCursors(), appendUndoItem(), contentsChanged(), endEditBlock(), and QTextDocumentPrivate().

int QTextDocumentPrivate::docChangeFrom [private]

Definition at line 271 of file qtextdocument_p.h.

Referenced by adjustDocumentChangesAndCursors(), documentChange(), endEditBlock(), QTextDocumentPrivate(), and undoRedo().

int QTextDocumentPrivate::docChangeOldLength [private]

Definition at line 272 of file qtextdocument_p.h.

Referenced by adjustDocumentChangesAndCursors(),