QGIS API Documentation  2.7.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 (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) 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, 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) 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, const 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 void readDataDefinedProperty (const QgsComposerObject::DataDefinedProperty property, const QDomElement &ddElem, QMap< QgsComposerObject::DataDefinedProperty, QgsDataDefined * > *dataDefinedProperties)
 Reads a single data defined property from xml DOM element. More...
 
static void readDataDefinedPropertyMap (const QDomElement &itemElem, QMap< QgsComposerObject::DataDefinedProperty, QString > *dataDefinedNames, QMap< QgsComposerObject::DataDefinedProperty, QgsDataDefined * > *dataDefinedProperties)
 Reads all data defined properties from xml. 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 textWidthMM (const QFont &font, const QString &text)
 Calculate font width in millimeters for a string, including workarounds for QT font rendering issues. More...
 
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. More...
 

Detailed Description

Utilities for compositions.

Definition at line 29 of file qgscomposerutils.h.

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

Definition at line 67 of file qgscomposerutils.cpp.

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 262 of file qgscomposerutils.cpp.

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 278 of file qgscomposerutils.cpp.

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 29 of file qgscomposerutils.cpp.

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

Definition at line 484 of file qgscomposerutils.cpp.

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

Definition at line 507 of file qgscomposerutils.cpp.

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

Definition at line 439 of file qgscomposerutils.cpp.

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

Definition at line 448 of file qgscomposerutils.cpp.

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

Definition at line 466 of file qgscomposerutils.cpp.

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

Definition at line 457 of file qgscomposerutils.cpp.

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 149 of file qgscomposerutils.cpp.

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 235 of file qgscomposerutils.cpp.

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 95 of file qgscomposerutils.cpp.

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 229 of file qgscomposerutils.cpp.

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

Definition at line 336 of file qgscomposerutils.cpp.

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

Definition at line 321 of file qgscomposerutils.cpp.

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 252 of file qgscomposerutils.cpp.

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 241 of file qgscomposerutils.cpp.

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 85 of file qgscomposerutils.cpp.

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

Definition at line 429 of file qgscomposerutils.cpp.

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 109 of file qgscomposerutils.cpp.

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

Definition at line 475 of file qgscomposerutils.cpp.

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

Definition at line 381 of file qgscomposerutils.cpp.


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