Qt 4.8
Public Types | Public Slots | Signals | Public Functions | Protected Functions | Properties | Friends | List of all members
QTextDocument Class Reference

The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit. More...

#include <qtextdocument.h>

Inheritance diagram for QTextDocument:
QObject QTextDocumentWithImageResources

Public Types

enum  FindFlag { FindBackward = 0x00001, FindCaseSensitively = 0x00002, FindWholeWords = 0x00004 }
 This enum describes the options available to QTextDocument's find function. More...
 
enum  MetaInformation { DocumentTitle, DocumentUrl }
 This enum describes the different types of meta information that can be added to a document. More...
 
enum  ResourceType { HtmlResource = 1, ImageResource = 2, StyleSheetResource = 3, UserResource = 100 }
 This enum describes the types of resources that can be loaded by QTextDocument's loadResource() function. More...
 
enum  Stacks { UndoStack = 0x01, RedoStack = 0x02, UndoAndRedoStacks = UndoStack | RedoStack }
 

Public Slots

void appendUndoItem (QAbstractUndoItem *)
 Appends a custom undo item to the undo stack. More...
 
void redo ()
 Redoes the last editing operation on the document if redo is available. More...
 
void setModified (bool m=true)
 
void undo ()
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 

Signals

void blockCountChanged (int newBlockCount)
 This signal is emitted when the total number of text blocks in the document changes. More...
 
void contentsChange (int from, int charsRemoves, int charsAdded)
 This signal is emitted whenever the document's content changes; for example, when text is inserted or deleted, or when formatting is applied. More...
 
void contentsChanged ()
 This signal is emitted whenever the document's content changes; for example, when text is inserted or deleted, or when formatting is applied. More...
 
void cursorPositionChanged (const QTextCursor &cursor)
 This signal is emitted whenever the position of a cursor changed due to an editing operation. More...
 
void documentLayoutChanged ()
 This signal is emitted when a new document layout is set. More...
 
void modificationChanged (bool m)
 This signal is emitted whenever the content of the document changes in a way that affects the modification state. More...
 
void redoAvailable (bool)
 This signal is emitted whenever redo operations become available (available is true) or unavailable (available is false). More...
 
void undoAvailable (bool)
 This signal is emitted whenever undo operations become available (available is true) or unavailable (available is false). More...
 
void undoCommandAdded ()
 This signal is emitted every time a new level of undo is added to the QTextDocument. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 

Public Functions

void addResource (int type, const QUrl &name, const QVariant &resource)
 Adds the resource resource to the resource cache, using type and name as identifiers. More...
 
void adjustSize ()
 Adjusts the document to a reasonable size. More...
 
QVector< QTextFormatallFormats () const
 Returns a vector of text formats for all the formats used in the document. More...
 
int availableRedoSteps () const
 Returns the number of available redo steps. More...
 
int availableUndoSteps () const
 Returns the number of available undo steps. More...
 
QTextBlock begin () const
 Returns the document's first text block. More...
 
int blockCount () const
 
QChar characterAt (int pos) const
 Returns the character at position pos, or a null character if the position is out of range. More...
 
int characterCount () const
 Returns the number of characters of this document. More...
 
virtual void clear ()
 Clears the document. More...
 
void clearUndoRedoStacks (Stacks historyToClear=UndoAndRedoStacks)
 Clears the stacks specified by stacksToClear. More...
 
QTextDocumentclone (QObject *parent=0) const
 Creates a new QTextDocument that is a copy of this text document. More...
 
Qt::CursorMoveStyle defaultCursorMoveStyle () const
 The default cursor movement style is used by all QTextCursor objects created from the document. More...
 
QFont defaultFont () const
 
QString defaultStyleSheet () const
 
QTextOption defaultTextOption () const
 the default text option will be set on all QTextLayout in the document. More...
 
QTextDocumentPrivatedocHandle () const
 So that not all classes have to be friends of each other. More...
 
QAbstractTextDocumentLayoutdocumentLayout () const
 Returns the document layout for this document. More...
 
qreal documentMargin () const
 
void drawContents (QPainter *painter, const QRectF &rect=QRectF())
 Draws the content of the document with painter p, clipped to rect. More...
 
QTextBlock end () const
 This function returns a block to test for the end of the document while iterating over it. More...
 
QTextCursor find (const QString &subString, int from=0, FindFlags options=0) const
 Finds the next occurrence of the string, subString, in the document. More...
 
QTextCursor find (const QString &subString, const QTextCursor &from, FindFlags options=0) const
 Finds the next occurrence of the string, subString, in the document. More...
 
QTextCursor find (const QRegExp &expr, int from=0, FindFlags options=0) const
 Finds the next occurrence, matching the regular expression, expr, in the document. More...
 
QTextCursor find (const QRegExp &expr, const QTextCursor &from, FindFlags options=0) const
 Finds the next occurrence, matching the regular expression, expr, in the document. More...
 
QTextBlock findBlock (int pos) const
 Returns the text block that contains the {pos}-th character. More...
 
QTextBlock findBlockByLineNumber (int blockNumber) const
 Returns the text block that contains the specified lineNumber. More...
 
QTextBlock findBlockByNumber (int blockNumber) const
 Returns the text block with the specified blockNumber. More...
 
QTextBlock firstBlock () const
 Returns the document's first text block. More...
 
QTextFrameframeAt (int pos) const
 Returns the frame that contains the text cursor position pos. More...
 
qreal idealWidth () const
 Returns the ideal width of the text document. More...
 
qreal indentWidth () const
 
bool isEmpty () const
 Returns true if the document is empty; otherwise returns false. More...
 
bool isModified () const
 
bool isRedoAvailable () const
 Returns true if redo is available; otherwise returns false. More...
 
bool isUndoAvailable () const
 Returns true if undo is available; otherwise returns false. More...
 
bool isUndoRedoEnabled () const
 
QTextBlock lastBlock () const
 Returns the document's last (valid) text block. More...
 
int lineCount () const
 Returns the number of lines of this document (if the layout supports this). More...
 
void markContentsDirty (int from, int length)
 Marks the contents specified by the given position and length as "dirty", informing the document that it needs to be laid out again. More...
 
int maximumBlockCount () const
 
QString metaInformation (MetaInformation info) const
 Returns meta information about the document of the type specified by info. More...
 
QTextObjectobject (int objectIndex) const
 Returns the text object associated with the given objectIndex. More...
 
QTextObjectobjectForFormat (const QTextFormat &) const
 Returns the text object associated with the format f. More...
 
int pageCount () const
 returns the number of pages in this document. More...
 
QSizeF pageSize () const
 
void print (QPrinter *printer) const
 Prints the document to the given printer. More...
 
 QTextDocument (QObject *parent=0)
 Constructs an empty QTextDocument with the given parent. More...
 
 QTextDocument (const QString &text, QObject *parent=0)
 Constructs a QTextDocument containing the plain (unformatted) text specified, and with the given parent. More...
 
void redo (QTextCursor *cursor)
 Redoes the last editing operation on the document if redo is available. More...
 
QVariant resource (int type, const QUrl &name) const
 Returns data of the specified type from the resource with the given name. More...
 
int revision () const
 Returns the document's revision (if undo is enabled). More...
 
QTextFramerootFrame () const
 Returns the document's root frame. More...
 
void setDefaultCursorMoveStyle (Qt::CursorMoveStyle style)
 Sets the default cursor movement style to the given style. More...
 
void setDefaultFont (const QFont &font)
 Sets the default font to use in the document layout. More...
 
void setDefaultStyleSheet (const QString &sheet)
 
void setDefaultTextOption (const QTextOption &option)
 Sets the default text option. More...
 
void setDocumentLayout (QAbstractTextDocumentLayout *layout)
 Sets the document to use the given layout. More...
 
void setDocumentMargin (qreal margin)
 
void setHtml (const QString &html)
 Replaces the entire contents of the document with the given HTML-formatted text in the html string. More...
 
void setIndentWidth (qreal width)
 Sets the width used for text list and text block indenting. More...
 
void setMaximumBlockCount (int maximum)
 
void setMetaInformation (MetaInformation info, const QString &)
 Sets the document's meta information of the type specified by info to the given string. More...
 
void setPageSize (const QSizeF &size)
 
void setPlainText (const QString &text)
 Replaces the entire contents of the document with the given plain text. More...
 
void setTextWidth (qreal width)
 
void setUndoRedoEnabled (bool enable)
 
void setUseDesignMetrics (bool b)
 
QSizeF size () const
 
qreal textWidth () const
 
QString toHtml (const QByteArray &encoding=QByteArray()) const
 Returns a string containing an HTML representation of the document. More...
 
QString toPlainText () const
 Returns the plain text contained in the document. More...
 
void undo (QTextCursor *cursor)
 Undoes the last editing operation on the document if undo is available. More...
 
bool useDesignMetrics () const
 
 ~QTextDocument ()
 Destroys the document. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Protected Functions

virtual QTextObjectcreateObject (const QTextFormat &f)
 Creates and returns a new document object (a QTextObject), based on the given format. More...
 
virtual QVariant loadResource (int type, const QUrl &name)
 Loads data of the specified type from the resource with the given name. More...
 
 QTextDocument (QTextDocumentPrivate &dd, QObject *parent)
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 

Properties

int blockCount
 Returns the number of text blocks in the document. More...
 
QFont defaultFont
 the default font used to display the document's text More...
 
QString defaultStyleSheet
 The default style sheet is applied to all newly HTML formatted text that is inserted into the document, for example using setHtml() or QTextCursor::insertHtml(). More...
 
qreal documentMargin
 The margin around the document. More...
 
qreal indentWidth
 Returns the width used for text list and text block indenting. More...
 
int maximumBlockCount
 Specifies the limit for blocks in the document. More...
 
bool modified
 whether the document has been modified by the user More...
 
QSizeF pageSize
 the page size that should be used for laying out the document More...
 
QSizeF size
 Returns the actual size of the document. More...
 
qreal textWidth
 The text width specifies the preferred width for text in the document. More...
 
bool undoRedoEnabled
 whether undo/redo are enabled for this document More...
 
bool useDesignMetrics
 whether the document uses design metrics of fonts to improve the accuracy of text layout More...
 

Friends

class QTextObjectPrivate
 

Additional Inherited Members

- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit.

Note
This class or function is reentrant.

QTextDocument is a container for structured rich text documents, providing support for styled text and various types of document elements, such as lists, tables, frames, and images. They can be created for use in a QTextEdit, or used independently.

Each document element is described by an associated format object. Each format object is treated as a unique object by QTextDocuments, and can be passed to objectForFormat() to obtain the document element that it is applied to.

A QTextDocument can be edited programmatically using a QTextCursor, and its contents can be examined by traversing the document structure. The entire document structure is stored as a hierarchy of document elements beneath the root frame, found with the rootFrame() function. Alternatively, if you just want to iterate over the textual contents of the document you can use begin(), end(), and findBlock() to retrieve text blocks that you can examine and iterate over.

The layout of a document is determined by the documentLayout(); you can create your own QAbstractTextDocumentLayout subclass and set it using setDocumentLayout() if you want to use your own layout logic. The document's title and other meta-information can be obtained by calling the metaInformation() function. For documents that are exposed to users through the QTextEdit class, the document title is also available via the QTextEdit::documentTitle() function.

The toPlainText() and toHtml() convenience functions allow you to retrieve the contents of the document as plain text and HTML. The document's text can be searched using the find() functions.

Undo/redo of operations performed on the document can be controlled using the setUndoRedoEnabled() function. The undo/redo system can be controlled by an editor widget through the undo() and redo() slots; the document also provides contentsChanged(), undoAvailable(), and redoAvailable() signals that inform connected editor widgets about the state of the undo/redo system. The following are the undo/redo operations of a QTextDocument:

See also
QTextCursor, QTextEdit, Rich Text Processing, {Text Object Example}

Definition at line 109 of file qtextdocument.h.

Enumerations

◆ FindFlag

This enum describes the options available to QTextDocument's find function.

The options can be OR-ed together from the following list:

  • FindBackward Search backwards instead of forwards.
  • FindCaseSensitively By default find works case insensitive. Specifying this option changes the behaviour to a case sensitive find operation.
  • FindWholeWords Makes find match only complete words.
Enumerator
FindBackward 
FindCaseSensitively 
FindWholeWords 

Definition at line 170 of file qtextdocument.h.

◆ MetaInformation

This enum describes the different types of meta information that can be added to a document.

  • DocumentTitle The title of the document.
  • DocumentUrl The url of the document. The loadResource() function uses this url as the base when loading relative resources.
See also
metaInformation(), setMetaInformation()
Enumerator
DocumentTitle 
DocumentUrl 

Definition at line 153 of file qtextdocument.h.

◆ ResourceType

This enum describes the types of resources that can be loaded by QTextDocument's loadResource() function.

  • HtmlResource The resource contains HTML.
  • ImageResource The resource contains image data. Currently supported data types are QVariant::Pixmap and QVariant::Image. If the corresponding variant is of type QVariant::ByteArray then Qt attempts to load the image using QImage::loadFromData. QVariant::Icon is currently not supported. The icon needs to be converted to one of the supported types first, for example using QIcon::pixmap.
  • StyleSheetResource The resource contains CSS.
  • UserResource The first available value for user defined resource types.
See also
loadResource()
Enumerator
HtmlResource 
ImageResource 
StyleSheetResource 
UserResource 

Definition at line 213 of file qtextdocument.h.

◆ Stacks

  • UndoStack The undo stack.
  • RedoStack The redo stack.
  • UndoAndRedoStacks Both the undo and redo stacks.
Enumerator
UndoStack 
RedoStack 
UndoAndRedoStacks 

Definition at line 259 of file qtextdocument.h.

Constructors and Destructors

◆ QTextDocument() [1/3]

QTextDocument::QTextDocument ( QObject parent = 0)
explicit

Constructs an empty QTextDocument with the given parent.

Definition at line 343 of file qtextdocument.cpp.

Referenced by clone().

344  : QObject(*new QTextDocumentPrivate, parent)
345 {
347  d->init();
348 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ QTextDocument() [2/3]

QTextDocument::QTextDocument ( const QString text,
QObject parent = 0 
)
explicit

Constructs a QTextDocument containing the plain (unformatted) text specified, and with the given parent.

Definition at line 354 of file qtextdocument.cpp.

355  : QObject(*new QTextDocumentPrivate, parent)
356 {
358  d->init();
359  QTextCursor(this).insertText(text);
360 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
void insertText(const QString &text)
Inserts text at the current position, using the current character format.
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ ~QTextDocument()

QTextDocument::~QTextDocument ( )

Destroys the document.

Definition at line 375 of file qtextdocument.cpp.

376 {
377 }

◆ QTextDocument() [3/3]

QTextDocument::QTextDocument ( QTextDocumentPrivate dd,
QObject parent 
)
protected
Warning
This function is not part of the public interface.

Definition at line 365 of file qtextdocument.cpp.

366  : QObject(dd, parent)
367 {
369  d->init();
370 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

Functions

◆ addResource()

void QTextDocument::addResource ( int  type,
const QUrl name,
const QVariant resource 
)

Adds the resource resource to the resource cache, using type and name as identifiers.

type should be a value from QTextDocument::ResourceType.

For example, you can add an image as a resource in order to reference it from within the document:

document->addResource(QTextDocument::ImageResource,
QUrl("mydata://image.png"), QVariant(image));

The image can be inserted into the document using the QTextCursor API:

QTextImageFormat imageFormat;
imageFormat.setName("mydata://image.png");
cursor.insertImage(imageFormat);

Alternatively, you can insert images using the HTML img tag:

editor->append("<img src=\"mydata://image.png\" />");

Definition at line 2108 of file qtextdocument.cpp.

Referenced by getImage(), getPixmap(), and QTextCursor::insertImage().

2109 {
2110  Q_UNUSED(type);
2111  Q_D(QTextDocument);
2112  d->resources.insert(name, resource);
2113 }
double d
Definition: qnumeric_p.h:62
int type
Definition: qmetatype.cpp:239
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ adjustSize()

void QTextDocument::adjustSize ( )

Adjusts the document to a reasonable size.

Since
4.2
See also
idealWidth(), textWidth, size

Definition at line 880 of file qtextdocument.cpp.

Referenced by QStaticTextPrivate::paintText(), and QWhatsThat::QWhatsThat().

881 {
882  // Pull this private function in from qglobal.cpp
883  QFont f = defaultFont();
884  QFontMetrics fm(f);
885  int mw = fm.width(QLatin1Char('x')) * 80;
886  int w = mw;
887  setTextWidth(w);
889  if (size.width() != 0) {
890  w = qt_int_sqrt((uint)(5 * size.height() * size.width() / 3));
891  setTextWidth(qMin(w, mw));
892 
893  size = documentLayout()->documentSize();
894  if (w*3 < 5*size.height()) {
895  w = qt_int_sqrt((uint)(2 * size.height() * size.width()));
896  setTextWidth(qMin(w, mw));
897  }
898  }
900 }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
Q_CORE_EXPORT unsigned int qt_int_sqrt(unsigned int n)
Definition: qglobal.cpp:2478
qreal width() const
Returns the width.
Definition: qsize.h:284
QSizeF size() const
qreal height() const
Returns the height.
Definition: qsize.h:287
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
virtual QSizeF documentSize() const =0
Returns the total size of the document&#39;s layout.
qreal idealWidth() const
Returns the ideal width of the text document.
unsigned int uint
Definition: qglobal.h:996
void setTextWidth(qreal width)
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
QAbstractTextDocumentLayout * documentLayout() const
Returns the document layout for this document.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
QFont defaultFont() const

◆ allFormats()

QVector< QTextFormat > QTextDocument::allFormats ( ) const

Returns a vector of text formats for all the formats used in the document.

Definition at line 3219 of file qtextdocument.cpp.

Referenced by QTextOdfWriter::writeAll().

3220 {
3221  Q_D(const QTextDocument);
3222  return d->formatCollection()->formats;
3223 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ appendUndoItem

void QTextDocument::appendUndoItem ( QAbstractUndoItem item)
slot

Appends a custom undo item to the undo stack.

Warning
This function is not part of the public interface.

Definition at line 531 of file qtextdocument.cpp.

532 {
534  d->appendUndoItem(item);
535 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ availableRedoSteps()

int QTextDocument::availableRedoSteps ( ) const

Returns the number of available redo steps.

Since
4.6
See also
isRedoAvailable()

Definition at line 1182 of file qtextdocument.cpp.

1183 {
1184  Q_D(const QTextDocument);
1185  return d->availableRedoSteps();
1186 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ availableUndoSteps()

int QTextDocument::availableUndoSteps ( ) const

Returns the number of available undo steps.

Since
4.6
See also
isUndoAvailable()

Definition at line 1167 of file qtextdocument.cpp.

1168 {
1169  Q_D(const QTextDocument);
1170  return d->availableUndoSteps();
1171 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ begin()

QTextBlock QTextDocument::begin ( ) const

Returns the document's first text block.

See also
firstBlock()

Definition at line 1685 of file qtextdocument.cpp.

Referenced by QTextHtmlExporter::emitBlock(), and qTextBlockAt().

1686 {
1687  Q_D(const QTextDocument);
1688  return QTextBlock(docHandle(), d->blockMap().begin().n);
1689 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QTextDocumentPrivate * docHandle() const
So that not all classes have to be friends of each other.
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ blockCount()

int QTextDocument::blockCount ( ) const

Referenced by adjustSize().

◆ blockCountChanged

QTextDocument::blockCountChanged ( int  newBlockCount)
signal

This signal is emitted when the total number of text blocks in the document changes.

Since
4.3

The value passed in newBlockCount is the new total.

◆ characterAt()

QChar QTextDocument::characterAt ( int  pos) const

Returns the character at position pos, or a null character if the position is out of range.

Since
4.5
See also
characterCount()

Definition at line 992 of file qtextdocument.cpp.

993 {
994  Q_D(const QTextDocument);
995  if (pos < 0 || pos >= d->length())
996  return QChar();
997  QTextDocumentPrivate::FragmentIterator fragIt = d->find(pos);
998  const QTextFragmentData * const frag = fragIt.value();
999  const int offsetInFragment = qMax(0, pos - fragIt.position());
1000  return d->text.at(frag->stringPosition + offsetInFragment);
1001 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
FragmentMap::ConstIterator FragmentIterator
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ characterCount()

int QTextDocument::characterCount ( ) const

Returns the number of characters of this document.

Since
4.5
See also
blockCount(), characterAt()

Definition at line 975 of file qtextdocument.cpp.

976 {
977  Q_D(const QTextDocument);
978  return d->length();
979 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ clear()

void QTextDocument::clear ( )
virtual

Clears the document.

Definition at line 420 of file qtextdocument.cpp.

Referenced by QTextControlPrivate::setContent().

421 {
423  d->clear();
424  d->resources.clear();
425 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ clearUndoRedoStacks()

void QTextDocument::clearUndoRedoStacks ( Stacks  stacksToClear = UndoAndRedoStacks)

Clears the stacks specified by stacksToClear.

Since
4.7

This method clears any commands on the undo stack, the redo stack, or both (the default). If commands are cleared, the appropriate signals are emitted, QTextDocument::undoAvailable() or QTextDocument::redoAvailable().

See also
QTextDocument::undoAvailable() QTextDocument::redoAvailable()

Definition at line 493 of file qtextdocument.cpp.

494 {
496  d->clearUndoRedoStacks(stacksToClear, true);
497 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ clone()

QTextDocument * QTextDocument::clone ( QObject parent = 0) const

Creates a new QTextDocument that is a copy of this text document.

parent is the parent of the returned text document.

Definition at line 384 of file qtextdocument.cpp.

385 {
386  Q_D(const QTextDocument);
387  QTextDocument *doc = new QTextDocument(parent);
389  doc->rootFrame()->setFrameFormat(rootFrame()->frameFormat());
390  QTextDocumentPrivate *priv = doc->d_func();
391  priv->title = d->title;
392  priv->url = d->url;
393  priv->pageSize = d->pageSize;
394  priv->indentWidth = d->indentWidth;
395  priv->defaultTextOption = d->defaultTextOption;
396  priv->setDefaultFont(d->defaultFont());
397  priv->resources = d->resources;
398  priv->cachedResources.clear();
399 #ifndef QT_NO_CSSPARSER
400  priv->defaultStyleSheet = d->defaultStyleSheet;
401  priv->parsedDefaultStyleSheet = d->parsedDefaultStyleSheet;
402 #endif
403  return doc;
404 }
double d
Definition: qnumeric_p.h:62
void setDefaultFont(const QFont &f)
#define Q_D(Class)
Definition: qglobal.h:2482
QTextOption defaultTextOption
QTextFrame * rootFrame() const
Returns the document&#39;s root frame.
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
QMap< QUrl, QVariant > cachedResources
QCss::StyleSheet parsedDefaultStyleSheet
void insertFragment(const QTextDocumentFragment &fragment)
Inserts the text fragment at the current position().
QTextDocument(QObject *parent=0)
Constructs an empty QTextDocument with the given parent.
static const QMetaObjectPrivate * priv(const uint *data)
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
QMap< QUrl, QVariant > resources
void setFrameFormat(const QTextFrameFormat &format)
Sets the frame&#39;s format.
Definition: qtextobject.h:191
The QTextDocumentFragment class represents a piece of formatted text from a QTextDocument.
void clear()
Removes all items from the map.
Definition: qmap.h:444

◆ contentsChange

void QTextDocument::contentsChange ( int  position,
int  charsRemoved,
int  charsAdded 
)
signal

This signal is emitted whenever the document's content changes; for example, when text is inserted or deleted, or when formatting is applied.

Information is provided about the position of the character in the document where the change occurred, the number of characters removed (charsRemoved), and the number of characters added (charsAdded).

The signal is emitted before the document's layout manager is notified about the change. This hook allows you to implement syntax highlighting for the document.

See also
QAbstractTextDocumentLayout::documentChanged(), contentsChanged()

◆ contentsChanged

void QTextDocument::contentsChanged ( )
signal

This signal is emitted whenever the document's content changes; for example, when text is inserted or deleted, or when formatting is applied.

See also
contentsChange()

◆ createObject()

QTextObject * QTextDocument::createObject ( const QTextFormat format)
protectedvirtual

Creates and returns a new document object (a QTextObject), based on the given format.

QTextObjects will always get created through this method, so you must reimplement it if you use custom text objects inside your document.

Definition at line 1586 of file qtextdocument.cpp.

Referenced by QTextDocumentPrivate::createObject().

1587 {
1588  QTextObject *obj = 0;
1589  if (f.isListFormat())
1590  obj = new QTextList(this);
1591  else if (f.isTableFormat())
1592  obj = new QTextTable(this);
1593  else if (f.isFrameFormat())
1594  obj = new QTextFrame(this);
1595 
1596  return obj;
1597 }
The QTextFrame class represents a frame in a QTextDocument.
Definition: qtextobject.h:122
The QTextTable class represents a table in a QTextDocument.
Definition: qtexttable.h:103
The QTextList class provides a decorated list of items in a QTextDocument.
Definition: qtextlist.h:57
The QTextObject class is a base class for different kinds of objects that can group parts of a QTextD...
Definition: qtextobject.h:64

◆ cursorPositionChanged

QTextDocument::cursorPositionChanged ( const QTextCursor cursor)
signal

This signal is emitted whenever the position of a cursor changed due to an editing operation.

The cursor that changed is passed in cursor. If you need a signal when the cursor is moved with the arrow keys you can use the QTextEdit::cursorPositionChanged() signal in QTextEdit.

◆ defaultCursorMoveStyle()

Qt::CursorMoveStyle QTextDocument::defaultCursorMoveStyle ( ) const

The default cursor movement style is used by all QTextCursor objects created from the document.

Since
4.8

The default is Qt::LogicalMoveStyle.

Definition at line 638 of file qtextdocument.cpp.

639 {
640  Q_D(const QTextDocument);
641  return d->defaultCursorMoveStyle;
642 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ defaultFont()

QFont QTextDocument::defaultFont ( ) const

Referenced by adjustSize(), and setDefaultFont().

◆ defaultStyleSheet()

QString QTextDocument::defaultStyleSheet ( ) const

Referenced by setDefaultStyleSheet().

◆ defaultTextOption()

QTextOption QTextDocument::defaultTextOption ( ) const

the default text option will be set on all QTextLayout in the document.

The default text option is used on all QTextLayout objects in the document.

When QTextBlock are created, the defaultTextOption is set on their QTextLayout. This allows setting global properties for the document such as the default word wrap mode.

Since
4.3

This allows setting global properties for the document such as the default word wrap mode.

Definition at line 607 of file qtextdocument.cpp.

Referenced by QLabelPrivate::ensureTextLayouted(), QPlainTextDocumentLayout::layoutBlock(), QTextEditPrivate::updateDefaultTextOption(), and QPlainTextEditPrivate::updateDefaultTextOption().

608 {
609  Q_D(const QTextDocument);
610  return d->defaultTextOption;
611 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ docHandle()

QTextDocumentPrivate * QTextDocument::docHandle ( ) const

So that not all classes have to be friends of each other.

Warning
This function is not part of the public interface.

..

Definition at line 3234 of file qtextdocument.cpp.

Referenced by QPlainTextEdit::anchorAt(), begin(), QTextBlockGroup::blockRemoved(), QTextHtmlExporter::emitBlock(), end(), findBlock(), findBlockByLineNumber(), findBlockByNumber(), QTextHtmlExporter::findUrlForImage(), firstBlock(), QTextCursor::insertFragment(), QTextDocumentFragment::isEmpty(), isModified(), lastBlock(), QTextDocumentFragmentPrivate::QTextDocumentFragmentPrivate(), QSyntaxHighlighterPrivate::reformatBlocks(), QAbstractTextDocumentLayoutPrivate::setDocument(), setModified(), QTextHtmlExporter::toHtml(), and QTextOdfWriter::writeAll().

3235 {
3236  Q_D(const QTextDocument);
3237  return const_cast<QTextDocumentPrivate *>(d);
3238 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ documentLayout()

QAbstractTextDocumentLayout * QTextDocument::documentLayout ( ) const

Returns the document layout for this document.

Definition at line 1223 of file qtextdocument.cpp.

Referenced by QPlainTextEditPrivate::_q_adjustScrollbars(), QTextControlPrivate::_q_documentLayoutChanged(), adjustSize(), QPlainTextEditPrivate::append(), QPlainTextEdit::blockBoundingRect(), boundingRectOfFloatsInSelection(), QTextEngine::docLayout(), documentSize(), drawContents(), getImageSize(), getPixmapSize(), QPlainTextEditControl::hitTest(), idealWidth(), QTextEditPrivate::init(), QPlainTextEditPrivate::init(), QWhatsThat::mouseMoveEvent(), QWhatsThat::mousePressEvent(), QWhatsThat::mouseReleaseEvent(), QAccessibleTextWidget::offsetAtPoint(), pageCount(), QTextEditPrivate::paint(), QGraphicsTextItem::paint(), QWhatsThat::paintEvent(), QPlainTextEdit::paintEvent(), QStaticTextPrivate::paintText(), QTextControl::print(), printPage(), QAccessibleTextEdit::rect(), QTextEditPrivate::relayoutDocument(), QPlainTextEditPrivate::relayoutDocument(), QTextEdit::resizeEvent(), QPlainTextEdit::setDocument(), and QPlainTextEditPrivate::verticalOffset().

1224 {
1225  Q_D(const QTextDocument);
1226  if (!d->lout) {
1227  QTextDocument *that = const_cast<QTextDocument *>(this);
1228  that->d_func()->setLayout(new QTextDocumentLayout(that));
1229  }
1230  return d->lout;
1231 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ documentLayoutChanged

QTextDocument::documentLayoutChanged ( )
signal

This signal is emitted when a new document layout is set.

Since
4.4
See also
setDocumentLayout()

◆ documentMargin()

qreal QTextDocument::documentMargin ( ) const

Referenced by idealWidth().

◆ drawContents()

void QTextDocument::drawContents ( QPainter p,
const QRectF rect = QRectF() 
)

Draws the content of the document with painter p, clipped to rect.

Since
4.2

If rect is a null rectangle (default) then the document is painted unclipped.

Definition at line 724 of file qtextdocument.cpp.

Referenced by QSplashScreen::drawContents().

725 {
726  p->save();
728  if (rect.isValid()) {
729  p->setClipRect(rect);
730  ctx.clip = rect;
731  }
732  documentLayout()->draw(p, ctx);
733  p->restore();
734 }
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
Definition: qrect.h:661
void setClipRect(const QRectF &, Qt::ClipOperation op=Qt::ReplaceClip)
Enables clipping, and sets the clip region to the given rectangle using the given clip operation...
Definition: qpainter.cpp:2801
void restore()
Restores the current painter state (pops a saved state off the stack).
Definition: qpainter.cpp:1620
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
QRectF clip
a hint to the layout specifying the area around paragraphs, frames or text require painting...
#define ctx
Definition: qgl.cpp:6094
QAbstractTextDocumentLayout * documentLayout() const
Returns the document layout for this document.
The QAbstractTextDocumentLayout::PaintContext class is a convenience class defining the parameters us...
virtual void draw(QPainter *painter, const PaintContext &context)=0
Draws the layout with the given painter using the given context.

◆ end()

QTextBlock QTextDocument::end ( ) const

This function returns a block to test for the end of the document while iterating over it.

for (QTextBlock it = doc->begin(); it != doc->end(); it = it.next())
cout << it.text().toStdString() << endl;

The block returned is invalid and represents the block after the last block in the document. You can use lastBlock() to retrieve the last valid block of the document.

See also
lastBlock()

Definition at line 1703 of file qtextdocument.cpp.

Referenced by findInBlock(), and formatDifference().

1704 {
1705  return QTextBlock(docHandle(), 0);
1706 }
QTextDocumentPrivate * docHandle() const
So that not all classes have to be friends of each other.
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199

◆ find() [1/4]

QTextCursor QTextDocument::find ( const QString subString,
int  position = 0,
FindFlags  options = 0 
) const

Finds the next occurrence of the string, subString, in the document.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

The search starts at the given position, and proceeds forwards through the document unless specified otherwise in the search options. The options control the type of search performed.

Returns a cursor with the match selected if subString was found; otherwise returns a null cursor.

If the position is 0 (the default) the search begins from the beginning of the document; otherwise it begins at the specified position.

Definition at line 1402 of file qtextdocument.cpp.

Referenced by QLabelPrivate::ensureTextPopulated(), and find().

1403 {
1404  QRegExp expr(subString);
1405  expr.setPatternSyntax(QRegExp::FixedString);
1406  expr.setCaseSensitivity((options & QTextDocument::FindCaseSensitively) ? Qt::CaseSensitive : Qt::CaseInsensitive);
1407 
1408  return find(expr, from, options);
1409 }
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
QTextCursor find(const QString &subString, int from=0, FindFlags options=0) const
Finds the next occurrence of the string, subString, in the document.

◆ find() [2/4]

QTextCursor QTextDocument::find ( const QString subString,
const QTextCursor cursor,
FindFlags  options = 0 
) const

Finds the next occurrence of the string, subString, in the document.

The search starts at the position of the given cursor, and proceeds forwards through the document unless specified otherwise in the search options. The options control the type of search performed.

Returns a cursor with the match selected if subString was found; otherwise returns a null cursor.

If the given cursor has a selection, the search begins after the selection; otherwise it begins at the cursor's position.

By default the search is case-sensitive, and can match text anywhere in the document.

Definition at line 1431 of file qtextdocument.cpp.

1432 {
1433  int pos = 0;
1434  if (!from.isNull()) {
1435  if (options & QTextDocument::FindBackward)
1436  pos = from.selectionStart();
1437  else
1438  pos = from.selectionEnd();
1439  }
1440  QRegExp expr(subString);
1441  expr.setPatternSyntax(QRegExp::FixedString);
1442  expr.setCaseSensitivity((options & QTextDocument::FindCaseSensitively) ? Qt::CaseSensitive : Qt::CaseInsensitive);
1443 
1444  return find(expr, pos, options);
1445 }
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
QTextCursor find(const QString &subString, int from=0, FindFlags options=0) const
Finds the next occurrence of the string, subString, in the document.

◆ find() [3/4]

QTextCursor QTextDocument::find ( const QRegExp expr,
int  position = 0,
FindFlags  options = 0 
) const

Finds the next occurrence, matching the regular expression, expr, in the document.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

The search starts at the given position, and proceeds forwards through the document unless specified otherwise in the search options. The options control the type of search performed. The FindCaseSensitively option is ignored for this overload, use QRegExp::caseSensitivity instead.

Returns a cursor with the match selected if a match was found; otherwise returns a null cursor.

If the position is 0 (the default) the search begins from the beginning of the document; otherwise it begins at the specified position.

Definition at line 1503 of file qtextdocument.cpp.

1504 {
1505  Q_D(const QTextDocument);
1506 
1507  if (expr.isEmpty())
1508  return QTextCursor();
1509 
1510  int pos = from;
1511  //the cursor is positioned between characters, so for a backward search
1512  //do not include the character given in the position.
1513  if (options & FindBackward) {
1514  --pos ;
1515  if(pos < 0)
1516  return QTextCursor();
1517  }
1518 
1519  QTextCursor cursor;
1520  QTextBlock block = d->blocksFind(pos);
1521 
1522  if (!(options & FindBackward)) {
1523  int blockOffset = qMax(0, pos - block.position());
1524  while (block.isValid()) {
1525  if (findInBlock(block, expr, blockOffset, options, cursor))
1526  return cursor;
1527  blockOffset = 0;
1528  block = block.next();
1529  }
1530  } else {
1531  int blockOffset = pos - block.position();
1532  while (block.isValid()) {
1533  if (findInBlock(block, expr, blockOffset, options, cursor))
1534  return cursor;
1535  block = block.previous();
1536  blockOffset = block.length() - 1;
1537  }
1538  }
1539 
1540  return QTextCursor();
1541 }
double d
Definition: qnumeric_p.h:62
static bool findInBlock(const QTextBlock &block, const QRegExp &expression, int offset, QTextDocument::FindFlags options, QTextCursor &cursor)
#define Q_D(Class)
Definition: qglobal.h:2482
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
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&#39;s first character within the document.
QTextBlock previous() const
Returns the text block in the document before this block, or an empty text block if this is the first...
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
int length() const
Returns the length of the block in characters.
bool isEmpty() const
Returns true if the pattern string is empty; otherwise returns false.
Definition: qregexp.cpp:3925
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.
Definition: qtextobject.h:208

◆ find() [4/4]

QTextCursor QTextDocument::find ( const QRegExp expr,
const QTextCursor cursor,
FindFlags  options = 0 
) const

Finds the next occurrence, matching the regular expression, expr, in the document.

The search starts at the position of the given cursor, and proceeds forwards through the document unless specified otherwise in the search options. The options control the type of search performed. The FindCaseSensitively option is ignored for this overload, use QRegExp::caseSensitivity instead.

Returns a cursor with the match selected if a match was found; otherwise returns a null cursor.

If the given cursor has a selection, the search begins after the selection; otherwise it begins at the cursor's position.

By default the search is case-sensitive, and can match text anywhere in the document.

Definition at line 1564 of file qtextdocument.cpp.

1565 {
1566  int pos = 0;
1567  if (!from.isNull()) {
1568  if (options & QTextDocument::FindBackward)
1569  pos = from.selectionStart();
1570  else
1571  pos = from.selectionEnd();
1572  }
1573  return find(expr, pos, options);
1574 }
QTextCursor find(const QString &subString, int from=0, FindFlags options=0) const
Finds the next occurrence of the string, subString, in the document.

◆ findBlock()

QTextBlock QTextDocument::findBlock ( int  pos) const

Returns the text block that contains the {pos}-th character.

Definition at line 1644 of file qtextdocument.cpp.

Referenced by QAccessibleTextWidget::characterRect(), QTextDocumentLayout::documentChanged(), QPlainTextDocumentLayout::documentChanged(), QPlainTextEditPrivate::ensureVisible(), and QSyntaxHighlighterPrivate::reformatBlocks().

1645 {
1646  Q_D(const QTextDocument);
1647  return QTextBlock(docHandle(), d->blockMap().findNode(pos));
1648 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QTextDocumentPrivate * docHandle() const
So that not all classes have to be friends of each other.
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ findBlockByLineNumber()

QTextBlock QTextDocument::findBlockByLineNumber ( int  lineNumber) const

Returns the text block that contains the specified lineNumber.

Since
4.5
See also
QTextBlock::firstLineNumber()

Definition at line 1674 of file qtextdocument.cpp.

Referenced by QPlainTextEditPrivate::setTopBlock(), and QPlainTextEditPrivate::setTopLine().

1675 {
1676  Q_D(const QTextDocument);
1677  return QTextBlock(docHandle(), d->blockMap().findNode(lineNumber, 2));
1678 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QTextDocumentPrivate * docHandle() const
So that not all classes have to be friends of each other.
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ findBlockByNumber()

QTextBlock QTextDocument::findBlockByNumber ( int  blockNumber) const

Returns the text block with the specified blockNumber.

Since
4.4
See also
QTextBlock::blockNumber()

Definition at line 1659 of file qtextdocument.cpp.

Referenced by QPlainTextEditControl::blockBoundingRect(), QPlainTextEditControl::firstVisibleBlock(), QScriptEdit::gotoLine(), QPlainTextEditControl::hitTest(), QPlainTextEditPrivate::setTopBlock(), and QPlainTextEditPrivate::verticalOffset().

1660 {
1661  Q_D(const QTextDocument);
1662  return QTextBlock(docHandle(), d->blockMap().findNode(blockNumber, 1));
1663 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QTextDocumentPrivate * docHandle() const
So that not all classes have to be friends of each other.
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ firstBlock()

QTextBlock QTextDocument::firstBlock ( ) const

Returns the document's first text block.

Since
4.4

Definition at line 1715 of file qtextdocument.cpp.

Referenced by QPlainTextDocumentLayout::documentChanged(), QPlainTextDocumentLayout::layoutBlock(), and QPlainTextDocumentLayoutPrivate::relayout().

1716 {
1717  Q_D(const QTextDocument);
1718  return QTextBlock(docHandle(), d->blockMap().begin().n);
1719 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QTextDocumentPrivate * docHandle() const
So that not all classes have to be friends of each other.
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ frameAt()

QTextFrame * QTextDocument::frameAt ( int  pos) const

Returns the frame that contains the text cursor position pos.

Warning
This function is not part of the public interface.

Definition at line 1607 of file qtextdocument.cpp.

1608 {
1609  Q_D(const QTextDocument);
1610  return d->frameAt(pos);
1611 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ idealWidth()

qreal QTextDocument::idealWidth ( ) const

Returns the ideal width of the text document.

Since
4.2

The ideal width is the actually used width of the document without optional alignments taken into account. It is always <= size().width().

See also
adjustSize(), textWidth

Definition at line 786 of file qtextdocument.cpp.

Referenced by adjustSize().

787 {
788  if (QTextDocumentLayout *lout = qobject_cast<QTextDocumentLayout *>(documentLayout()))
789  return lout->idealWidth();
790  return textWidth();
791 }
QAbstractTextDocumentLayout * documentLayout() const
Returns the document layout for this document.
qreal textWidth() const

◆ indentWidth()

qreal QTextDocument::indentWidth ( ) const

Referenced by setDocumentMargin().

◆ isEmpty()

bool QTextDocument::isEmpty ( ) const

Returns true if the document is empty; otherwise returns false.

Definition at line 409 of file qtextdocument.cpp.

Referenced by QPlainTextEdit::keyPressEvent(), and QTextEdit::keyPressEvent().

410 {
411  Q_D(const QTextDocument);
412  /* because if we're empty we still have one single paragraph as
413  * one single fragment */
414  return d->length() <= 1;
415 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ isModified()

bool QTextDocument::isModified ( ) const

Definition at line 1818 of file qtextdocument.cpp.

1819 {
1820  return docHandle()->isModified();
1821 }
QTextDocumentPrivate * docHandle() const
So that not all classes have to be friends of each other.

◆ isRedoAvailable()

bool QTextDocument::isRedoAvailable ( ) const

Returns true if redo is available; otherwise returns false.

See also
isUndoAvailable(), availableRedoSteps()

Definition at line 1152 of file qtextdocument.cpp.

1153 {
1154  Q_D(const QTextDocument);
1155  return d->isRedoAvailable();
1156 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ isUndoAvailable()

bool QTextDocument::isUndoAvailable ( ) const

Returns true if undo is available; otherwise returns false.

See also
isRedoAvailable(), availableUndoSteps()

Definition at line 1141 of file qtextdocument.cpp.

1142 {
1143  Q_D(const QTextDocument);
1144  return d->isUndoAvailable();
1145 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ isUndoRedoEnabled()

bool QTextDocument::isUndoRedoEnabled ( ) const

Definition at line 553 of file qtextdocument.cpp.

Referenced by QTextEdit::isUndoRedoEnabled(), and QTextControlPrivate::setContent().

554 {
555  Q_D(const QTextDocument);
556  return d->isUndoRedoEnabled();
557 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ lastBlock()

QTextBlock QTextDocument::lastBlock ( ) const

Returns the document's last (valid) text block.

Since
4.4

Definition at line 1728 of file qtextdocument.cpp.

Referenced by QPlainTextEditPrivate::_q_adjustScrollbars(), and QPlainTextEditPrivate::append().

1729 {
1730  Q_D(const QTextDocument);
1731  return QTextBlock(docHandle(), d->blockMap().last().n);
1732 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QTextDocumentPrivate * docHandle() const
So that not all classes have to be friends of each other.
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ lineCount()

int QTextDocument::lineCount ( ) const

Returns the number of lines of this document (if the layout supports this).

Since
4.5

Otherwise, this is identical to the number of blocks.

See also
blockCount(), characterCount()

Definition at line 959 of file qtextdocument.cpp.

Referenced by QPlainTextEditPrivate::_q_adjustScrollbars(), QPlainTextDocumentLayout::layoutBlock(), and QDeclarativeTextPrivate::setupTextLayout().

960 {
961  Q_D(const QTextDocument);
962  return d->blockMap().length(2);
963 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ loadResource()

QVariant QTextDocument::loadResource ( int  type,
const QUrl name 
)
protectedvirtual

Loads data of the specified type from the resource with the given name.

This function is called by the rich text engine to request data that isn't directly stored by QTextDocument, but still associated with it. For example, images are referenced indirectly by the name attribute of a QTextImageFormat object.

When called by Qt, type is one of the values of QTextDocument::ResourceType.

If the QTextDocument is a child object of a QTextEdit, QTextBrowser, or a QTextDocument itself then the default implementation tries to retrieve the data from the parent.

Reimplemented in QTextDocumentWithImageResources.

Definition at line 2131 of file qtextdocument.cpp.

Referenced by QTextDocumentWithImageResources::loadResource(), and loadResource().

2132 {
2133  Q_D(QTextDocument);
2134  QVariant r;
2135 
2137  if (doc) {
2138  r = doc->loadResource(type, name);
2139  }
2140 #ifndef QT_NO_TEXTEDIT
2141  else if (QTextEdit *edit = qobject_cast<QTextEdit *>(parent())) {
2142  QUrl resolvedName = edit->d_func()->resolveUrl(name);
2143  r = edit->loadResource(type, resolvedName);
2144  }
2145 #endif
2146 #ifndef QT_NO_TEXTCONTROL
2147  else if (QTextControl *control = qobject_cast<QTextControl *>(parent())) {
2148  r = control->loadResource(type, name);
2149  }
2150 #endif
2151 
2152  // handle data: URLs
2153  if (r.isNull() && name.scheme().compare(QLatin1String("data"), Qt::CaseInsensitive) == 0)
2154  r = qDecodeDataUrl(name).second;
2155 
2156  // if resource was not loaded try to load it here
2157  if (!doc && r.isNull() && name.isRelative()) {
2158  QUrl currentURL = d->url;
2159  QUrl resourceUrl = name;
2160 
2161  // For the second case QUrl can merge "#someanchor" with "foo.html"
2162  // correctly to "foo.html#someanchor"
2163  if (!(currentURL.isRelative()
2164  || (currentURL.scheme() == QLatin1String("file")
2165  && !QFileInfo(currentURL.toLocalFile()).isAbsolute()))
2166  || (name.hasFragment() && name.path().isEmpty())) {
2167  resourceUrl = currentURL.resolved(name);
2168  } else {
2169  // this is our last resort when current url and new url are both relative
2170  // we try to resolve against the current working directory in the local
2171  // file system.
2172  QFileInfo fi(currentURL.toLocalFile());
2173  if (fi.exists()) {
2174  resourceUrl =
2175  QUrl::fromLocalFile(fi.absolutePath() + QDir::separator()).resolved(name);
2176  } else if (currentURL.isEmpty()) {
2177  resourceUrl.setScheme(QLatin1String("file"));
2178  }
2179  }
2180 
2181  QString s = resourceUrl.toLocalFile();
2182  QFile f(s);
2183  if (!s.isEmpty() && f.open(QFile::ReadOnly)) {
2184  r = f.readAll();
2185  f.close();
2186  }
2187  }
2188 
2189  if (!r.isNull()) {
2190  if (type == ImageResource && r.type() == QVariant::ByteArray) {
2191  if (qApp->thread() != QThread::currentThread()) {
2192  // must use images in non-GUI threads
2193  QImage image;
2194  image.loadFromData(r.toByteArray());
2195  if (!image.isNull())
2196  r = image;
2197  } else {
2198  QPixmap pm;
2199  pm.loadFromData(r.toByteArray());
2200  if (!pm.isNull())
2201  r = pm;
2202  }
2203  }
2204  d->cachedResources.insert(name, r);
2205  }
2206  return r;
2207 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
double d
Definition: qnumeric_p.h:62
int type
Definition: qmetatype.cpp:239
bool isNull() const
Returns true if this is a NULL variant, false otherwise.
Definition: qvariant.cpp:3102
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
bool isEmpty() const
Returns true if the URL has no data; otherwise returns false.
Definition: qurl.cpp:4317
T2 second
Definition: qpair.h:66
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
T * qobject_cast(QObject *object)
Definition: qobject.h:375
#define Q_D(Class)
Definition: qglobal.h:2482
static QChar separator()
Returns the native directory separator: "/" under Unix (including Mac OS X) and "\\" under Windows...
Definition: qdir.cpp:1831
bool isRelative() const
Returns true if the URL is relative; otherwise returns false.
Definition: qurl.cpp:5880
QByteArray toByteArray() const
Returns the variant as a QByteArray if the variant has type() ByteArray or String (converted using QS...
Definition: qvariant.cpp:2383
QString path() const
Returns the path of the URL.
Definition: qurl.cpp:4977
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
#define qApp
const char * name
virtual QVariant loadResource(int type, const QUrl &name)
Loads data of the specified type from the resource with the given name.
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
bool loadFromData(const uchar *buf, uint len, const char *format=0, Qt::ImageConversionFlags flags=Qt::AutoColor)
Loads a pixmap from the len first bytes of the given binary data.
Definition: qpixmap.cpp:979
QString toLocalFile() const
Returns the path of this URL formatted as a local file path.
Definition: qurl.cpp:6412
QString scheme() const
Returns the scheme of the URL.
Definition: qurl.cpp:4550
int compare(const QString &s) const
Definition: qstring.cpp:5037
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
bool hasFragment() const
Returns true if this URL contains a fragment (i.
Definition: qurl.cpp:5773
void setScheme(const QString &scheme)
Sets the scheme of the URL to scheme.
Definition: qurl.cpp:4533
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
static QUrl fromLocalFile(const QString &localfile)
Returns a QUrl representation of localFile, interpreted as a local file.
Definition: qurl.cpp:6374
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
QUrl resolved(const QUrl &relative) const
Returns the result of the merge of this URL with relative.
Definition: qurl.cpp:5819
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
The QTextEdit class provides a widget that is used to edit and display both plain and rich text...
Definition: qtextedit.h:70
Q_CORE_EXPORT QPair< QString, QByteArray > qDecodeDataUrl(const QUrl &uri)
Decode a data: URL into its mimetype and payload.
Definition: qdataurl.cpp:57
bool loadFromData(const uchar *buf, int len, const char *format=0)
Loads an image from the first len bytes of the given binary data.
Definition: qimage.cpp:5275

◆ markContentsDirty()

void QTextDocument::markContentsDirty ( int  from,
int  length 
)

Marks the contents specified by the given position and length as "dirty", informing the document that it needs to be laid out again.

Definition at line 668 of file qtextdocument.cpp.

Referenced by QSyntaxHighlighterPrivate::applyFormatChanges().

669 {
671  d->documentChange(from, length);
672  if (!d->inContentsChange) {
673  if (d->lout) {
674  d->lout->documentChanged(d->docChangeFrom, d->docChangeOldLength, d->docChangeLength);
675  d->docChangeFrom = -1;
676  }
677  }
678 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ maximumBlockCount()

int QTextDocument::maximumBlockCount ( ) const

Referenced by isUndoRedoEnabled().

◆ metaInformation()

QString QTextDocument::metaInformation ( MetaInformation  info) const

Returns meta information about the document of the type specified by info.

See also
setMetaInformation()

Definition at line 1240 of file qtextdocument.cpp.

Referenced by QTextEdit::documentTitle(), QTextControl::print(), and QTextHtmlExporter::toHtml().

1241 {
1242  Q_D(const QTextDocument);
1243  switch (info) {
1244  case DocumentTitle:
1245  return d->title;
1246  case DocumentUrl:
1247  return d->url;
1248  }
1249  return QString();
1250 }
double d
Definition: qnumeric_p.h:62
static mach_timebase_info_data_t info
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ modificationChanged

QTextDocument::modificationChanged ( bool  changed)
signal

This signal is emitted whenever the content of the document changes in a way that affects the modification state.

If changed is true, the document has been modified; otherwise it is false.

For example, calling setModified(false) on a document and then inserting text causes the signal to get emitted. If you undo that operation, causing the document to return to its original unmodified state, the signal will get emitted again.

◆ object()

QTextObject * QTextDocument::object ( int  objectIndex) const

Returns the text object associated with the given objectIndex.

Definition at line 1625 of file qtextdocument.cpp.

1626 {
1627  Q_D(const QTextDocument);
1628  return d->objectForIndex(objectIndex);
1629 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ objectForFormat()

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

Returns the text object associated with the format f.

Definition at line 1634 of file qtextdocument.cpp.

Referenced by QTextDocumentLayoutPrivate::blockIndent(), QTextDocumentLayoutPrivate::drawBlock(), QTextDocumentLayoutPrivate::drawListItem(), QTextHtmlExporter::emitFragment(), QTextBlock::textList(), and QTextOdfWriter::writeAll().

1635 {
1636  Q_D(const QTextDocument);
1637  return d->objectForFormat(f);
1638 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ pageCount()

int QTextDocument::pageCount ( ) const

returns the number of pages in this document.

Definition at line 1764 of file qtextdocument.cpp.

1765 {
1766  return documentLayout()->pageCount();
1767 }
virtual int pageCount() const =0
Returns the number of pages contained in the layout.
QAbstractTextDocumentLayout * documentLayout() const
Returns the document layout for this document.

◆ pageSize()

QSizeF QTextDocument::pageSize ( ) const

Referenced by setPageSize().

◆ print()

void QTextDocument::print ( QPrinter printer) const

Prints the document to the given printer.

The QPrinter must be set up before being used with this function.

This is only a convenience method to print the whole document to the printer.

If the document is already paginated through a specified height in the pageSize() property it is printed as-is.

If the document is not paginated, like for example a document used in a QTextEdit, then a temporary copy of the document is created and the copy is broken into multiple pages according to the size of the QPrinter's paperRect(). By default a 2 cm margin is set around the document contents. In addition the current page number is printed at the bottom of each page.

Note that QPrinter::Selection is not supported as print range with this function since the selection is a property of QTextCursor. If you have a QTextEdit associated with your QTextDocument then you can use QTextEdit's print() function because QTextEdit has access to the user's selection.

See also
QTextEdit::print()

Definition at line 1884 of file qtextdocument.cpp.

Referenced by QTextControl::print().

1885 {
1886  Q_D(const QTextDocument);
1887 
1888  if (!printer || !printer->isValid())
1889  return;
1890 
1891  if (!d->title.isEmpty())
1892  printer->setDocName(d->title);
1893 
1894  bool documentPaginated = d->pageSize.isValid() && !d->pageSize.isNull()
1895  && d->pageSize.height() != INT_MAX;
1896 
1897  if (!documentPaginated && !printer->fullPage() && !printer->d_func()->hasCustomPageMargins)
1898  printer->setPageMargins(23.53, 23.53, 23.53, 23.53, QPrinter::Millimeter);
1899 
1900  QPainter p(printer);
1901 
1902  // Check that there is a valid device to print to.
1903  if (!p.isActive())
1904  return;
1905 
1906  const QTextDocument *doc = this;
1908  (void)doc->documentLayout(); // make sure that there is a layout
1909 
1910  QRectF body = QRectF(QPointF(0, 0), d->pageSize);
1911  QPointF pageNumberPos;
1912 
1913  if (documentPaginated) {
1914  qreal sourceDpiX = qt_defaultDpi();
1915  qreal sourceDpiY = sourceDpiX;
1916 
1917  QPaintDevice *dev = doc->documentLayout()->paintDevice();
1918  if (dev) {
1919  sourceDpiX = dev->logicalDpiX();
1920  sourceDpiY = dev->logicalDpiY();
1921  }
1922 
1923  const qreal dpiScaleX = qreal(printer->logicalDpiX()) / sourceDpiX;
1924  const qreal dpiScaleY = qreal(printer->logicalDpiY()) / sourceDpiY;
1925 
1926  // scale to dpi
1927  p.scale(dpiScaleX, dpiScaleY);
1928 
1929  QSizeF scaledPageSize = d->pageSize;
1930  scaledPageSize.rwidth() *= dpiScaleX;
1931  scaledPageSize.rheight() *= dpiScaleY;
1932 
1933  const QSizeF printerPageSize(printer->pageRect().size());
1934 
1935  // scale to page
1936  p.scale(printerPageSize.width() / scaledPageSize.width(),
1937  printerPageSize.height() / scaledPageSize.height());
1938  } else {
1939  doc = clone(const_cast<QTextDocument *>(this));
1940  clonedDoc.reset(const_cast<QTextDocument *>(doc));
1941 
1942  for (QTextBlock srcBlock = firstBlock(), dstBlock = clonedDoc->firstBlock();
1943  srcBlock.isValid() && dstBlock.isValid();
1944  srcBlock = srcBlock.next(), dstBlock = dstBlock.next()) {
1945  dstBlock.layout()->setAdditionalFormats(srcBlock.layout()->additionalFormats());
1946  }
1947 
1949  layout->setPaintDevice(p.device());
1950 
1951  // copy the custom object handlers
1952  layout->d_func()->handlers = documentLayout()->d_func()->handlers;
1953 
1954  int dpiy = p.device()->logicalDpiY();
1955  int margin = 0;
1956  if (printer->fullPage() && !printer->d_func()->hasCustomPageMargins) {
1957  // for compatibility
1958  margin = (int) ((2/2.54)*dpiy); // 2 cm margins
1959  QTextFrameFormat fmt = doc->rootFrame()->frameFormat();
1960  fmt.setMargin(margin);
1961  doc->rootFrame()->setFrameFormat(fmt);
1962  }
1963 
1964  QRectF pageRect(printer->pageRect());
1965  body = QRectF(0, 0, pageRect.width(), pageRect.height());
1966  pageNumberPos = QPointF(body.width() - margin,
1967  body.height() - margin
1968  + QFontMetrics(doc->defaultFont(), p.device()).ascent()
1969  + 5 * dpiy / 72.0);
1970  clonedDoc->setPageSize(body.size());
1971  }
1972 
1973  int docCopies;
1974  int pageCopies;
1975  if (printer->collateCopies() == true){
1976  docCopies = 1;
1977  pageCopies = printer->supportsMultipleCopies() ? 1 : printer->copyCount();
1978  } else {
1979  docCopies = printer->supportsMultipleCopies() ? 1 : printer->copyCount();
1980  pageCopies = 1;
1981  }
1982 
1983  int fromPage = printer->fromPage();
1984  int toPage = printer->toPage();
1985  bool ascending = true;
1986 
1987  if (fromPage == 0 && toPage == 0) {
1988  fromPage = 1;
1989  toPage = doc->pageCount();
1990  }
1991  // paranoia check
1992  fromPage = qMax(1, fromPage);
1993  toPage = qMin(doc->pageCount(), toPage);
1994 
1995  if (toPage < fromPage) {
1996  // if the user entered a page range outside the actual number
1997  // of printable pages, just return
1998  return;
1999  }
2000 
2001  if (printer->pageOrder() == QPrinter::LastPageFirst) {
2002  int tmp = fromPage;
2003  fromPage = toPage;
2004  toPage = tmp;
2005  ascending = false;
2006  }
2007 
2008  for (int i = 0; i < docCopies; ++i) {
2009 
2010  int page = fromPage;
2011  while (true) {
2012  for (int j = 0; j < pageCopies; ++j) {
2013  if (printer->printerState() == QPrinter::Aborted
2014  || printer->printerState() == QPrinter::Error)
2015  return;
2016  printPage(page, &p, doc, body, pageNumberPos);
2017  if (j < pageCopies - 1)
2018  printer->newPage();
2019  }
2020 
2021  if (page == toPage)
2022  break;
2023 
2024  if (ascending)
2025  ++page;
2026  else
2027  --page;
2028 
2029  printer->newPage();
2030  }
2031 
2032  if ( i < docCopies - 1)
2033  printer->newPage();
2034  }
2035 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
bool fullPage() const
Returns true if the origin of the printer&#39;s coordinate system is at the corner of the page and false ...
Definition: qprinter.cpp:1542
double d
Definition: qnumeric_p.h:62
int toPage() const
Returns the number of the last page in a range of pages to be printed (the "to page" setting)...
Definition: qprinter.cpp:2196
double qreal
Definition: qglobal.h:1193
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
PrinterState printerState() const
Returns the current state of the printer.
Definition: qprinter.cpp:1990
QRect pageRect() const
Returns the page&#39;s rectangle; this is usually smaller than the paperRect() since the page normally ha...
Definition: qprinter.cpp:1800
int logicalDpiY() const
Definition: qpaintdevice.h:96
qreal width() const
Returns the width.
Definition: qsize.h:284
int fromPage() const
Returns the number of the first page in a range of pages to be printed (the "from page" setting)...
Definition: qprinter.cpp:2168
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
qreal height() const
Returns the height.
Definition: qsize.h:287
void setPageMargins(qreal left, qreal top, qreal right, qreal bottom, Unit unit)
This function sets the left, top, right and bottom page margins for this printer. ...
Definition: qprinter.cpp:1831
void scale(qreal w, qreal h, Qt::AspectRatioMode mode)
Scales the size to a rectangle with the given width and height, according to the specified mode...
Definition: qsize.h:296
void setPageSize(const QSizeF &size)
QFont defaultFont
the default font used to display the document&#39;s text
#define Q_D(Class)
Definition: qglobal.h:2482
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon dest...
QTextFrame * rootFrame() const
Returns the document&#39;s root frame.
int logicalDpiX() const
Definition: qpaintdevice.h:95
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
const char * layout
bool isValid() const
Returns true if the printer currently selected is a valid printer in the system, or a pure PDF/PostSc...
Definition: qprinter.cpp:895
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
int pageCount() const
returns the number of pages in this document.
bool supportsMultipleCopies() const
Returns true if the printer supports printing multiple copies of the same document in one job; otherw...
Definition: qprinter.cpp:1453
QTextDocument * clone(QObject *parent=0) const
Creates a new QTextDocument that is a copy of this text document.
static void printPage(int index, QPainter *painter, const QTextDocument *doc, const QRectF &body, const QPointF &pageNumberPos)
void reset(T *other=0)
Deletes the existing object it is pointing to if any, and sets its pointer to other.
bool newPage()
Tells the printer to eject the current page and to continue printing on a new page.
Definition: qprinter.cpp:1962
bool collateCopies() const
Returns true if collation is turned on when multiple copies is selected.
Definition: qprinter.cpp:1473
Q_GUI_EXPORT int qt_defaultDpi()
Definition: qfont.cpp:240
QAbstractTextDocumentLayout * documentLayout() const
Returns the document layout for this document.
The QTextFrameFormat class provides formatting information for frames in a QTextDocument.
Definition: qtextformat.h:727
QPaintDevice * paintDevice() const
Returns the paint device used to render the document&#39;s layout.
int copyCount() const
Returns the number of copies that will be printed.
Definition: qprinter.cpp:1430
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.
Definition: qtextobject.h:208
void setPaintDevice(QPaintDevice *device)
Sets the paint device used for rendering the document&#39;s layout to the given device.
void setMargin(qreal margin)
Sets the frame&#39;s margin in pixels.
void setDocName(const QString &)
Sets the document name to name.
Definition: qprinter.cpp:1052
qreal & rheight()
Returns a reference to the height.
Definition: qsize.h:302
void setFrameFormat(const QTextFrameFormat &format)
Sets the frame&#39;s format.
Definition: qtextobject.h:191
QTextFrameFormat frameFormat() const
Returns the frame&#39;s format.
Definition: qtextobject.h:131
#define INT_MAX
qreal & rwidth()
Returns a reference to the width.
Definition: qsize.h:299
PageOrder pageOrder() const
Returns the current page order.
Definition: qprinter.cpp:1286
The QAbstractTextDocumentLayout class is an abstract base class used to implement custom layouts for ...
QTextBlock firstBlock() const
Returns the document&#39;s first text block.

◆ redo() [1/2]

void QTextDocument::redo ( QTextCursor cursor)

Redoes the last editing operation on the document if redo is available.

Since
4.2

The provided cursor is positioned at the end of the location where the edition operation was redone.

Definition at line 462 of file qtextdocument.cpp.

463 {
465  const int pos = d->undoRedo(false);
466  if (cursor && pos >= 0) {
467  *cursor = QTextCursor(this);
468  cursor->setPosition(pos);
469  }
470 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
void setPosition(int pos, MoveMode mode=MoveAnchor)
Moves the cursor to the absolute position in the document specified by pos using a MoveMode specified...
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ redo [2/2]

void QTextDocument::redo ( )
slot

Redoes the last editing operation on the document if redo is available.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 517 of file qtextdocument.cpp.

518 {
520  d->undoRedo(false);
521 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ redoAvailable

QTextDocument::redoAvailable ( bool  available)
signal

This signal is emitted whenever redo operations become available (available is true) or unavailable (available is false).

◆ resource()

QVariant QTextDocument::resource ( int  type,
const QUrl name 
) const

Returns data of the specified type from the resource with the given name.

This function is called by the rich text engine to request data that isn't directly stored by QTextDocument, but still associated with it. For example, images are referenced indirectly by the name attribute of a QTextImageFormat object.

Resources are cached internally in the document. If a resource can not be found in the cache, loadResource is called to try to load the resource. loadResource should then use addResource to add the resource to the cache.

See also
QTextDocument::ResourceType

Definition at line 2078 of file qtextdocument.cpp.

Referenced by QTextHtmlParserNode::applyBackgroundImage(), getImage(), and getPixmap().

2079 {
2080  Q_D(const QTextDocument);
2081  QVariant r = d->resources.value(name);
2082  if (!r.isValid()) {
2083  r = d->cachedResources.value(name);
2084  if (!r.isValid())
2085  r = const_cast<QTextDocument *>(this)->loadResource(type, name);
2086  }
2087  return r;
2088 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
double d
Definition: qnumeric_p.h:62
int type
Definition: qmetatype.cpp:239
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485

◆ revision()

int QTextDocument::revision ( ) const

Returns the document's revision (if undo is enabled).

Since
4.4

The revision is guaranteed to increase when a document that is not modified is edited.

See also
QTextBlock::revision(), isModified()

Definition at line 1200 of file qtextdocument.cpp.

1201 {
1202  Q_D(const QTextDocument);
1203  return d->revision;
1204 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ rootFrame()

QTextFrame * QTextDocument::rootFrame ( ) const

Returns the document's root frame.

Definition at line 1616 of file qtextdocument.cpp.

Referenced by clone(), QTextHtmlImporter::closeTag(), QTextDocumentLayoutPrivate::drawBlock(), QTextHtmlExporter::emitFrame(), QLabelPrivate::ensureTextLayouted(), QTextDocumentLayoutPrivate::frameIteratorForYPosition(), QTextDocumentLayoutPrivate::layoutFlow(), QTextHtmlImporter::processSpecialNodes(), setDocumentMargin(), QTextHtmlExporter::toHtml(), QTextOdfWriter::writeAll(), and QTextOdfWriter::writeFrame().

1617 {
1618  Q_D(const QTextDocument);
1619  return d->rootFrame();
1620 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ setDefaultCursorMoveStyle()

void QTextDocument::setDefaultCursorMoveStyle ( Qt::CursorMoveStyle  style)

Sets the default cursor movement style to the given style.

Since
4.8

Definition at line 652 of file qtextdocument.cpp.

653 {
655  d->defaultCursorMoveStyle = style;
656 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ setDefaultFont()

void QTextDocument::setDefaultFont ( const QFont font)

Sets the default font to use in the document layout.

Definition at line 1772 of file qtextdocument.cpp.

Referenced by QTextEditPrivate::init(), QPlainTextEditPrivate::init(), QStaticTextPrivate::paintText(), QTextControl::print(), QWhatsThat::QWhatsThat(), and QGraphicsTextItem::setFont().

1773 {
1774  Q_D(QTextDocument);
1775  d->setDefaultFont(font);
1776  if (d->lout)
1777  d->lout->documentChanged(0, 0, d->length());
1778 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ setDefaultStyleSheet()

void QTextDocument::setDefaultStyleSheet ( const QString sheet)

Definition at line 1023 of file qtextdocument.cpp.

Referenced by QStaticTextPrivate::paintText().

1024 {
1025  Q_D(QTextDocument);
1026  d->defaultStyleSheet = sheet;
1027  QCss::Parser parser(sheet);
1028  d->parsedDefaultStyleSheet = QCss::StyleSheet();
1029  d->parsedDefaultStyleSheet.origin = QCss::StyleSheetOrigin_UserAgent;
1030  parser.parse(&d->parsedDefaultStyleSheet);
1031 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ setDefaultTextOption()

void QTextDocument::setDefaultTextOption ( const QTextOption option)

Sets the default text option.

Since
4.3

Definition at line 621 of file qtextdocument.cpp.

Referenced by QLabelPrivate::ensureTextLayouted(), QStaticTextPrivate::paintText(), QTextEditPrivate::updateDefaultTextOption(), and QPlainTextEditPrivate::updateDefaultTextOption().

622 {
624  d->defaultTextOption = option;
625  if (d->lout)
626  d->lout->documentChanged(0, 0, d->length());
627 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ setDocumentLayout()

void QTextDocument::setDocumentLayout ( QAbstractTextDocumentLayout layout)

Sets the document to use the given layout.

The previous layout is deleted.

See also
documentLayoutChanged()

Definition at line 1214 of file qtextdocument.cpp.

Referenced by QPlainTextEditPrivate::init(), and QPlainTextEdit::setDocument().

1215 {
1216  Q_D(QTextDocument);
1217  d->setLayout(layout);
1218 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ setDocumentMargin()

void QTextDocument::setDocumentMargin ( qreal  margin)

Definition at line 808 of file qtextdocument.cpp.

Referenced by QStaticTextPrivate::paintText().

809 {
811  if (d->documentMargin != margin) {
812  d->documentMargin = margin;
813 
814  QTextFrame* root = rootFrame();
816  format.setMargin(margin);
817  root->setFrameFormat(format);
818 
819  if (d->lout)
820  d->lout->documentChanged(0, 0, d->length());
821  }
822 }
double d
Definition: qnumeric_p.h:62
The QTextFrame class represents a frame in a QTextDocument.
Definition: qtextobject.h:122
#define Q_D(Class)
Definition: qglobal.h:2482
QTextFrame * rootFrame() const
Returns the document&#39;s root frame.
The QTextFrameFormat class provides formatting information for frames in a QTextDocument.
Definition: qtextformat.h:727
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
void setMargin(qreal margin)
Sets the frame&#39;s margin in pixels.
void setFrameFormat(const QTextFrameFormat &format)
Sets the frame&#39;s format.
Definition: qtextobject.h:191
QTextFrameFormat frameFormat() const
Returns the frame&#39;s format.
Definition: qtextobject.h:131

◆ setHtml()

void QTextDocument::setHtml ( const QString html)

Replaces the entire contents of the document with the given HTML-formatted text in the html string.

The HTML formatting is respected as much as possible; for example, "<b>bold</b> text" will produce text where the first word has a font weight that gives it a bold appearance: "<b>bold</b> text".

Note
It is the responsibility of the caller to make sure that the text is correctly decoded when a QString containing HTML is created and passed to setHtml().
See also
setPlainText(), {Supported HTML Subset}

Definition at line 1338 of file qtextdocument.cpp.

Referenced by QSplashScreen::drawContents(), QLabelPrivate::ensureTextPopulated(), handleStringAttribute(), QStaticTextPrivate::paintText(), QWhatsThat::QWhatsThat(), QTextDocumentWithImageResources::requestFinished(), QTextControlPrivate::setContent(), QTextDocumentWithImageResources::setText(), and QAccessibleDisplay::text().

1339 {
1340  Q_D(QTextDocument);
1341  bool previousState = d->isUndoRedoEnabled();
1342  d->enableUndoRedo(false);
1343  d->beginEditBlock();
1344  d->clear();
1346  d->endEditBlock();
1347  d->enableUndoRedo(previousState);
1348 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ setIndentWidth()

void QTextDocument::setIndentWidth ( qreal  width)

Sets the width used for text list and text block indenting.

Since
4.4

The indent properties of QTextListFormat and QTextBlockFormat specify multiples of this value. The default indent width is 40 .

See also
indentWidth()

Definition at line 857 of file qtextdocument.cpp.

858 {
860  if (d->indentWidth != width) {
861  d->indentWidth = width;
862  if (d->lout)
863  d->lout->documentChanged(0, 0, d->length());
864  }
865 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ setMaximumBlockCount()

void QTextDocument::setMaximumBlockCount ( int  maximum)

Definition at line 589 of file qtextdocument.cpp.

Referenced by QPlainTextEditPrivate::append().

590 {
592  d->maximumBlockCount = maximum;
593  d->ensureMaximumBlockCount();
594  setUndoRedoEnabled(false);
595 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
void setUndoRedoEnabled(bool enable)
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ setMetaInformation()

void QTextDocument::setMetaInformation ( MetaInformation  info,
const QString string 
)

Sets the document's meta information of the type specified by info to the given string.

See also
metaInformation()

Definition at line 1258 of file qtextdocument.cpp.

Referenced by QTextHtmlImporter::import(), QTextControl::print(), and QTextEdit::setDocumentTitle().

1259 {
1260  Q_D(QTextDocument);
1261  switch (info) {
1262  case DocumentTitle:
1263  d->title = string;
1264  break;
1265  case DocumentUrl:
1266  d->url = string;
1267  break;
1268  }
1269 }
double d
Definition: qnumeric_p.h:62
static mach_timebase_info_data_t info
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ setModified

void QTextDocument::setModified ( bool  m = true)
slot

Definition at line 1823 of file qtextdocument.cpp.

Referenced by QTextControlPrivate::setContent().

1824 {
1825  docHandle()->setModified(m);
1826 }
QTextDocumentPrivate * docHandle() const
So that not all classes have to be friends of each other.

◆ setPageSize()

void QTextDocument::setPageSize ( const QSizeF size)

Definition at line 1747 of file qtextdocument.cpp.

Referenced by QTextEditPrivate::init(), QTextControl::print(), QTextEditPrivate::relayoutDocument(), and setTextWidth().

1748 {
1749  Q_D(QTextDocument);
1750  d->pageSize = size;
1751  if (d->lout)
1752  d->lout->documentChanged(0, 0, d->length());
1753 }
double d
Definition: qnumeric_p.h:62
QSizeF size() const
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ setPlainText()

void QTextDocument::setPlainText ( const QString text)

Replaces the entire contents of the document with the given plain text.

See also
setHtml()

Definition at line 1309 of file qtextdocument.cpp.

Referenced by QSplashScreen::drawContents(), QLabelPrivate::ensureTextPopulated(), QStaticTextPrivate::paintText(), QWhatsThat::QWhatsThat(), QTextDocumentWithImageResources::requestFinished(), QTextControlPrivate::setContent(), and QTextDocumentWithImageResources::setText().

1310 {
1311  Q_D(QTextDocument);
1312  bool previousState = d->isUndoRedoEnabled();
1313  d->enableUndoRedo(false);
1314  d->beginEditBlock();
1315  d->clear();
1316  QTextCursor(this).insertText(text);
1317  d->endEditBlock();
1318  d->enableUndoRedo(previousState);
1319 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
void insertText(const QString &text)
Inserts text at the current position, using the current character format.
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ setTextWidth()

void QTextDocument::setTextWidth ( qreal  width)

Definition at line 760 of file qtextdocument.cpp.

Referenced by adjustSize(), QSplashScreen::drawContents(), QLabelPrivate::ensureTextLayouted(), QPlainTextEditPrivate::init(), and QStaticTextPrivate::paintText().

761 {
763  QSizeF sz = d->pageSize;
764  sz.setWidth(width);
765  sz.setHeight(-1);
766  setPageSize(sz);
767 }
double d
Definition: qnumeric_p.h:62
void setPageSize(const QSizeF &size)
void setWidth(qreal w)
Sets the width to the given width.
Definition: qsize.h:290
#define Q_D(Class)
Definition: qglobal.h:2482
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
void setHeight(qreal h)
Sets the height to the given height.
Definition: qsize.h:293

◆ setUndoRedoEnabled()

void QTextDocument::setUndoRedoEnabled ( bool  enable)

Definition at line 547 of file qtextdocument.cpp.

Referenced by QLabelPrivate::ensureTextPopulated(), QTextEditPrivate::init(), QTextControlPrivate::init(), QTextDocumentFragmentPrivate::QTextDocumentFragmentPrivate(), QWhatsThat::QWhatsThat(), QTextControlPrivate::setContent(), setMaximumBlockCount(), and QTextEdit::setUndoRedoEnabled().

548 {
550  d->enableUndoRedo(enable);
551 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ setUseDesignMetrics()

void QTextDocument::setUseDesignMetrics ( bool  b)

Definition at line 699 of file qtextdocument.cpp.

Referenced by QTextControl::print().

700 {
702  if (b == d->defaultTextOption.useDesignMetrics())
703  return;
704  d->defaultTextOption.setUseDesignMetrics(b);
705  if (d->lout)
706  d->lout->documentChanged(0, 0, d->length());
707 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ size()

QSizeF QTextDocument::size ( ) const

◆ textWidth()

qreal QTextDocument::textWidth ( ) const

Referenced by idealWidth(), and setTextWidth().

◆ toHtml()

QString QTextDocument::toHtml ( const QByteArray encoding = QByteArray()) const

Returns a string containing an HTML representation of the document.

The encoding parameter specifies the value for the charset attribute in the html header. For example if 'utf-8' is specified then the beginning of the generated html will look like this:

<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body>...

If no encoding is specified then no such meta information is generated.

If you later on convert the returned html string into a byte array for transmission over a network or when saving to disk you should specify the encoding you're going to use for the conversion to a byte array here.

See also
{Supported HTML Subset}

Definition at line 3210 of file qtextdocument.cpp.

Referenced by QTextEdit::toHtml(), and QTextDocumentWriter::write().

3211 {
3212  return QTextHtmlExporter(this).toHtml(encoding);
3213 }
QString toHtml(const QByteArray &encoding, ExportMode mode=ExportEntireDocument)
Returns the document in HTML format.

◆ toPlainText()

QString QTextDocument::toPlainText ( ) const

Returns the plain text contained in the document.

If you want formatting information use a QTextCursor instead.

See also
toHtml()

Definition at line 1277 of file qtextdocument.cpp.

Referenced by handleStringAttribute(), QAccessibleDisplay::text(), QTextDocumentFragment::toPlainText(), QTextEdit::toPlainText(), and QTextDocumentWriter::write().

1278 {
1279  Q_D(const QTextDocument);
1280  QString txt = d->plainText();
1281 
1282  QChar *uc = txt.data();
1283  QChar *e = uc + txt.size();
1284 
1285  for (; uc != e; ++uc) {
1286  switch (uc->unicode()) {
1287  case 0xfdd0: // QTextBeginningOfFrame
1288  case 0xfdd1: // QTextEndOfFrame
1290  case QChar::LineSeparator:
1291  *uc = QLatin1Char('\n');
1292  break;
1293  case QChar::Nbsp:
1294  *uc = QLatin1Char(' ');
1295  break;
1296  default:
1297  ;
1298  }
1299  }
1300  return txt;
1301 }
double d
Definition: qnumeric_p.h:62
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
QChar * data()
Returns a pointer to the data stored in the QString.
Definition: qstring.h:710
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ undo() [1/2]

void QTextDocument::undo ( QTextCursor cursor)

Undoes the last editing operation on the document if undo is available.

Since
4.2

The provided cursor is positioned at the end of the location where the edition operation was undone.

See the Overview of Qt's Undo Framework documentation for details.

See also
undoAvailable(), isUndoRedoEnabled()

Definition at line 441 of file qtextdocument.cpp.

442 {
444  const int pos = d->undoRedo(true);
445  if (cursor && pos >= 0) {
446  *cursor = QTextCursor(this);
447  cursor->setPosition(pos);
448  }
449 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
void setPosition(int pos, MoveMode mode=MoveAnchor)
Moves the cursor to the absolute position in the document specified by pos using a MoveMode specified...
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ undo [2/2]

void QTextDocument::undo ( )
slot

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 503 of file qtextdocument.cpp.

504 {
506  d->undoRedo(true);
507 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...

◆ undoAvailable

QTextDocument::undoAvailable ( bool  available)
signal

This signal is emitted whenever undo operations become available (available is true) or unavailable (available is false).

See the Overview of Qt's Undo Framework documentation for details.

See also
undo(), isUndoRedoEnabled()

◆ undoCommandAdded

QTextDocument::undoCommandAdded ( )
signal

This signal is emitted every time a new level of undo is added to the QTextDocument.

Since
4.4

Referenced by QTextDocumentPrivate::appendUndoItem(), and QTextDocumentPrivate::endEditBlock().

◆ useDesignMetrics()

bool QTextDocument::useDesignMetrics ( ) const

Referenced by setUseDesignMetrics().

Friends and Related Functions

◆ QTextObjectPrivate

friend class QTextObjectPrivate
friend

Definition at line 303 of file qtextdocument.h.

Properties

◆ blockCount

int QTextDocument::blockCount
private

Returns the number of text blocks in the document.

Since
4.2

The value of this property is undefined in documents with tables or frames.

By default, if defined, this property contains a value of 1.

See also
lineCount(), characterCount()

Definition at line 120 of file qtextdocument.h.

Referenced by QPlainTextEditPrivate::append(), QPlainTextEdit::blockBoundingRect(), QAccessibleTextEdit::childCount(), and QPlainTextDocumentLayout::documentChanged().

◆ defaultFont

QFont QTextDocument::defaultFont
private

the default font used to display the document's text

Returns the default font to be used in the document layout.

Definition at line 116 of file qtextdocument.h.

Referenced by QGraphicsTextItem::font(), QTextControl::print(), printPage(), and QTextHtmlExporter::QTextHtmlExporter().

◆ defaultStyleSheet

QString QTextDocument::defaultStyleSheet
private

The default style sheet is applied to all newly HTML formatted text that is inserted into the document, for example using setHtml() or QTextCursor::insertHtml().

Since
4.2

The style sheet needs to be compliant to CSS 2.1 syntax.

Note: Changing the default style sheet does not have any effect to the existing content of the document.

See also
{Supported HTML Subset}

Definition at line 123 of file qtextdocument.h.

◆ documentMargin

qreal QTextDocument::documentMargin
private

◆ indentWidth

qreal QTextDocument::indentWidth
private

Returns the width used for text list and text block indenting.

Since
4.4

The indent properties of QTextListFormat and QTextBlockFormat specify multiples of this value. The default indent width is 40.

Definition at line 121 of file qtextdocument.h.

Referenced by QTextDocumentLayoutPrivate::blockIndent().

◆ maximumBlockCount

int QTextDocument::maximumBlockCount
private

Specifies the limit for blocks in the document.

Since
4.2

Specifies the maximum number of blocks the document may have. If there are more blocks in the document that specified with this property blocks are removed from the beginning of the document.

A negative or zero value specifies that the document may contain an unlimited amount of blocks.

The default value is 0.

Note that setting this property will apply the limit immediately to the document contents.

Setting this property also disables the undo redo history.

This property is undefined in documents with tables or frames.

Definition at line 125 of file qtextdocument.h.

Referenced by QPlainTextEditPrivate::append().

◆ modified

QTextDocument::modified
private

whether the document has been modified by the user

By default, this property is false.

See also
modificationChanged()

Definition at line 114 of file qtextdocument.h.

◆ pageSize

QSizeF QTextDocument::pageSize
private

◆ size

QSizeF QTextDocument::size
private

Returns the actual size of the document.

Since
4.2

This is equivalent to documentLayout()->documentSize();

The size of the document can be changed either by setting a text width or setting an entire page size.

Note that the width is always >= pageSize().width().

By default, for a newly-created, empty document, this property contains a configuration-dependent size.

See also
setTextWidth(), setPageSize(), idealWidth()

Definition at line 118 of file qtextdocument.h.

Referenced by QStaticTextPrivate::paintText(), and QWhatsThat::QWhatsThat().

◆ textWidth

qreal QTextDocument::textWidth
private

The text width specifies the preferred width for text in the document.

Since
4.2

If the text (or content in general) is wider than the specified with it is broken into multiple lines and grows vertically. If the text cannot be broken into multiple lines to fit into the specified text width it will be larger and the size() and the idealWidth() property will reflect that.

If the text width is set to -1 then the text will not be broken into multiple lines unless it is enforced through an explicit line break or a new paragraph.

The default value is -1.

Setting the text width will also set the page height to -1, causing the document to grow or shrink vertically in a continuous way. If you want the document layout to break the text into multiple pages then you have to set the pageSize property instead.

See also
size(), idealWidth(), pageSize()

Definition at line 119 of file qtextdocument.h.

◆ undoRedoEnabled

QTextDocument::undoRedoEnabled
private

whether undo/redo are enabled for this document

This defaults to true. If disabled, the undo stack is cleared and no items will be added to it.

Definition at line 113 of file qtextdocument.h.

◆ useDesignMetrics

bool QTextDocument::useDesignMetrics
private

whether the document uses design metrics of fonts to improve the accuracy of text layout

Since
4.1

If this property is set to true, the layout will use design metrics. Otherwise, the metrics of the paint device as set on QAbstractTextDocumentLayout::setPaintDevice() will be used.

Using design metrics makes a layout have a width that is no longer dependent on hinting and pixel-rounding. This means that WYSIWYG text layout becomes possible because the width scales much more linearly based on paintdevice metrics than it would otherwise.

By default, this property is false.

Definition at line 117 of file qtextdocument.h.

Referenced by QTextControl::print().


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