QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
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
26class QgsLayout;
28class QPainter;
29class QRectF;
30class QStyleOptionGraphicsItem;
31
36class CORE_EXPORT QgsLayoutUtils
37{
38 public:
39
46 static void rotate( double angle, double &x, double &y );
47
53 static double normalizedAngle( double angle, bool allowNegative = false );
54
59 static double snappedAngle( double angle );
60
68 static QgsRenderContext createRenderContextForMap( QgsLayoutItemMap *map, QPainter *painter, double dpi = -1 );
69
78 static QgsRenderContext createRenderContextForLayout( QgsLayout *layout, QPainter *painter, double dpi = -1 );
79
88 static void relativeResizeRect( QRectF &rectToResize, const QRectF &boundsBefore, const QRectF &boundsAfter );
89
99 static double relativePosition( double position, double beforeMin, double beforeMax, double afterMin, double afterMax );
100
106 static QFont scaledFontPixelSize( const QFont &font );
107
115 static double fontAscentMM( const QFont &font );
116
124 static double fontDescentMM( const QFont &font );
125
134 static double fontHeightMM( const QFont &font );
135
144 static double fontHeightCharacterMM( const QFont &font, QChar character );
145
155 static double textWidthMM( const QFont &font, const QString &text );
156
166 static double textHeightMM( const QFont &font, const QString &text, double multiLineHeight = 1.0 );
167
175 static void drawText( QPainter *painter, QPointF position, const QString &text, const QFont &font, const QColor &color = QColor() );
176
189 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 );
190
199 static QRectF largestRotatedRectWithinBounds( const QRectF &originalRect, const QRectF &boundsRect, double rotation );
200
206 static QgsLayoutItemPage::Orientation decodePaperOrientation( const QString &string, bool &ok );
207
213 Q_DECL_DEPRECATED static double scaleFactorFromItemStyle( const QStyleOptionGraphicsItem *style ) SIP_DEPRECATED;
214
220 static double scaleFactorFromItemStyle( const QStyleOptionGraphicsItem *style, QPainter *painter );
221
231 static QgsMapLayer *mapLayerFromString( const QString &string, QgsProject *project );
232
241 static double calculatePrettySize( double minimumSize, double maximumSize );
242
248 static bool itemIsAClippingSource( const QgsLayoutItem *item );
249
255 static QVector< double > predefinedScales( const QgsLayout *layout );
256
257 private:
258
260 static constexpr double FONT_WORKAROUND_SCALE = 10;
261
266 static double pointsToMM( double pointSize );
267
272 static double mmToPoints( double mmSize );
273
274 friend class TestQgsLayoutUtils;
275};
276
277#endif //QGSLAYOUTUTILS_H
Layout graphical items for displaying a map.
Orientation
Page orientation.
Base class for graphical items within a QgsLayout.
Utilities for layouts.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition qgslayout.h:49
Base class for all map layer types.
Definition qgsmaplayer.h:76
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:107
Contains information about the context of a rendering operation.
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define FONT_WORKAROUND_SCALE