QGIS API Documentation  2.99.0-Master (19b062c)
qgscomposerutils.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposerutils.h
3  -------------------
4  begin : July 2014
5  copyright : (C) 2014 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 #ifndef QGSCOMPOSERUTILS_H
18 #define QGSCOMPOSERUTILS_H
19 
20 #include "qgis_core.h"
21 #include "qgscomposition.h" //for page size and orientation enums
22 #include "qgsrendercontext.h"
23 #include <QPointF>
24 #include <QRectF>
25 
26 class QPainter;
27 
32 class CORE_EXPORT QgsComposerUtils
33 {
34  public:
35 
45  static void drawArrowHead( QPainter *p, const double x, const double y, const double angle, const double arrowHeadWidth );
46 
54  static double angle( QPointF p1, QPointF p2 );
55 
62  static void rotate( const double angle, double &x, double &y );
63 
70  static double normalizedAngle( const double angle );
71 
77  static double snappedAngle( const double angle );
78 
87  static QRectF largestRotatedRectWithinBounds( const QRectF &originalRect, const QRectF &boundsRect, const double rotation );
88 
94  static double pointsToMM( const double pointSize );
95 
101  static double mmToPoints( const double mmSize );
102 
111  static void relativeResizeRect( QRectF &rectToResize, const QRectF &boundsBefore, const QRectF &boundsAfter );
112 
122  static double relativePosition( const double position, const double beforeMin, const double beforeMax, const double afterMin, const double afterMax );
123 
130  static QgsComposition::PaperOrientation decodePaperOrientation( const QString &orientationString, bool &ok );
131 
139  static bool decodePresetPaperSize( const QString &presetString, double &width, double &height );
140 
147  static void readOldDataDefinedPropertyMap( const QDomElement &itemElem,
148  QgsPropertyCollection &dataDefinedProperties );
149 
155  static QgsProperty readOldDataDefinedProperty( const QgsComposerObject::DataDefinedProperty property, const QDomElement &ddElem );
156 
164  static QFont scaledFontPixelSize( const QFont &font );
165 
176  static double fontAscentMM( const QFont &font );
177 
188  static double fontDescentMM( const QFont &font );
189 
201  static double fontHeightMM( const QFont &font );
202 
215  static double fontHeightCharacterMM( const QFont &font, QChar character );
216 
230  static double textWidthMM( const QFont &font, const QString &text );
231 
243  static double textHeightMM( const QFont &font, const QString &text, double multiLineHeight = 1.0 );
244 
255  static void drawText( QPainter *painter, QPointF pos, const QString &text, const QFont &font, const QColor &color = QColor() );
256 
270  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 );
271 
280  static QgsRenderContext createRenderContextForMap( QgsComposerMap *map, QPainter *painter, double dpi = -1 );
281 
289  static QgsRenderContext createRenderContextForComposition( QgsComposition *composition, QPainter *painter );
290 
291 };
292 
293 #endif
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
Definition: MathUtils.cpp:786
DataDefinedProperty
Data defined properties for different item types.
A store for object properties.
Definition: qgsproperty.h:229
Graphics scene for map printing.
Object representing map window.
Contains information about the context of a rendering operation.
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
Utilities for compositions.