QGIS API Documentation  2.6.0-Brighton
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Static Public Member Functions | List of all members
QgsComposerUtils Class Reference

Utilities for compositions. More...

#include <qgscomposerutils.h>

Static Public Member Functions

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.
static double angle (const QPointF &p1, const QPointF &p2)
 Calculates the angle of the line from p1 to p2 (counter clockwise, starting from a line from north to south)
static void rotate (const double angle, double &x, double &y)
 Rotates a point / vector around the origin.
static double normalizedAngle (const double angle)
 Ensures that an angle is in the range 0 <= angle < 360.
static double snappedAngle (const double angle)
 Snaps an angle to its closest 45 degree angle.
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.
static double pointsToMM (const double pointSize)
 Returns the size in mm corresponding to a font point size.
static double mmToPoints (const double mmSize)
 Returns the size in mm corresponding to a font point size.
static void relativeResizeRect (QRectF &rectToResize, const QRectF &boundsBefore, const QRectF &boundsAfter)
 Resizes a QRectF relative to a resized bounding rectangle.
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.
static
QgsComposition::PaperOrientation 
decodePaperOrientation (const QString orientationString, bool &ok)
 Decodes a string representing a paper orientation.
static bool decodePresetPaperSize (const QString presetString, double &width, double &height)
 Decodes a string representing a preset page size.
static void readDataDefinedPropertyMap (const QDomElement &itemElem, QMap< QgsComposerObject::DataDefinedProperty, QString > *dataDefinedNames, QMap< QgsComposerObject::DataDefinedProperty, QgsDataDefined * > *dataDefinedProperties)
 Reads all data defined properties from xml.
static void readDataDefinedProperty (const QgsComposerObject::DataDefinedProperty property, const QDomElement &ddElem, QMap< QgsComposerObject::DataDefinedProperty, QgsDataDefined * > *dataDefinedProperties)
 Reads a single data defined property from xml DOM element.
static void writeDataDefinedPropertyMap (QDomElement &itemElem, QDomDocument &doc, const QMap< QgsComposerObject::DataDefinedProperty, QString > *dataDefinedNames, const QMap< QgsComposerObject::DataDefinedProperty, QgsDataDefined * > *dataDefinedProperties)
 Writes data defined properties to xml.
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.
static double fontAscentMM (const QFont &font)
 Calculate font ascent in millimeters, including workarounds for QT font rendering issues.
static double fontDescentMM (const QFont &font)
 Calculate font descent in millimeters, including workarounds for QT font rendering issues.
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).
static double fontHeightCharacterMM (const QFont &font, const QChar &character)
 Calculate font height in millimeters of a single character, including workarounds for QT font rendering issues.
static double textWidthMM (const QFont &font, const QString &text)
 Calculate font width in millimeters for a string, including workarounds for QT font rendering issues.
static void drawText (QPainter *painter, const 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)
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)

Detailed Description

Utilities for compositions.

Member Function Documentation

double QgsComposerUtils::angle ( const QPointF &  p1,
const 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
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
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
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
void QgsComposerUtils::drawText ( QPainter *  painter,
const 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
Note
added in version 2.5
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
Note
added in version 2.5
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
Note
added in version 2.5
See Also
fontDescentMM
fontHeightMM
fontHeightCharacterMM
textWidthMM
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
Note
added in version 2.5
See Also
fontAscentMM
fontHeightMM
fontHeightCharacterMM
textWidthMM
double QgsComposerUtils::fontHeightCharacterMM ( const QFont &  font,
const 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
Note
added in version 2.5
See Also
fontAscentMM
fontDescentMM
fontHeightMM
textWidthMM
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
Note
added in version 2.5
See Also
fontAscentMM
fontDescentMM
fontHeightCharacterMM
textWidthMM
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
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
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
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
void QgsComposerUtils::readDataDefinedProperty ( const QgsComposerObject::DataDefinedProperty  property,
const QDomElement &  ddElem,
QMap< QgsComposerObject::DataDefinedProperty, QgsDataDefined * > *  dataDefinedProperties 
)
static

Reads a single data defined property from xml DOM element.

Parameters
propertydata defined property to read
ddElemdom element containing settings for data defined property
dataDefinedPropertiesmap of data defined properties to QgsDataDefined in which to store properties from xml
Note
this method was added in version 2.5
See Also
readDataDefinedPropertyMap
void QgsComposerUtils::readDataDefinedPropertyMap ( const QDomElement &  itemElem,
QMap< QgsComposerObject::DataDefinedProperty, QString > *  dataDefinedNames,
QMap< QgsComposerObject::DataDefinedProperty, QgsDataDefined * > *  dataDefinedProperties 
)
static

Reads all data defined properties from xml.

Parameters
itemElemdom element containing data defined properties
dataDefinedNamesmap of data defined property to name used within xml
dataDefinedPropertiesmap of data defined properties to QgsDataDefined in which to store properties from xml
Note
this method was added in version 2.5
See Also
readDataDefinedProperty
writeDataDefinedPropertyMap
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
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
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
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
Note
added in version 2.5
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
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
Note
added in version 2.5
See Also
fontAscentMM
fontDescentMM
fontHeightMM
fontHeightCharacterMM
void QgsComposerUtils::writeDataDefinedPropertyMap ( QDomElement &  itemElem,
QDomDocument &  doc,
const QMap< QgsComposerObject::DataDefinedProperty, QString > *  dataDefinedNames,
const QMap< QgsComposerObject::DataDefinedProperty, QgsDataDefined * > *  dataDefinedProperties 
)
static

Writes data defined properties to xml.

Parameters
itemElemDOM element in which to store data defined properties
docDOM document
dataDefinedNamesmap of data defined property to name used within xml
dataDefinedPropertiesmap of data defined properties to QgsDataDefined for storing in xml
Note
this method was added in version 2.5
See Also
readDataDefinedPropertyMap

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