Class: QgsTextDocument¶
Represents a document consisting of one or more QgsTextBlock
objects.
Warning
This API is not considered stable and may change in future QGIS versions.
Added in version 3.14.
Methods
Appends a block to the document. |
|
Applies a capitalization style to the document's text. |
|
Returns the block at the specified index. |
|
Returns |
|
Inserts a block into the document, at the specified index. |
|
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. |
Static Methods
Constructor for |
|
Constructor for |
|
Constructor for |
- class qgis.core.QgsTextDocument[source]¶
Bases:
object
- __init__()
- __init__(block: QgsTextBlock)
Constructor for a QgsTextDocument consisting of a single text
block
.- Parameters:
block (QgsTextBlock)
- __init__(fragment: QgsTextFragment)
Constructor for a QgsTextDocument consisting of a single text
fragment
.- Parameters:
fragment (QgsTextFragment)
- __init__(a0: QgsTextDocument)
- Parameters:
a0 (QgsTextDocument)
- append(self, block: QgsTextBlock)[source]¶
Appends a
block
to the document.- Parameters:
block (QgsTextBlock)
- applyCapitalization(self, capitalization: Qgis.Capitalization)[source]¶
Applies a
capitalization
style to the document’s text.Added 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:
- static fromHtml(lines: Iterable[str | None]) QgsTextDocument [source]¶
Constructor for
QgsTextDocument
consisting of a set of HTML formattedlines
.If the HTML contains tab characters they will be appended as separate text fragments within the document, consisting of just the tab character.
- Parameters:
lines (Iterable[Optional[str]])
- Return type:
- static fromPlainText(lines: Iterable[str | None]) QgsTextDocument [source]¶
Constructor for
QgsTextDocument
consisting of a set of plain textlines
.If any line contains tab characters they will be appended as separate text fragments within the document, consisting of just the tab character.
- Parameters:
lines (Iterable[Optional[str]])
- Return type:
- static fromTextAndFormat(lines: Iterable[str | None], format: QgsTextFormat) QgsTextDocument [source]¶
Constructor for
QgsTextDocument
consisting of a set oflines
, respecting settings from a textformat
.This method will determine from the text
format
whether the lines should be treated as HTML or plain text.Added in version 3.40.
- Parameters:
lines (Iterable[Optional[str]])
format (QgsTextFormat)
- Return type:
- hasBackgrounds(self) bool [source]¶
Returns
True
if any blocks or fragments in the document have background brushes set.Added in version 3.42.
- Return type:
bool
- insert(self, index: int, block: QgsTextBlock)[source]¶
Inserts a
block
into the document, at the specified index.- Raises:
IndexError – if no block exists at the specified index.
Added in version 3.40.
- Parameters:
index (int)
block (QgsTextBlock)
- reserve(self, count: int)[source]¶
Reserves the specified
count
of blocks for optimised block appending.- Parameters:
count (int)
- splitLines(self, wrapCharacter: str | None, autoWrapLength: int = 0, useMaxLineLengthWhenAutoWrapping: bool = True)[source]¶
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 (Optional[str])
autoWrapLength (int = 0)
useMaxLineLengthWhenAutoWrapping (bool = True)