QGIS API Documentation 4.3.0-Master (0cef2469b72)
Loading...
Searching...
No Matches
qgspainting.h
Go to the documentation of this file.
1/***************************************************************************
2 qgspainting.h
3 ---------------------
4 begin : July 2016
5 copyright : (C) 2016 by Martin Dobias
6 email : wonder dot sk at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15#ifndef QGSPAINTING_H
16#define QGSPAINTING_H
17
18#include "qgis.h"
19#include "qgis_core.h"
20#include "qgis_sip.h"
21
22#include <QPainter>
23
24class QTransform;
25
31class CORE_EXPORT QgsPainting
32{
33 public:
39 static QPainter::CompositionMode getCompositionMode( Qgis::BlendMode blendMode );
40
46 static Qgis::BlendMode getBlendModeEnum( QPainter::CompositionMode blendMode );
47
53 static bool isClippingMode( Qgis::BlendMode mode );
54
77 static QTransform triangleToTriangleTransform(
78 double inX1, double inY1, double inX2, double inY2, double inX3, double inY3, double outX1, double outY1, double outX2, double outY2, double outX3, double outY3, bool &ok SIP_OUT
79 );
80
93 static bool drawTriangleUsingTexture(
94 QPainter *painter, const QPolygonF &triangle, const QImage &textureImage, float textureX1, float textureY1, float textureX2, float textureY2, float textureX3, float textureY3
95 );
96
105 static int qtDefaultDpiX();
106
115 static int qtDefaultDpiY();
116
128 static void applyScaleFixForQPictureDpi( QPainter *painter );
129
137 static void drawPicture( QPainter *painter, const QPointF &point, const QPicture &picture );
138
147 static void rotatePainterAroundPoint( QPainter *painter, const QPointF &point, double angle );
148
157 static QPicture deepCopyQPicture( const QPicture &picture );
158};
159
160#ifndef SIP_RUN
161
162// TODO - this can be replaced by QPainterStateGuard when we require Qt 6.9 +
177{
178 public:
182 enum class InitialState
183 {
186 };
187
193 QgsScopedQPainterState( QPainter *painter, InitialState initialState = InitialState::Save )
194 : mPainter( painter )
195 {
196 if ( mPainter && initialState == InitialState::Save )
197 {
198 mPainter->save();
199 mSavedStates++;
200 }
201 }
202
207 {
208 while ( mPainter && mSavedStates > 0 )
209 {
210 mPainter->restore();
211 mSavedStates--;
212 }
213 }
214
219
226 void restore()
227 {
228 if ( mPainter && mSavedStates > 0 )
229 {
230 mPainter->restore();
231 mSavedStates--;
232 }
233 }
234
240 void save()
241 {
242 if ( mPainter )
243 {
244 mPainter->save();
245 mSavedStates++;
246 }
247 }
248
249 private:
250 int mSavedStates = 0;
251 QPainter *mPainter = nullptr;
252};
253
254#endif
255
256#endif // QGSPAINTING_H
BlendMode
Blending modes defining the available composition modes that can be used when painting.
Definition qgis.h:5497
Contains miscellaneous painting utility functions.
Definition qgspainting.h:32
static bool drawTriangleUsingTexture(QPainter *painter, const QPolygonF &triangle, const QImage &textureImage, float textureX1, float textureY1, float textureX2, float textureY2, float textureX3, float textureY3)
Draws a triangle onto a painter using a mapped texture image.
static void rotatePainterAroundPoint(QPainter *painter, const QPointF &point, double angle)
Rotates a painter by angle degrees clockwise around point.
static int qtDefaultDpiY()
Returns the default Qt vertical DPI.
static Qgis::BlendMode getBlendModeEnum(QPainter::CompositionMode blendMode)
Returns a Qgis::BlendMode corresponding to a QPainter::CompositionMode.
static bool isClippingMode(Qgis::BlendMode mode)
Returns true if mode is a clipping blend mode.
static int qtDefaultDpiX()
Returns the default Qt horizontal DPI.
static QTransform triangleToTriangleTransform(double inX1, double inY1, double inX2, double inY2, double inX3, double inY3, double outX1, double outY1, double outX2, double outY2, double outX3, double outY3, bool &ok)
Calculates the QTransform which maps the triangle defined by the points (inX1, inY1),...
static QPainter::CompositionMode getCompositionMode(Qgis::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a Qgis::BlendMode.
static QPicture deepCopyQPicture(const QPicture &picture)
Deep copies a QPicture, making a copy which is safe to use in a different thread.
static void applyScaleFixForQPictureDpi(QPainter *painter)
Applies a workaround to a painter to avoid an issue with incorrect scaling when drawing QPictures.
static void drawPicture(QPainter *painter, const QPointF &point, const QPicture &picture)
Draws a picture onto a painter, correctly applying workarounds to avoid issues with incorrect scaling...
QgsScopedQPainterState(QgsScopedQPainterState &&)=delete
QgsScopedQPainterState & operator=(const QgsScopedQPainterState &)=delete
InitialState
Initial action to take when constructing the scoped object.
@ NoSave
Do not save the current painter state.
@ Save
Immediately save the current painter state.
QgsScopedQPainterState(const QgsScopedQPainterState &)=delete
void save()
Performs a manual save on the painter state, pushing another saved state to the painter.
~QgsScopedQPainterState()
Restores the painter back to its original state.
void restore()
Performs a manual restore on the painter state, popping the latest state from the painter.
QgsScopedQPainterState(QPainter *painter, InitialState initialState=InitialState::Save)
Constructor for QgsScopedQPainterState.
QgsScopedQPainterState & operator=(QgsScopedQPainterState &&)=delete
#define SIP_OUT
Definition qgis_sip.h:57