QGIS API Documentation  2.99.0-Master (0a63d1f)
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 
31 class CORE_EXPORT QgsComposerUtils
32 {
33  public:
34 
43  static void drawArrowHead( QPainter* p, const double x, const double y, const double angle, const double arrowHeadWidth );
44 
51  static double angle( QPointF p1, QPointF p2 );
52 
58  static void rotate( const double angle, double& x, double& y );
59 
65  static double normalizedAngle( const double angle );
66 
71  static double snappedAngle( const double angle );
72 
80  static QRectF largestRotatedRectWithinBounds( const QRectF &originalRect, const QRectF &boundsRect, const double rotation );
81 
86  static double pointsToMM( const double pointSize );
87 
92  static double mmToPoints( const double mmSize );
93 
101  static void relativeResizeRect( QRectF &rectToResize, const QRectF &boundsBefore, const QRectF &boundsAfter );
102 
111  static double relativePosition( const double position, const double beforeMin, const double beforeMax, const double afterMin, const double afterMax );
112 
118  static QgsComposition::PaperOrientation decodePaperOrientation( const QString& orientationString, bool &ok );
119 
126  static bool decodePresetPaperSize( const QString& presetString, double &width, double &height );
127 
136  static void readDataDefinedPropertyMap( const QDomElement &itemElem,
137  QMap< QgsComposerObject::DataDefinedProperty, QString >* dataDefinedNames,
138  QMap< QgsComposerObject::DataDefinedProperty, QgsDataDefined* >* dataDefinedProperties
139  );
140 
148  static void readDataDefinedProperty( const QgsComposerObject::DataDefinedProperty property, const QDomElement &ddElem,
149  QMap< QgsComposerObject::DataDefinedProperty, QgsDataDefined* >* dataDefinedProperties );
150 
159  static void writeDataDefinedPropertyMap( QDomElement &itemElem, QDomDocument &doc,
160  const QMap< QgsComposerObject::DataDefinedProperty, QString >* dataDefinedNames,
161  const QMap< QgsComposerObject::DataDefinedProperty, QgsDataDefined* >* dataDefinedProperties );
162 
169  static QFont scaledFontPixelSize( const QFont& font );
170 
180  static double fontAscentMM( const QFont& font );
181 
191  static double fontDescentMM( const QFont& font );
192 
203  static double fontHeightMM( const QFont& font );
204 
216  static double fontHeightCharacterMM( const QFont& font, QChar character );
217 
230  static double textWidthMM( const QFont& font, const QString& text );
231 
242  static double textHeightMM( const QFont& font, const QString& text, double multiLineHeight = 1.0 );
243 
253  static void drawText( QPainter* painter, QPointF pos, const QString& text, const QFont& font, const QColor& color = QColor() );
254 
267  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 );
268 
275  static QgsRenderContext createRenderContext( QgsComposition* composition, QPainter& painter );
276 
277 };
278 
279 #endif
DataDefinedProperty
Data defined properties for different item types.
Graphics scene for map printing.
Contains information about the context of a rendering operation.
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)
Definition: MathUtils.cc:857
Utilities for compositions.