Class: QgsTextDocument¶
- class qgis.core.QgsTextDocument¶
Bases:
sip.wrapper
Represents a document consisting of one or more
QgsTextBlock
objects.Warning
This API is not considered stable and may change in future QGIS versions.
New in version 3.14.
QgsTextDocument()
QgsTextDocument(block:
QgsTextBlock
) Constructor for aQgsTextDocument
consisting of a single textblock
.QgsTextDocument(fragment:
QgsTextFragment
) Constructor for aQgsTextDocument
consisting of a single textfragment
.QgsTextDocument(
QgsTextDocument
)Methods
Appends a
block
to the document.Applies a
capitalization
style to the document's text.Returns the block at the specified
index
.Constructor for
QgsTextDocument
consisting of a set of HTML formattedlines
.Constructor for
QgsTextDocument
consisting of a set of plain textlines
.Reserves the specified
count
of blocks for optimised block appending.Returns the number of blocks in the document.
Splits lines of text in the document to separate lines, using a specified wrap character (
wrapCharacter
) or newline characters.Returns a list of plain text lines of text representing the document.
- append(self, block: QgsTextBlock)¶
Appends a
block
to the document.- Parameters:
block (QgsTextBlock) –
- applyCapitalization(self, capitalization: Qgis.Capitalization)¶
Applies a
capitalization
style to the document’s text.New in version 3.16.
- Parameters:
capitalization (Qgis.Capitalization) –
- at(self, index: int) QgsTextBlock ¶
Returns the block at the specified
index
.- Raises:
KeyError – if no block exists at the specified index.
- Parameters:
index (int) –
- Return type:
- fromHtml(lines: Iterable[str]) QgsTextDocument ¶
Constructor for
QgsTextDocument
consisting of a set of HTML formattedlines
.- Parameters:
lines (Iterable[str]) –
- Return type:
- fromPlainText(lines: Iterable[str]) QgsTextDocument ¶
Constructor for
QgsTextDocument
consisting of a set of plain textlines
.- Parameters:
lines (Iterable[str]) –
- Return type:
- reserve(self, count: int)¶
Reserves the specified
count
of blocks for optimised block appending.- Parameters:
count (int) –
- size(self) int ¶
Returns the number of blocks in the document.
- Return type:
int
- splitLines(self, wrapCharacter: str, autoWrapLength: int = 0, useMaxLineLengthWhenAutoWrapping: bool = True)¶
Splits lines of text in the document to separate lines, using a specified wrap character (
wrapCharacter
) or newline characters.The
autoWrapLength
argument can be used to specify an ideal length of line to automatically wrap text to (automatic wrapping is disabled ifautoWrapLength
is 0). This automatic wrapping is performed after processing wrapping usingwrapCharacter
. When auto wrapping is enabled, theuseMaxLineLengthWhenAutoWrapping
argument controls whether the lines should be wrapped to an ideal maximum ofautoWrapLength
characters, or ifFalse
then the lines are wrapped to an ideal minimum length ofautoWrapLength
characters.- Parameters:
wrapCharacter (str) –
autoWrapLength (int = 0) –
useMaxLineLengthWhenAutoWrapping (bool = True) –
- toPlainText(self) List[str] ¶
Returns a list of plain text lines of text representing the document.
- Return type:
List[str]