QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 "qgscomposition.h" //for page size and orientation enums
21 #include <QPointF>
22 #include <QRectF>
23 
24 class QPainter;
25 
29 class CORE_EXPORT QgsComposerUtils
30 {
31  public:
32 
41  static void drawArrowHead( QPainter* p, const double x, const double y, const double angle, const double arrowHeadWidth );
42 
49  static double angle( const QPointF& p1, const QPointF& p2 );
50 
56  static void rotate( const double angle, double& x, double& y );
57 
63  static double normalizedAngle( const double angle );
64 
69  static double snappedAngle( const double angle );
70 
78  static QRectF largestRotatedRectWithinBounds( const QRectF originalRect, const QRectF boundsRect, const double rotation );
79 
84  static double pointsToMM( const double pointSize );
85 
90  static double mmToPoints( const double mmSize );
91 
99  static void relativeResizeRect( QRectF &rectToResize, const QRectF &boundsBefore, const QRectF &boundsAfter );
100 
109  static double relativePosition( const double position, const double beforeMin, const double beforeMax, const double afterMin, const double afterMax );
110 
116  static QgsComposition::PaperOrientation decodePaperOrientation( const QString orientationString, bool &ok );
117 
124  static bool decodePresetPaperSize( const QString presetString, double &width, double &height );
125 
134  static void readDataDefinedPropertyMap( const QDomElement &itemElem,
135  QMap< QgsComposerObject::DataDefinedProperty, QString >* dataDefinedNames,
136  QMap< QgsComposerObject::DataDefinedProperty, QgsDataDefined* >* dataDefinedProperties
137  );
138 
146  static void readDataDefinedProperty( const QgsComposerObject::DataDefinedProperty property, const QDomElement &ddElem,
147  QMap< QgsComposerObject::DataDefinedProperty, QgsDataDefined* >* dataDefinedProperties );
148 
157  static void writeDataDefinedPropertyMap( QDomElement &itemElem, QDomDocument &doc,
158  const QMap< QgsComposerObject::DataDefinedProperty, QString >* dataDefinedNames,
159  const QMap< QgsComposerObject::DataDefinedProperty, QgsDataDefined* >* dataDefinedProperties );
160 
167  static QFont scaledFontPixelSize( const QFont& font );
168 
178  static double fontAscentMM( const QFont& font );
179 
189  static double fontDescentMM( const QFont& font );
190 
201  static double fontHeightMM( const QFont& font );
202 
214  static double fontHeightCharacterMM( const QFont& font, const QChar& character );
215 
227  static double textWidthMM( const QFont& font, const QString& text );
228 
238  static void drawText( QPainter* painter, const QPointF& pos, const QString& text, const QFont& font, const QColor& color = QColor() );
239 
252  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 );
253 
254 };
255 
256 #endif