QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
QgsTextBlockFormat Class Reference

Stores information relating to individual block formatting. More...

#include <qgstextblockformat.h>

Public Types

enum class  BooleanValue { NotSet , SetTrue , SetFalse }
 Status values for boolean format properties. More...
 

Public Member Functions

 QgsTextBlockFormat ()=default
 
 QgsTextBlockFormat (const QTextBlockFormat &format)
 Constructor for QgsTextBlockFormat, based on the specified QTextBlockFormat format.
 
QBrush backgroundBrush () const
 Returns the brush used for rendering the background of the block.
 
QString backgroundImagePath () const
 Returns the path for the image to be used for rendering the background of the fragment.
 
bool hasBackground () const
 Returns true if the block has a background set.
 
bool hasHorizontalAlignmentSet () const
 Returns true if the format has an explicit horizontal alignment set.
 
Qgis::TextHorizontalAlignment horizontalAlignment () const
 Returns the format horizontal alignment.
 
double lineHeight () const
 Returns the line height in points, or NaN if the line height is not set and should be auto calculated.
 
double lineHeightPercentage () const
 Returns the line height percentage size (as fraction of font size from 0.0 to 1.0), or NaN if the line height percentage is not set.
 
QgsMargins margins () const
 Returns the block margins, in points.
 
void overrideWith (const QgsTextBlockFormat &other)
 Override all the default/unset properties of the current block format with the settings from another format.
 
void setBackgroundBrush (const QBrush &brush)
 Sets the brush used for rendering the background of the block.
 
void setBackgroundImagePath (const QString &path)
 Sets the path for the image to be used for rendering the background of the fragment.
 
void setHasHorizontalAlignmentSet (bool set)
 Sets whether the format has an explicit horizontal alignment set.
 
void setHorizontalAlignment (Qgis::TextHorizontalAlignment alignment)
 Sets the format horizontal alignment.
 
void setLineHeight (double height)
 Sets the font line height, in points.
 
void setLineHeightPercentage (double height)
 Sets the line height percentage height (as fraction of font size from 0.0 to 1.0).
 
void setMargins (const QgsMargins &margins)
 Sets the block margins, in points.
 
void updateFontForFormat (QFont &font, const QgsRenderContext &context, double scaleFactor=1.0) const
 Updates the specified font in place, applying block formatting options which are applicable on a font level when rendered in the given context.
 

Detailed Description

Stores information relating to individual block formatting.

These options encapsulate formatting options which override the default settings from a QgsTextFormat for individual text blocks.

Warning
This API is not considered stable and may change in future QGIS versions.
Since
QGIS 3.40

Definition at line 43 of file qgstextblockformat.h.

Member Enumeration Documentation

◆ BooleanValue

Status values for boolean format properties.

Enumerator
NotSet 

Property is not set.

SetTrue 

Property is set and true.

SetFalse 

Property is set and false.

Definition at line 55 of file qgstextblockformat.h.

Constructor & Destructor Documentation

◆ QgsTextBlockFormat() [1/2]

QgsTextBlockFormat::QgsTextBlockFormat ( )
default

◆ QgsTextBlockFormat() [2/2]

QgsTextBlockFormat::QgsTextBlockFormat ( const QTextBlockFormat &  format)

Constructor for QgsTextBlockFormat, based on the specified QTextBlockFormat format.

Definition at line 46 of file qgstextblockformat.cpp.

Member Function Documentation

◆ backgroundBrush()

QBrush QgsTextBlockFormat::backgroundBrush ( ) const

Returns the brush used for rendering the background of the block.

Alternatively, the format may have a backgroundBrush() set.

See also
hasBackground()
setBackgroundBrush()
Since
QGIS 3.42

Definition at line 114 of file qgstextblockformat.cpp.

◆ backgroundImagePath()

QString QgsTextBlockFormat::backgroundImagePath ( ) const

Returns the path for the image to be used for rendering the background of the fragment.

Alternatively, the format may have a backgroundBrush() set.

See also
hasBackground()
setBackgroundImagePath()
Since
QGIS 3.42

Definition at line 124 of file qgstextblockformat.cpp.

◆ hasBackground()

bool QgsTextBlockFormat::hasBackground ( ) const

Returns true if the block has a background set.

See also
backgroundBrush()
Since
QGIS 3.42

Definition at line 109 of file qgstextblockformat.cpp.

◆ hasHorizontalAlignmentSet()

bool QgsTextBlockFormat::hasHorizontalAlignmentSet ( ) const
inline

Returns true if the format has an explicit horizontal alignment set.

If false is returned then the horizontal alignment will be inherited.

See also
setHasHorizontalAlignmentSet()
horizontalAlignment()

Definition at line 83 of file qgstextblockformat.h.

◆ horizontalAlignment()

Qgis::TextHorizontalAlignment QgsTextBlockFormat::horizontalAlignment ( ) const
inline

Returns the format horizontal alignment.

This property is only respected if hasHorizontalAlignmentSet() is true.

See also
hasHorizontalAlignmentSet()
setHorizontalAlignment()

Definition at line 103 of file qgstextblockformat.h.

◆ lineHeight()

double QgsTextBlockFormat::lineHeight ( ) const

Returns the line height in points, or NaN if the line height is not set and should be auto calculated.

Note
A format should have either lineHeight() or lineHeightPercentage() set, not both.
See also
lineHeightPercentage()
setLineHeight()
Since
QGIS 3.42

Definition at line 84 of file qgstextblockformat.cpp.

◆ lineHeightPercentage()

double QgsTextBlockFormat::lineHeightPercentage ( ) const

Returns the line height percentage size (as fraction of font size from 0.0 to 1.0), or NaN if the line height percentage is not set.

Note
A format should have either lineHeight() or lineHeightPercentage() set, not both.
See also
lineHeight()
setLineHeightPercentage()
Since
QGIS 3.42

Definition at line 94 of file qgstextblockformat.cpp.

◆ margins()

QgsMargins QgsTextBlockFormat::margins ( ) const
inline

Returns the block margins, in points.

See also
setMargins()
Since
QGIS 3.42

Definition at line 175 of file qgstextblockformat.h.

◆ overrideWith()

void QgsTextBlockFormat::overrideWith ( const QgsTextBlockFormat other)

Override all the default/unset properties of the current block format with the settings from another format.

This will replace any default/unset existing settings with the settings from other.

Any settings which are default/unset in other will be left unchanged.

Parameters
otherThe format to override with.

Definition at line 61 of file qgstextblockformat.cpp.

◆ setBackgroundBrush()

void QgsTextBlockFormat::setBackgroundBrush ( const QBrush &  brush)

Sets the brush used for rendering the background of the block.

Alternatively, the format may have a backgroundBrush() set.

See also
backgroundBrush()
Since
QGIS 3.42

Definition at line 119 of file qgstextblockformat.cpp.

◆ setBackgroundImagePath()

void QgsTextBlockFormat::setBackgroundImagePath ( const QString &  path)

Sets the path for the image to be used for rendering the background of the fragment.

Alternatively, the format may have a backgroundBrush() set.

See also
backgroundImagePath()
Since
QGIS 3.42

Definition at line 129 of file qgstextblockformat.cpp.

◆ setHasHorizontalAlignmentSet()

void QgsTextBlockFormat::setHasHorizontalAlignmentSet ( bool  set)
inline

Sets whether the format has an explicit horizontal alignment set.

If set is false then the horizontal alignment will be inherited.

See also
hasHorizontalAlignmentSet()
setHorizontalAlignment()

Definition at line 93 of file qgstextblockformat.h.

◆ setHorizontalAlignment()

void QgsTextBlockFormat::setHorizontalAlignment ( Qgis::TextHorizontalAlignment  alignment)
inline

Sets the format horizontal alignment.

This property is only respected if hasHorizontalAlignmentSet() is true.

See also
hasHorizontalAlignmentSet()
horizontalAlignment()

Definition at line 113 of file qgstextblockformat.h.

◆ setLineHeight()

void QgsTextBlockFormat::setLineHeight ( double  height)

Sets the font line height, in points.

Set height to NaN if the line height is not set and should be auto calculated.

Note
A format should have either lineHeight() or lineHeightPercentage() set, not both.
See also
lineHeight()
setLineHeightPercentage()
Since
QGIS 3.42

Definition at line 89 of file qgstextblockformat.cpp.

◆ setLineHeightPercentage()

void QgsTextBlockFormat::setLineHeightPercentage ( double  height)

Sets the line height percentage height (as fraction of font size from 0.0 to 1.0).

Set height to NaN if the line height percentange is not set.

Note
A format should have either lineHeight() or lineHeightPercentage() set, not both.
See also
lineHeightPercentage()
setLineHeight()
Since
QGIS 3.42

Definition at line 99 of file qgstextblockformat.cpp.

◆ setMargins()

void QgsTextBlockFormat::setMargins ( const QgsMargins margins)
inline

Sets the block margins, in points.

See also
margins()
Since
QGIS 3.42

Definition at line 183 of file qgstextblockformat.h.

◆ updateFontForFormat()

void QgsTextBlockFormat::updateFontForFormat ( QFont &  font,
const QgsRenderContext context,
double  scaleFactor = 1.0 
) const

Updates the specified font in place, applying block formatting options which are applicable on a font level when rendered in the given context.

The optional scaleFactor parameter can specify a font size scaling factor. It is recommended to set this to QgsTextRenderer::calculateScaleFactorForFormat() and then manually calculations based on the resultant font metrics. Failure to do so will result in poor quality text rendering at small font sizes.

Definition at line 104 of file qgstextblockformat.cpp.


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