QGIS API Documentation 3.32.0-Lima (311a8cb8a6)
qgspainting.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgspainting.cpp
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
16#include "qgspainting.h"
17
18#include "qgslogger.h"
19
20QPainter::CompositionMode QgsPainting::getCompositionMode( Qgis::BlendMode blendMode )
21{
22 // Map Qgis::BlendMode::Normal to QPainter::CompositionMode
23 switch ( blendMode )
24 {
25 case Qgis::BlendMode::Normal:
26 return QPainter::CompositionMode_SourceOver;
27 case Qgis::BlendMode::Lighten:
28 return QPainter::CompositionMode_Lighten;
29 case Qgis::BlendMode::Screen:
30 return QPainter::CompositionMode_Screen;
31 case Qgis::BlendMode::Dodge:
32 return QPainter::CompositionMode_ColorDodge;
33 case Qgis::BlendMode::Addition:
34 return QPainter::CompositionMode_Plus;
35 case Qgis::BlendMode::Darken:
36 return QPainter::CompositionMode_Darken;
37 case Qgis::BlendMode::Multiply:
38 return QPainter::CompositionMode_Multiply;
39 case Qgis::BlendMode::Burn:
40 return QPainter::CompositionMode_ColorBurn;
41 case Qgis::BlendMode::Overlay:
42 return QPainter::CompositionMode_Overlay;
43 case Qgis::BlendMode::SoftLight:
44 return QPainter::CompositionMode_SoftLight;
45 case Qgis::BlendMode::HardLight:
46 return QPainter::CompositionMode_HardLight;
47 case Qgis::BlendMode::Difference:
48 return QPainter::CompositionMode_Difference;
49 case Qgis::BlendMode::Subtract:
50 return QPainter::CompositionMode_Exclusion;
51 case Qgis::BlendMode::Source:
52 return QPainter::CompositionMode_Source;
53 case Qgis::BlendMode::DestinationOver:
54 return QPainter::CompositionMode_DestinationOver;
55 case Qgis::BlendMode::Clear:
56 return QPainter::CompositionMode_Clear;
57 case Qgis::BlendMode::Destination:
58 return QPainter::CompositionMode_Destination;
59 case Qgis::BlendMode::SourceIn:
60 return QPainter::CompositionMode_SourceIn;
61 case Qgis::BlendMode::DestinationIn:
62 return QPainter::CompositionMode_DestinationIn;
63 case Qgis::BlendMode::SourceOut:
64 return QPainter::CompositionMode_SourceOut;
65 case Qgis::BlendMode::DestinationOut:
66 return QPainter::CompositionMode_DestinationOut;
67 case Qgis::BlendMode::SourceAtop:
68 return QPainter::CompositionMode_SourceAtop;
69 case Qgis::BlendMode::DestinationAtop:
70 return QPainter::CompositionMode_DestinationAtop;
71 case Qgis::BlendMode::Xor:
72 return QPainter::CompositionMode_Xor;
73 default:
74 QgsDebugError( QStringLiteral( "Blend mode %1 mapped to SourceOver" ).arg( qgsEnumValueToKey( blendMode ) ) );
75 return QPainter::CompositionMode_SourceOver;
76 }
77}
78
79
80Qgis::BlendMode QgsPainting::getBlendModeEnum( QPainter::CompositionMode blendMode )
81{
82 // Map QPainter::CompositionMode to Qgis::BlendMode::Normal
83 switch ( blendMode )
84 {
85 case QPainter::CompositionMode_SourceOver:
86 return Qgis::BlendMode::Normal;
87 case QPainter::CompositionMode_Lighten:
88 return Qgis::BlendMode::Lighten;
89 case QPainter::CompositionMode_Screen:
90 return Qgis::BlendMode::Screen;
91 case QPainter::CompositionMode_ColorDodge:
92 return Qgis::BlendMode::Dodge;
93 case QPainter::CompositionMode_Plus:
94 return Qgis::BlendMode::Addition;
95 case QPainter::CompositionMode_Darken:
96 return Qgis::BlendMode::Darken;
97 case QPainter::CompositionMode_Multiply:
98 return Qgis::BlendMode::Multiply;
99 case QPainter::CompositionMode_ColorBurn:
100 return Qgis::BlendMode::Burn;
101 case QPainter::CompositionMode_Overlay:
102 return Qgis::BlendMode::Overlay;
103 case QPainter::CompositionMode_SoftLight:
104 return Qgis::BlendMode::SoftLight;
105 case QPainter::CompositionMode_HardLight:
106 return Qgis::BlendMode::HardLight;
107 case QPainter::CompositionMode_Difference:
108 return Qgis::BlendMode::Difference;
109 case QPainter::CompositionMode_Exclusion:
110 return Qgis::BlendMode::Subtract;
111 case QPainter::CompositionMode_Source:
112 return Qgis::BlendMode::Source;
113 case QPainter::CompositionMode_DestinationOver:
114 return Qgis::BlendMode::DestinationOver;
115 case QPainter::CompositionMode_Clear:
116 return Qgis::BlendMode::Clear;
117 case QPainter::CompositionMode_Destination:
118 return Qgis::BlendMode::Destination;
119 case QPainter::CompositionMode_SourceIn:
120 return Qgis::BlendMode::SourceIn;
121 case QPainter::CompositionMode_DestinationIn:
122 return Qgis::BlendMode::DestinationIn;
123 case QPainter::CompositionMode_SourceOut:
124 return Qgis::BlendMode::SourceOut;
125 case QPainter::CompositionMode_DestinationOut:
126 return Qgis::BlendMode::DestinationOut;
127 case QPainter::CompositionMode_SourceAtop:
128 return Qgis::BlendMode::SourceAtop;
129 case QPainter::CompositionMode_DestinationAtop:
130 return Qgis::BlendMode::DestinationAtop;
131 case QPainter::CompositionMode_Xor:
132 return Qgis::BlendMode::Xor;
133 default:
134 QgsDebugError( QStringLiteral( "Composition mode %1 mapped to Normal" ).arg( blendMode ) );
135 return Qgis::BlendMode::Normal;
136 }
137}
138
140{
141 switch ( mode )
142 {
143 case Qgis::BlendMode::Normal:
144 case Qgis::BlendMode::Lighten:
145 case Qgis::BlendMode::Screen:
146 case Qgis::BlendMode::Dodge:
147 case Qgis::BlendMode::Addition:
148 case Qgis::BlendMode::Darken:
149 case Qgis::BlendMode::Multiply:
150 case Qgis::BlendMode::Burn:
151 case Qgis::BlendMode::Overlay:
152 case Qgis::BlendMode::SoftLight:
153 case Qgis::BlendMode::HardLight:
154 case Qgis::BlendMode::Difference:
155 case Qgis::BlendMode::Subtract:
156 case Qgis::BlendMode::Source:
157 case Qgis::BlendMode::DestinationOver:
158 case Qgis::BlendMode::Clear:
159 case Qgis::BlendMode::Destination:
160 return false;
161
162 case Qgis::BlendMode::SourceIn:
163 case Qgis::BlendMode::DestinationIn:
164 case Qgis::BlendMode::SourceOut:
165 case Qgis::BlendMode::DestinationOut:
166 case Qgis::BlendMode::SourceAtop:
167 case Qgis::BlendMode::DestinationAtop:
168 case Qgis::BlendMode::Xor:
169 return true;
170 }
171 return false;
172}
BlendMode
Blending modes defining the available composition modes that can be used when painting.
Definition: qgis.h:3227
static Qgis::BlendMode getBlendModeEnum(QPainter::CompositionMode blendMode)
Returns a BlendMode corresponding to a QPainter::CompositionMode.
Definition: qgspainting.cpp:80
static bool isClippingMode(Qgis::BlendMode mode)
Returns true if mode is a clipping blend mode.
static QPainter::CompositionMode getCompositionMode(Qgis::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode.
Definition: qgspainting.cpp:20
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
Definition: qgis.h:4192
#define QgsDebugError(str)
Definition: qgslogger.h:38