QGIS API Documentation 3.41.0-Master (af5edcb665c)
|
Utilities for layouts. More...
#include <qgslayoututils.h>
Static Public Member Functions | |
static double | calculatePrettySize (double minimumSize, double maximumSize) |
Calculates a "pretty" size which falls between the range [minimumSize, maximumSize]. | |
static QgsRenderContext | createRenderContextForLayout (QgsLayout *layout, QPainter *painter, double dpi=-1) |
Creates a render context suitable for the specified layout and painter destination. | |
static QgsRenderContext | createRenderContextForMap (QgsLayoutItemMap *map, QPainter *painter, double dpi=-1) |
Creates a render context suitable for the specified layout map and painter destination. | |
static QgsLayoutItemPage::Orientation | decodePaperOrientation (const QString &string, bool &ok) |
Decodes a string representing a paper orientation and returns the decoded orientation. | |
static void | drawText (QPainter *painter, const QRectF &rectangle, const QString &text, const QFont &font, const QColor &color=QColor(), Qt::AlignmentFlag halignment=Qt::AlignLeft, Qt::AlignmentFlag valignment=Qt::AlignTop, int flags=Qt::TextWordWrap) |
Draws text on a painter within a rectangle, taking care of layout specific issues (calculation to pixel, scaling of font and painter to work around Qt font bugs). | |
static void | drawText (QPainter *painter, QPointF position, const QString &text, const QFont &font, const QColor &color=QColor()) |
Draws text on a painter at a specific position, taking care of layout specific issues (calculation to pixel, scaling of font and painter to work around Qt font bugs). | |
static double | fontAscentMM (const QFont &font) |
Calculates a font ascent in millimeters, including workarounds for QT font rendering issues. | |
static double | fontDescentMM (const QFont &font) |
Calculate a font descent in millimeters, including workarounds for QT font rendering issues. | |
static double | fontHeightCharacterMM (const QFont &font, QChar character) |
Calculate a font height in millimeters of a single character, including workarounds for QT font rendering issues. | |
static double | fontHeightMM (const QFont &font) |
Calculate a font height in millimeters, including workarounds for QT font rendering issues. | |
static bool | itemIsAClippingSource (const QgsLayoutItem *item) |
Returns true if an item is a clipping item for another layout item. | |
static QRectF | largestRotatedRectWithinBounds (const QRectF &originalRect, const QRectF &boundsRect, double rotation) |
Calculates the largest scaled version of originalRect which fits within boundsRect, when it is rotated by the a specified rotation amount. | |
static QgsMapLayer * | mapLayerFromString (const QString &string, QgsProject *project) |
Resolves a string into a map layer from a given project. | |
static double | normalizedAngle (double angle, bool allowNegative=false) |
Ensures that an angle (in degrees) is in the range 0 <= angle < 360. | |
static QVector< double > | predefinedScales (const QgsLayout *layout) |
Returns a list of predefined scales associated with a layout. | |
static double | relativePosition (double position, double beforeMin, double beforeMax, double afterMin, double afterMax) |
Returns a scaled position given a before and after range. | |
static void | relativeResizeRect (QRectF &rectToResize, const QRectF &boundsBefore, const QRectF &boundsAfter) |
Resizes a QRectF relative to a resized bounding rectangle. | |
static void | rotate (double angle, double &x, double &y) |
Rotates a point / vector around the origin. | |
static QFont | scaledFontPixelSize (const QFont &font) |
Returns a font where size is set in points and the size has been upscaled with FONT_WORKAROUND_SCALE to workaround QT font rendering bugs. | |
static Q_DECL_DEPRECATED double | scaleFactorFromItemStyle (const QStyleOptionGraphicsItem *style) |
Extracts the scale factor from an item style. | |
static double | scaleFactorFromItemStyle (const QStyleOptionGraphicsItem *style, QPainter *painter) |
Extracts the scale factor from an item style and painter. | |
static double | snappedAngle (double angle) |
Snaps an angle (in degrees) to its closest 45 degree angle. | |
static double | textHeightMM (const QFont &font, const QString &text, double multiLineHeight=1.0) |
Calculate a font height in millimeters for a text string, including workarounds for QT font rendering issues. | |
static double | textWidthMM (const QFont &font, const QString &text) |
Calculate a font width in millimeters for a text string, including workarounds for QT font rendering issues. | |
Friends | |
class | TestQgsLayoutUtils |
Utilities for layouts.
Definition at line 36 of file qgslayoututils.h.
|
static |
Calculates a "pretty" size which falls between the range [minimumSize, maximumSize].
This method will return an optimal round number which falls within the given range, finding the largest "pretty" number possible.
Definition at line 468 of file qgslayoututils.cpp.
|
static |
Creates a render context suitable for the specified layout and painter destination.
This method returns a new QgsRenderContext which matches the scale and settings from the layout's QgsLayout::referenceMap(). If the dpi argument is not specified then the dpi will be taken from the destination painter device.
Definition at line 143 of file qgslayoututils.cpp.
|
static |
Creates a render context suitable for the specified layout map and painter destination.
This method returns a new QgsRenderContext which matches the scale and settings of the target map. If the dpi argument is not specified then the dpi will be taken from the destination painter device.
Definition at line 99 of file qgslayoututils.cpp.
|
static |
Decodes a string representing a paper orientation and returns the decoded orientation.
If the string was correctly decoded, ok will be set to true
.
Definition at line 392 of file qgslayoututils.cpp.
|
static |
Draws text on a painter within a rectangle, taking care of layout specific issues (calculation to pixel, scaling of font and painter to work around Qt font bugs).
If color is specified, text will be rendered in that color. If not specified, the current painter pen color will be used instead.
The text alignment within rectangle can be set via the halignment and valignment arguments.
The flags parameter allows for passing Qt::TextFlags to control appearance of rendered text.
Definition at line 287 of file qgslayoututils.cpp.
|
static |
Draws text on a painter at a specific position, taking care of layout specific issues (calculation to pixel, scaling of font and painter to work around Qt font bugs).
If color is specified, text will be rendered in that color. If not specified, the current painter pen color will be used instead.
Definition at line 265 of file qgslayoututils.cpp.
|
static |
Calculates a font ascent in millimeters, including workarounds for QT font rendering issues.
Definition at line 194 of file qgslayoututils.cpp.
|
static |
Calculate a font descent in millimeters, including workarounds for QT font rendering issues.
Definition at line 203 of file qgslayoututils.cpp.
|
static |
Calculate a font height in millimeters of a single character, including workarounds for QT font rendering issues.
Definition at line 223 of file qgslayoututils.cpp.
|
static |
Calculate a font height in millimeters, including workarounds for QT font rendering issues.
The font height is the font ascent + descent + 1 (for the baseline).
Definition at line 213 of file qgslayoututils.cpp.
|
static |
Returns true
if an item is a clipping item for another layout item.
Definition at line 496 of file qgslayoututils.cpp.
|
static |
Calculates the largest scaled version of originalRect which fits within boundsRect, when it is rotated by the a specified rotation amount.
originalRect | QRectF to be rotated and scaled |
boundsRect | QRectF specifying the bounds which the rotated and scaled rectangle must fit within |
rotation | the rotation in degrees to be applied to the rectangle |
Definition at line 312 of file qgslayoututils.cpp.
|
static |
Resolves a string into a map layer from a given project.
Attempts different forms of layer matching such as matching by layer id or layer name.
Layer names are matched using a case-insensitive check, ONLY if an exact case match was not found.
Definition at line 433 of file qgslayoututils.cpp.
|
static |
Ensures that an angle (in degrees) is in the range 0 <= angle < 360.
If allowNegative is true
then angles between (-360, 360) are allowed. If false
, angles are converted to positive angles in the range [0, 360).
Definition at line 45 of file qgslayoututils.cpp.
|
static |
Returns a list of predefined scales associated with a layout.
Definition at line 524 of file qgslayoututils.cpp.
|
static |
Returns a scaled position given a before and after range.
position | initial position within before range to scale |
beforeMin | minimum value in before range |
beforeMax | maximum value in before range |
afterMin | minimum value in after range |
afterMax | maximum value in after range |
Definition at line 175 of file qgslayoututils.cpp.
|
static |
Resizes a QRectF relative to a resized bounding rectangle.
rectToResize | QRectF to resize, contained within boundsBefore. The rectangle is linearly scaled to retain its relative position and size within boundsAfter. |
boundsBefore | QRectF of bounds before resize |
boundsAfter | QRectF of bounds after resize |
Definition at line 156 of file qgslayoututils.cpp.
|
static |
Rotates a point / vector around the origin.
angle | rotation angle in degrees, counterclockwise |
x | in/out: x coordinate before / after the rotation |
y | in/out: y coordinate before / after the rotation |
Definition at line 35 of file qgslayoututils.cpp.
|
static |
Returns a font where size is set in points and the size has been upscaled with FONT_WORKAROUND_SCALE to workaround QT font rendering bugs.
Returns a font with size set in pixels.
Definition at line 184 of file qgslayoututils.cpp.
|
static |
Extracts the scale factor from an item style.
Definition at line 409 of file qgslayoututils.cpp.
|
static |
Extracts the scale factor from an item style and painter.
Definition at line 427 of file qgslayoututils.cpp.
|
static |
Snaps an angle (in degrees) to its closest 45 degree angle.
Definition at line 59 of file qgslayoututils.cpp.
|
static |
Calculate a font height in millimeters for a text string, including workarounds for QT font rendering issues.
Note that this method uses a non-standard measure of text height, where only the font ascent is considered for the first line of text.
The multiLineHeight parameter specifies the line spacing factor.
Definition at line 249 of file qgslayoututils.cpp.
|
static |
Calculate a font width in millimeters for a text string, including workarounds for QT font rendering issues.
Definition at line 232 of file qgslayoututils.cpp.
|
friend |
Definition at line 274 of file qgslayoututils.h.