QGIS API Documentation  2.99.0-Master (23ddace)
Static Public Member Functions | List of all members
QgsComposerUtils Class Reference

Utilities for compositions. More...

#include <qgscomposerutils.h>

Static Public Member Functions

static double angle (QPointF p1, QPointF p2)
 Calculates the angle of the line from p1 to p2 (counter clockwise, starting from a line from north to south) More...
 
static QgsRenderContext createRenderContextForComposition (QgsComposition *composition, QPainter *painter)
 Creates a render context suitable for the specified composition and painter destination. More...
 
static QgsRenderContext createRenderContextForMap (QgsComposerMap *map, QPainter *painter, double dpi=-1)
 Creates a render context suitable for the specified composer map and painter destination. More...
 
static QgsComposition::PaperOrientation decodePaperOrientation (const QString &orientationString, bool &ok)
 Decodes a string representing a paper orientation. More...
 
static bool decodePresetPaperSize (const QString &presetString, double &width, double &height)
 Decodes a string representing a preset page size. More...
 
static void drawArrowHead (QPainter *p, const double x, const double y, const double angle, const double arrowHeadWidth)
 Draws an arrow head on to a QPainter. More...
 
static void drawText (QPainter *painter, QPointF pos, const QString &text, const QFont &font, const QColor &color=QColor())
 Draws text on a painter at a specific position, taking care of composer specific issues (calculation to pixel, scaling of font and painter to work around Qt font bugs) More...
 
static void drawText (QPainter *painter, const QRectF &rect, const QString &text, const QFont &font, const QColor &color=QColor(), const Qt::AlignmentFlag halignment=Qt::AlignLeft, const Qt::AlignmentFlag valignment=Qt::AlignTop, const int flags=Qt::TextWordWrap)
 Draws text on a painter within a rectangle, taking care of composer specific issues (calculation to pixel, scaling of font and painter to work around Qt font bugs) More...
 
static double fontAscentMM (const QFont &font)
 Calculate font ascent in millimeters, including workarounds for QT font rendering issues. More...
 
static double fontDescentMM (const QFont &font)
 Calculate font descent in millimeters, including workarounds for QT font rendering issues. More...
 
static double fontHeightCharacterMM (const QFont &font, QChar character)
 Calculate font height in millimeters of a single character, including workarounds for QT font rendering issues. More...
 
static double fontHeightMM (const QFont &font)
 Calculate font height in millimeters, including workarounds for QT font rendering issues The font height is the font ascent + descent + 1 (for the baseline). More...
 
static QRectF largestRotatedRectWithinBounds (const QRectF &originalRect, const QRectF &boundsRect, const double rotation)
 Calculates the largest scaled version of originalRect which fits within boundsRect, when it is rotated by a specified amount. More...
 
static double mmToPoints (const double mmSize)
 Returns the size in mm corresponding to a font point size. More...
 
static double normalizedAngle (const double angle)
 Ensures that an angle is in the range 0 <= angle < 360. More...
 
static double pointsToMM (const double pointSize)
 Returns the size in mm corresponding to a font point size. More...
 
static QgsProperty readOldDataDefinedProperty (const QgsComposerObject::DataDefinedProperty property, const QDomElement &ddElem)
 Reads a pre 3.0 data defined property from an XML DOM element. More...
 
static void readOldDataDefinedPropertyMap (const QDomElement &itemElem, QgsPropertyCollection &dataDefinedProperties)
 Reads all pre 3.0 data defined properties from an XML element. More...
 
static double relativePosition (const double position, const double beforeMin, const double beforeMax, const double afterMin, const double afterMax)
 Returns a scaled position given a before and after range. More...
 
static void relativeResizeRect (QRectF &rectToResize, const QRectF &boundsBefore, const QRectF &boundsAfter)
 Resizes a QRectF relative to a resized bounding rectangle. More...
 
static void rotate (const double angle, double &x, double &y)
 Rotates a point / vector around the origin. More...
 
static QFont scaledFontPixelSize (const QFont &font)
 Returns a font where size is set in pixels and the size has been upscaled with FONT_WORKAROUND_SCALE to workaround QT font rendering bugs. More...
 
static double snappedAngle (const double angle)
 Snaps an angle to its closest 45 degree angle. More...
 
static double textHeightMM (const QFont &font, const QString &text, double multiLineHeight=1.0)
 Calculate font height in millimeters for a string, including workarounds for QT font rendering issues. More...
 
static double textWidthMM (const QFont &font, const QString &text)
 Calculate font width in millimeters for a string, including workarounds for QT font rendering issues. More...
 

Detailed Description

Utilities for compositions.

Definition at line 31 of file qgscomposerutils.h.

Member Function Documentation

◆ angle()

double QgsComposerUtils::angle ( QPointF  p1,
QPointF  p2 
)
static

Calculates the angle of the line from p1 to p2 (counter clockwise, starting from a line from north to south)

Parameters
p1start point of line
p2end point of line
Returns
angle in degrees, clockwise from south

Definition at line 69 of file qgscomposerutils.cpp.

◆ createRenderContextForComposition()

QgsRenderContext QgsComposerUtils::createRenderContextForComposition ( QgsComposition composition,
QPainter *  painter 
)
static

Creates a render context suitable for the specified composition and painter destination.

This method returns a new QgsRenderContext which matches the scale and settings from the composition's QgsComposition::referenceMap().

Since
QGIS 3.0
See also
createRenderContextForMap()

Definition at line 529 of file qgscomposerutils.cpp.

◆ createRenderContextForMap()

QgsRenderContext QgsComposerUtils::createRenderContextForMap ( QgsComposerMap map,
QPainter *  painter,
double  dpi = -1 
)
static

Creates a render context suitable for the specified composer 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 destinatation painter device.

Since
QGIS 3.0
See also
createRenderContextForComposition()

Definition at line 490 of file qgscomposerutils.cpp.

◆ decodePaperOrientation()

QgsComposition::PaperOrientation QgsComposerUtils::decodePaperOrientation ( const QString &  orientationString,
bool &  ok 
)
static

Decodes a string representing a paper orientation.

Parameters
orientationStringstring to decode
okwill be true if string could be decoded
Returns
decoded paper orientation

Definition at line 264 of file qgscomposerutils.cpp.

◆ decodePresetPaperSize()

bool QgsComposerUtils::decodePresetPaperSize ( const QString &  presetString,
double &  width,
double &  height 
)
static

Decodes a string representing a preset page size.

Parameters
presetStringstring to decode
widthdouble for decoded paper width
heightdouble for decoded paper height
Returns
true if string could be decoded successfully

Definition at line 280 of file qgscomposerutils.cpp.

◆ drawArrowHead()

void QgsComposerUtils::drawArrowHead ( QPainter *  p,
const double  x,
const double  y,
const double  angle,
const double  arrowHeadWidth 
)
static

Draws an arrow head on to a QPainter.

Parameters
pdestination painter
xx-coordinate of arrow center
yy-coordinate of arrow center
angleangle in degrees which arrow should point toward, measured clockwise from pointing vertical upward
arrowHeadWidthsize of arrow head

Definition at line 31 of file qgscomposerutils.cpp.

◆ drawText() [1/2]

void QgsComposerUtils::drawText ( QPainter *  painter,
QPointF  pos,
const QString &  text,
const QFont &  font,
const QColor &  color = QColor() 
)
static

Draws text on a painter at a specific position, taking care of composer specific issues (calculation to pixel, scaling of font and painter to work around Qt font bugs)

Parameters
painterdestination QPainter
posposition to draw text
textstring to draw
fontfont to use for drawing text
colorcolor to draw text
Since
QGIS 2.5

Definition at line 441 of file qgscomposerutils.cpp.

◆ drawText() [2/2]

void QgsComposerUtils::drawText ( QPainter *  painter,
const QRectF &  rect,
const QString &  text,
const QFont &  font,
const QColor &  color = QColor(),
const Qt::AlignmentFlag  halignment = Qt::AlignLeft,
const Qt::AlignmentFlag  valignment = Qt::AlignTop,
const int  flags = Qt::TextWordWrap 
)
static

Draws text on a painter within a rectangle, taking care of composer specific issues (calculation to pixel, scaling of font and painter to work around Qt font bugs)

Parameters
painterdestination QPainter
rectrectangle to draw into
textstring to draw
fontfont to use for drawing text
colorcolor to draw text
halignmentoptional horizontal alignment
valignmentoptional vertical alignment
flagsallows for passing Qt::TextFlags to control appearance of rendered text
Since
QGIS 2.5

Definition at line 464 of file qgscomposerutils.cpp.

◆ fontAscentMM()

double QgsComposerUtils::fontAscentMM ( const QFont &  font)
static

Calculate font ascent in millimeters, including workarounds for QT font rendering issues.

Parameters
fontinput font
Returns
font ascent in millimeters
Since
QGIS 2.5
See also
fontDescentMM
fontHeightMM
fontHeightCharacterMM
textWidthMM

Definition at line 380 of file qgscomposerutils.cpp.

◆ fontDescentMM()

double QgsComposerUtils::fontDescentMM ( const QFont &  font)
static

Calculate font descent in millimeters, including workarounds for QT font rendering issues.

Parameters
fontinput font
Returns
font descent in millimeters
Since
QGIS 2.5
See also
fontAscentMM
fontHeightMM
fontHeightCharacterMM
textWidthMM

Definition at line 389 of file qgscomposerutils.cpp.

◆ fontHeightCharacterMM()

double QgsComposerUtils::fontHeightCharacterMM ( const QFont &  font,
QChar  character 
)
static

Calculate font height in millimeters of a single character, including workarounds for QT font rendering issues.

Parameters
fontinput font
charactercharacter to calculate height for
Returns
character height in millimeters
Since
QGIS 2.5
See also
fontAscentMM
fontDescentMM
fontHeightMM
textWidthMM

Definition at line 407 of file qgscomposerutils.cpp.

◆ fontHeightMM()

double QgsComposerUtils::fontHeightMM ( const QFont &  font)
static

Calculate font height in millimeters, including workarounds for QT font rendering issues The font height is the font ascent + descent + 1 (for the baseline).

Parameters
fontinput font
Returns
font height in millimeters
Since
QGIS 2.5
See also
fontAscentMM
fontDescentMM
fontHeightCharacterMM
textWidthMM

Definition at line 398 of file qgscomposerutils.cpp.

◆ largestRotatedRectWithinBounds()

QRectF QgsComposerUtils::largestRotatedRectWithinBounds ( const QRectF &  originalRect,
const QRectF &  boundsRect,
const double  rotation 
)
static

Calculates the largest scaled version of originalRect which fits within boundsRect, when it is rotated by a specified amount.

Parameters
originalRectQRectF to be rotated and scaled
boundsRectQRectF specifying the bounds which the rotated and scaled rectangle must fit within
rotationthe rotation in degrees to be applied to the rectangle
Returns
largest scaled version of the rectangle possible

Definition at line 151 of file qgscomposerutils.cpp.

◆ mmToPoints()

double QgsComposerUtils::mmToPoints ( const double  mmSize)
static

Returns the size in mm corresponding to a font point size.

Parameters
mmSizefont size in mm
See also
pointsToMM

Definition at line 237 of file qgscomposerutils.cpp.

◆ normalizedAngle()

double QgsComposerUtils::normalizedAngle ( const double  angle)
static

Ensures that an angle is in the range 0 <= angle < 360.

Parameters
angleangle in degrees
Returns
equivalent angle within the range [0, 360)
See also
snappedAngle

Definition at line 97 of file qgscomposerutils.cpp.

◆ pointsToMM()

double QgsComposerUtils::pointsToMM ( const double  pointSize)
static

Returns the size in mm corresponding to a font point size.

Parameters
pointSizefont size in points
See also
mmToPoints

Definition at line 231 of file qgscomposerutils.cpp.

◆ readOldDataDefinedProperty()

QgsProperty QgsComposerUtils::readOldDataDefinedProperty ( const QgsComposerObject::DataDefinedProperty  property,
const QDomElement &  ddElem 
)
static

Reads a pre 3.0 data defined property from an XML DOM element.

Since
QGIS 3.0
See also
readDataDefinedPropertyMap

Definition at line 340 of file qgscomposerutils.cpp.

◆ readOldDataDefinedPropertyMap()

void QgsComposerUtils::readOldDataDefinedPropertyMap ( const QDomElement &  itemElem,
QgsPropertyCollection dataDefinedProperties 
)
static

Reads all pre 3.0 data defined properties from an XML element.

Since
QGIS 3.0
See also
readDataDefinedProperty
writeDataDefinedPropertyMap

Definition at line 323 of file qgscomposerutils.cpp.

◆ relativePosition()

double QgsComposerUtils::relativePosition ( const double  position,
const double  beforeMin,
const double  beforeMax,
const double  afterMin,
const double  afterMax 
)
static

Returns a scaled position given a before and after range.

Parameters
positioninitial position within before range to scale
beforeMinminimum value in before range
beforeMaxmaximum value in before range
afterMinminimum value in after range
afterMaxmaximum value in after range
Returns
position scaled to range specified by afterMin and afterMax

Definition at line 254 of file qgscomposerutils.cpp.

◆ relativeResizeRect()

void QgsComposerUtils::relativeResizeRect ( QRectF &  rectToResize,
const QRectF &  boundsBefore,
const QRectF &  boundsAfter 
)
static

Resizes a QRectF relative to a resized bounding rectangle.

Parameters
rectToResizeQRectF to resize, contained within boundsBefore. The rectangle is linearly scaled to retain its relative position and size within boundsAfter.
boundsBeforeQRectF of bounds before resize
boundsAfterQRectF of bounds after resize

Definition at line 243 of file qgscomposerutils.cpp.

◆ rotate()

void QgsComposerUtils::rotate ( const double  angle,
double &  x,
double &  y 
)
static

Rotates a point / vector around the origin.

Parameters
anglerotation angle in degrees, counterclockwise
xin/out: x coordinate before / after the rotation
yin/out: y cooreinate before / after the rotation

Definition at line 87 of file qgscomposerutils.cpp.

◆ scaledFontPixelSize()

QFont QgsComposerUtils::scaledFontPixelSize ( const QFont &  font)
static

Returns a font where size is set in pixels and the size has been upscaled with FONT_WORKAROUND_SCALE to workaround QT font rendering bugs.

Parameters
fontsource font with size set in points
Returns
font with size set in pixels
Since
QGIS 2.5

Definition at line 370 of file qgscomposerutils.cpp.

◆ snappedAngle()

double QgsComposerUtils::snappedAngle ( const double  angle)
static

Snaps an angle to its closest 45 degree angle.

Parameters
angleangle in degrees
Returns
angle snapped to 0, 45/90/135/180/225/270 or 315 degrees

Definition at line 111 of file qgscomposerutils.cpp.

◆ textHeightMM()

double QgsComposerUtils::textHeightMM ( const QFont &  font,
const QString &  text,
double  multiLineHeight = 1.0 
)
static

Calculate font height in millimeters for a 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.

Parameters
fontinput font
textstring to calculate height of
multiLineHeightline spacing factor
Returns
string height in millimeters
Since
QGIS 2.12
See also
textWidthMM

Definition at line 425 of file qgscomposerutils.cpp.

◆ textWidthMM()

double QgsComposerUtils::textWidthMM ( const QFont &  font,
const QString &  text 
)
static

Calculate font width in millimeters for a string, including workarounds for QT font rendering issues.

Parameters
fontinput font
textstring to calculate width of
Returns
string width in millimeters
Since
QGIS 2.5
See also
fontAscentMM
fontDescentMM
fontHeightMM
fontHeightCharacterMM
textHeightMM

Definition at line 416 of file qgscomposerutils.cpp.


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