QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgslayoututils.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayoututils.h
3  -------------------
4  begin : July 2017
5  copyright : (C) 2017 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 QGSLAYOUTUTILS_H
18 #define QGSLAYOUTUTILS_H
19 
20 #include "qgis_core.h"
21 #include "qgslayoutitempage.h"
22 #include <QFont>
23 #include <QColor>
24 
25 class QgsRenderContext;
26 class QgsLayout;
27 class QgsLayoutItemMap;
28 class QPainter;
29 class QRectF;
30 class QStyleOptionGraphicsItem;
31 
37 class CORE_EXPORT QgsLayoutUtils
38 {
39  public:
40 
47  static void rotate( double angle, double &x, double &y );
48 
54  static double normalizedAngle( double angle, bool allowNegative = false );
55 
60  static double snappedAngle( double angle );
61 
69  static QgsRenderContext createRenderContextForMap( QgsLayoutItemMap *map, QPainter *painter, double dpi = -1 );
70 
79  static QgsRenderContext createRenderContextForLayout( QgsLayout *layout, QPainter *painter, double dpi = -1 );
80 
89  static void relativeResizeRect( QRectF &rectToResize, const QRectF &boundsBefore, const QRectF &boundsAfter );
90 
100  static double relativePosition( double position, double beforeMin, double beforeMax, double afterMin, double afterMax );
101 
107  static QFont scaledFontPixelSize( const QFont &font );
108 
116  static double fontAscentMM( const QFont &font );
117 
125  static double fontDescentMM( const QFont &font );
126 
135  static double fontHeightMM( const QFont &font );
136 
145  static double fontHeightCharacterMM( const QFont &font, QChar character );
146 
156  static double textWidthMM( const QFont &font, const QString &text );
157 
167  static double textHeightMM( const QFont &font, const QString &text, double multiLineHeight = 1.0 );
168 
176  static void drawText( QPainter *painter, QPointF position, const QString &text, const QFont &font, const QColor &color = QColor() );
177 
190  static void drawText( QPainter *painter, const QRectF &rectangle, const QString &text, const QFont &font, const QColor &color = QColor(), Qt::AlignmentFlag halignment = Qt::AlignLeft, Qt::AlignmentFlag valignment = Qt::AlignTop, int flags = Qt::TextWordWrap );
191 
200  static QRectF largestRotatedRectWithinBounds( const QRectF &originalRect, const QRectF &boundsRect, double rotation );
201 
207  static QgsLayoutItemPage::Orientation decodePaperOrientation( const QString &string, bool &ok );
208 
212  static double scaleFactorFromItemStyle( const QStyleOptionGraphicsItem *style );
213 
223  static QgsMapLayer *mapLayerFromString( const QString &string, QgsProject *project );
224 
233  static double calculatePrettySize( double minimumSize, double maximumSize );
234 
235  private:
236 
238  static constexpr double FONT_WORKAROUND_SCALE = 10;
239 
244  static double pointsToMM( double pointSize );
245 
250  static double mmToPoints( double mmSize );
251 
252  friend class TestQgsLayoutUtils;
253 };
254 
255 #endif //QGSLAYOUTUTILS_H
QgsRenderContext
Definition: qgsrendercontext.h:57
QgsProject
Definition: qgsproject.h:92
FONT_WORKAROUND_SCALE
#define FONT_WORKAROUND_SCALE
Definition: qgslegendsettings.cpp:112
QgsLayoutItemMap
Layout graphical items for displaying a map.
Definition: qgslayoutitemmap.h:39
qgslayoutitempage.h
QgsLayoutItemPage::Orientation
Orientation
Page orientation.
Definition: qgslayoutitempage.h:62
QgsLayout
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:49
QgsMapLayer
Definition: qgsmaplayer.h:81
QgsLayoutUtils
Definition: qgslayoututils.h:37
MathUtils::angle
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