23 #define FONT_WORKAROUND_SCALE 10 //scale factor for upscaling fontsize and downscaling painter    26 #define M_DEG2RAD 0.0174532925    36   double angleRad = angle / 180.0 * 
M_PI;
    43   p1Rotated.
setX( p1.
x() * cos( angleRad ) + p1.
y() * -sin( angleRad ) );
    44   p1Rotated.
setY( p1.
x() * sin( angleRad ) + p1.
y() * cos( angleRad ) );
    45   p2Rotated.
setX( p2.
x() * cos( angleRad ) + p2.
y() * -sin( angleRad ) );
    46   p2Rotated.
setY( p2.
x() * sin( angleRad ) + p2.
y() * cos( angleRad ) );
    49   arrowHeadPoly << middlePoint;
    50   arrowHeadPoly << 
QPointF( middlePoint.x() + p1Rotated.
x(), middlePoint.y() + p1Rotated.
y() );
    51   arrowHeadPoly << 
QPointF( middlePoint.x() + p2Rotated.
x(), middlePoint.y() + p2Rotated.
y() );
    58   arrowBrush.
setStyle( Qt::SolidPattern );
    61   arrowBrush.
setStyle( Qt::SolidPattern );
    69   double xDiff = p2.
x() - p1.
x();
    70   double yDiff = p2.
y() - p1.
y();
    71   double length = sqrt( xDiff * xDiff + yDiff * yDiff );
    77   double angle = acos(( -yDiff * length ) / ( length * length ) ) * 180 / 
M_PI;
    80     return ( 360 - angle );
    87   double rotToRad = angle * 
M_PI / 180.0;
    89   xRot = x * cos( rotToRad ) - y * sin( rotToRad );
    90   yRot = x * sin( rotToRad ) + y * cos( rotToRad );
    97   double clippedAngle = 
angle;
    98   if ( clippedAngle >= 360.0 || clippedAngle <= -360.0 )
   100     clippedAngle = fmod( clippedAngle, 360.0 );
   102   if ( clippedAngle < 0.0 )
   104     clippedAngle += 360.0;
   115   if ( clippedAngle >= 22.5 && clippedAngle < 67.5 )
   119   else if ( clippedAngle >= 67.5 && clippedAngle < 112.5 )
   123   else if ( clippedAngle >= 112.5 && clippedAngle < 157.5 )
   127   else if ( clippedAngle >= 157.5 && clippedAngle < 202.5 )
   131   else if ( clippedAngle >= 202.5 && clippedAngle < 247.5 )
   135   else if ( clippedAngle >= 247.5 && clippedAngle < 292.5 )
   139   else if ( clippedAngle >= 292.5 && clippedAngle < 337.5 )
   151   double originalWidth = originalRect.
width();
   152   double originalHeight = originalRect.
height();
   153   double boundsWidth = boundsRect.
width();
   154   double boundsHeight = boundsRect.
height();
   155   double ratioBoundsRect = boundsWidth / boundsHeight;
   165       rectScale = (( originalWidth / originalHeight ) > ratioBoundsRect ) ? boundsWidth / originalWidth : boundsHeight / originalHeight;
   169       rectScale = (( originalHeight / originalWidth ) > ratioBoundsRect ) ? boundsWidth / originalHeight : boundsHeight / originalWidth;
   171     double rectScaledWidth = rectScale * originalWidth;
   172     double rectScaledHeight = rectScale * originalHeight;
   176       return QRectF(( boundsWidth - rectScaledWidth ) / 2.0, ( boundsHeight - rectScaledHeight ) / 2.0, rectScaledWidth, rectScaledHeight );
   180       return QRectF(( boundsWidth - rectScaledHeight ) / 2.0, ( boundsHeight - rectScaledWidth ) / 2.0, rectScaledWidth, rectScaledHeight );
   185   double angleRad = -clippedRotation * 
M_DEG2RAD;
   186   double cosAngle = cos( angleRad );
   187   double sinAngle = sin( angleRad );
   190   double widthBoundsRotatedRect = originalWidth * fabs( cosAngle ) + originalHeight * fabs( sinAngle );
   191   double heightBoundsRotatedRect = originalHeight * fabs( cosAngle ) + originalWidth * fabs( sinAngle );
   195   double ratioBoundsRotatedRect = widthBoundsRotatedRect / heightBoundsRotatedRect;
   196   double rectScale = ratioBoundsRotatedRect > ratioBoundsRect ? boundsWidth / widthBoundsRotatedRect : boundsHeight / heightBoundsRotatedRect;
   197   double rectScaledWidth = rectScale * originalWidth;
   198   double rectScaledHeight = rectScale * originalHeight;
   202   double currentCornerX = 0;
   204   currentCornerX += rectScaledWidth * cosAngle;
   205   minX = minX < currentCornerX ? minX : currentCornerX;
   206   currentCornerX += rectScaledHeight * sinAngle;
   207   minX = minX < currentCornerX ? minX : currentCornerX;
   208   currentCornerX -= rectScaledWidth * cosAngle;
   209   minX = minX < currentCornerX ? minX : currentCornerX;
   211   double currentCornerY = 0;
   213   currentCornerY -= rectScaledWidth * sinAngle;
   214   minY = minY < currentCornerY ? minY : currentCornerY;
   215   currentCornerY += rectScaledHeight * cosAngle;
   216   minY = minY < currentCornerY ? minY : currentCornerY;
   217   currentCornerY += rectScaledWidth * sinAngle;
   218   minY = minY < currentCornerY ? minY : currentCornerY;
   221   double offsetX = ratioBoundsRotatedRect > ratioBoundsRect ? 0 : ( boundsWidth - rectScale * widthBoundsRotatedRect ) / 2.0;
   222   offsetX += fabs( minX );
   223   double offsetY = ratioBoundsRotatedRect > ratioBoundsRect ? ( boundsHeight - rectScale * heightBoundsRotatedRect ) / 2.0 : 0;
   224   offsetY += fabs( minY );
   226   return QRectF( offsetX, offsetY, rectScaledWidth, rectScaledHeight );
   232   return ( pointSize * 0.3527 );
   238   return ( mmSize / 0.3527 );
   249   rectToResize.
setRect( left, top, right - left, bottom - top );
   255   double m = ( afterMax - afterMin ) / ( beforeMax - beforeMin );
   256   double c = afterMin - ( beforeMin * m );
   259   return m * position + c;
   264   if ( orientationString.
compare( 
"Portrait", Qt::CaseInsensitive ) == 0 )
   269   if ( orientationString.
compare( 
"Landscape", Qt::CaseInsensitive ) == 0 )
   286   presets << qMakePair( 
QString( 
"A0" ), 
QSizeF( 841, 1189 ) );
   291   presets << qMakePair( 
QString( 
"B1" ), 
QSizeF( 707, 1000 ) );
   292   presets << qMakePair( 
QString( 
"B0" ), 
QSizeF( 1000, 1414 ) );
   294   presets << qMakePair( 
QString( 
"Legal" ), 
QSizeF( 215.9, 355.6 ) );
   295   presets << qMakePair( 
QString( 
"Letter" ), 
QSizeF( 215.9, 279.4 ) );
   296   presets << qMakePair( 
QString( 
"ANSI A" ), 
QSizeF( 215.9, 279.4 ) );
   297   presets << qMakePair( 
QString( 
"ANSI B" ), 
QSizeF( 279.4, 431.8 ) );
   298   presets << qMakePair( 
QString( 
"ANSI C" ), 
QSizeF( 431.8, 558.8 ) );
   299   presets << qMakePair( 
QString( 
"ANSI D" ), 
QSizeF( 558.8, 863.6 ) );
   300   presets << qMakePair( 
QString( 
"ANSI E" ), 
QSizeF( 863.6, 1117.6 ) );
   301   presets << qMakePair( 
QString( 
"Arch A" ), 
QSizeF( 228.6, 304.8 ) );
   302   presets << qMakePair( 
QString( 
"Arch B" ), 
QSizeF( 304.8, 457.2 ) );
   303   presets << qMakePair( 
QString( 
"Arch C" ), 
QSizeF( 457.2, 609.6 ) );
   304   presets << qMakePair( 
QString( 
"Arch D" ), 
QSizeF( 609.6, 914.4 ) );
   305   presets << qMakePair( 
QString( 
"Arch E" ), 
QSizeF( 914.4, 1219.2 ) );
   306   presets << qMakePair( 
QString( 
"Arch E1" ), 
QSizeF( 762, 1066.8 ) );
   309   for ( ;presetIt != presets.
constEnd(); ++presetIt )
   311     if ( presetString.
compare(( *presetIt ).first, Qt::CaseInsensitive ) == 0 )
   313       width = ( *presetIt ).second.width();
   314       height = ( *presetIt ).second.height();
   324   for ( ; i != dataDefinedNames->
constEnd(); ++i )
   347   if ( it != dataDefinedProperties->
constEnd() )
   355     dataDefinedProperties->
insert( property, dd );
   360   if ( active.
compare( 
"true", Qt::CaseInsensitive ) == 0 )
   371   if ( useExpr.
compare( 
"true", Qt::CaseInsensitive ) == 0 )
   384   for ( ; i != dataDefinedNames->
constEnd(); ++i )
   389     if ( it != dataDefinedProperties->
constEnd() )
   399         bool defaultVals = ( !active && !useExpr && expr.
isEmpty() && field.
isEmpty() );
   433   QFont scaledFont = font;
   487   int lines = multiLineSplit.
size();
   494   double fontHeight = fontMetrics.
ascent() + fontMetrics.
descent(); 
   495   double textHeight = fontMetrics.
ascent() + 
static_cast< double >(( lines - 1 ) * fontHeight * multiLineHeight );
   518   painter->
scale( scaleFactor, scaleFactor );
   544   painter->
scale( scaleFactor, scaleFactor );
   545   painter->
drawText( scaledRect, halignment | valignment | flags, text );
 static void relativeResizeRect(QRectF &rectToResize, const QRectF &boundsBefore, const QRectF &boundsAfter)
Resizes a QRectF relative to a resized bounding rectangle. 
 
QDomNodeList elementsByTagName(const QString &tagname) const
 
void setActive(bool active)
 
A container class for data source field mapping or expression. 
 
static double normalizedAngle(const double angle)
Ensures that an angle is in the range 0 <= angle < 360. 
 
QDomNode appendChild(const QDomNode &newChild)
 
QString attribute(const QString &name, const QString &defValue) const
 
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...
 
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
 
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. 
 
void scale(qreal sx, qreal sy)
 
const_iterator constBegin() const
 
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 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 ...
 
void drawPolygon(const QPointF *points, int pointCount, Qt::FillRule fillRule)
 
void setJoinStyle(Qt::PenJoinStyle style)
 
static double fontAscentMM(const QFont &font)
Calculate font ascent in millimeters, including workarounds for QT font rendering issues...
 
const_iterator constFind(const Key &key) const
 
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 ...
 
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 double fontDescentMM(const QFont &font)
Calculate font descent in millimeters, including workarounds for QT font rendering issues...
 
void setStyle(Qt::BrushStyle style)
 
qreal width(const QString &text) const
 
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference) 
 
DataDefinedProperty
Data defined properties for different item types. 
 
bool useExpression() const
Returns if the field or the expression part is active. 
 
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. 
 
QDomElement toElement() const
 
void setPixelSize(int pixelSize)
 
void setUseExpression(bool use)
Controls if the field or the expression part is active. 
 
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. 
 
void setFont(const QFont &font)
 
static double fontHeightCharacterMM(const QFont &font, QChar character)
Calculate font height in millimeters of a single character, including workarounds for QT font renderi...
 
void setPen(const QColor &color)
 
QRectF boundingRect(const QString &text) const
 
void setAttribute(const QString &name, const QString &value)
 
void setField(const QString &field)
Set the field name which this QgsDataDefined represents. 
 
QString expressionString() const
Returns the expression string of this QgsDataDefined. 
 
const_iterator constEnd() const
 
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. 
 
void setBrush(const QBrush &brush)
 
void drawText(const QPointF &position, const QString &text)
 
static void rotate(const double angle, double &x, double &y)
Rotates a point / vector around the origin. 
 
double ANALYSIS_EXPORT angle(Point3D *p1, Point3D *p2, Point3D *p3, Point3D *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored) 
 
const QBrush & brush() const
 
QString field() const
Get the field which this QgsDataDefined represents. 
 
static bool decodePresetPaperSize(const QString &presetString, double &width, double &height)
Decodes a string representing a preset page size. 
 
const Key key(const T &value) const
 
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 double fontHeightMM(const QFont &font)
Calculate font height in millimeters, including workarounds for QT font rendering issues The font hei...
 
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...
 
static double pointsToMM(const double pointSize)
Returns the size in mm corresponding to a font point size. 
 
static double snappedAngle(const double angle)
Snaps an angle to its closest 45 degree angle. 
 
#define FONT_WORKAROUND_SCALE
 
iterator insert(const Key &key, const T &value)
 
void setRect(qreal x, qreal y, qreal width, qreal height)
 
const_iterator constEnd() const
 
QDomElement createElement(const QString &tagName)
 
const_iterator constBegin() const
 
int compare(const QString &other) const
 
void setExpressionString(const QString &expr)
Sets the expression for this QgsDataDefined. 
 
iterator find(const Key &key)
 
static QgsComposition::PaperOrientation decodePaperOrientation(const QString &orientationString, bool &ok)
Decodes a string representing a paper orientation. 
 
QDomNode at(int index) const
 
const T value(const Key &key) const
 
static double mmToPoints(const double mmSize)
Returns the size in mm corresponding to a font point size.