QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
qgspainteffect.h
Go to the documentation of this file.
1/***************************************************************************
2 qgspainteffect.h
3 ----------------
4 begin : December 2014
5 copyright : (C) 2014 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 QGSPAINTEFFECT_H
18#define QGSPAINTEFFECT_H
19
20#include "qgis.h"
21#include "qgis_core.h"
22#include "qgis_sip.h"
23
24#include <QDomDocument>
25#include <QDomElement>
26#include <QPainter>
27#include <QPicture>
28
30
53
55{
56
57#ifdef SIP_RUN
59 if ( sipCpp->type() == "drawSource" && dynamic_cast<QgsDrawSourceEffect *>( sipCpp ) != NULL )
60 {
61 sipType = sipType_QgsDrawSourceEffect;
62 }
63 else if ( sipCpp->type() == "effectStack" && dynamic_cast<QgsEffectStack *>( sipCpp ) != NULL )
64 {
65 sipType = sipType_QgsEffectStack;
66 }
67 else if ( sipCpp->type() == "blur" && dynamic_cast<QgsBlurEffect *>( sipCpp ) != NULL )
68 {
69 sipType = sipType_QgsBlurEffect;
70 }
71 else if ( sipCpp->type() == "dropShadow" && dynamic_cast<QgsDropShadowEffect *>( sipCpp ) != NULL )
72 {
73 sipType = sipType_QgsDropShadowEffect;
74 }
75 else if ( sipCpp->type() == "outerGlow" && dynamic_cast<QgsOuterGlowEffect *>( sipCpp ) != NULL )
76 {
77 sipType = sipType_QgsOuterGlowEffect;
78 }
79 else if ( sipCpp->type() == "innerGlow" && dynamic_cast<QgsInnerGlowEffect *>( sipCpp ) != NULL )
80 {
81 sipType = sipType_QgsInnerGlowEffect;
82 }
83 else if ( sipCpp->type() == "transform" && dynamic_cast<QgsTransformEffect *>( sipCpp ) != NULL )
84 {
85 sipType = sipType_QgsTransformEffect;
86 }
87 else if ( sipCpp->type() == "color" && dynamic_cast<QgsColorEffect *>( sipCpp ) != NULL )
88 {
89 sipType = sipType_QgsColorEffect;
90 }
91 else
92 {
93 sipType = 0;
94 }
96#endif
97
98 public:
99
111
112 QgsPaintEffect() = default;
113
114 QgsPaintEffect( const QgsPaintEffect &other );
115 virtual ~QgsPaintEffect();
116
121 virtual QString type() const = 0;
122
127 virtual QgsPaintEffect *clone() const = 0 SIP_FACTORY;
128
134 virtual Qgis::PaintEffectFlags flags() const;
135
143 virtual QVariantMap properties() const = 0;
144
151 virtual void readProperties( const QVariantMap &props ) = 0;
152
162 virtual bool saveProperties( QDomDocument &doc, QDomElement &element ) const;
163
170 virtual bool readProperties( const QDomElement &element );
171
178 virtual void render( const QPicture &picture, QgsRenderContext &context );
179
188 virtual void begin( QgsRenderContext &context );
189
196 virtual void end( QgsRenderContext &context );
197
203 bool enabled() const { return mEnabled; }
204
210 void setEnabled( bool enabled );
211
218 DrawMode drawMode() const { return mDrawMode; }
219
226 void setDrawMode( DrawMode drawMode );
227
228 protected:
229
230 bool mEnabled = true;
233
241 virtual void draw( QgsRenderContext &context ) = 0;
242
250 void drawSource( QPainter &painter );
251
259 const QPicture &source() const { return mPicture; }
260
272 QImage sourceAsImage( QgsRenderContext &context );
273
281 QPointF imageOffset( const QgsRenderContext &context ) const;
282
292 virtual QRectF boundingRect( const QRectF &rect, const QgsRenderContext &context ) const;
293
302 Q_DECL_DEPRECATED void fixQPictureDpi( QPainter *painter ) const SIP_DEPRECATED;
303
304 private:
305
306 QPicture mPicture;
307 QImage mSourceImage;
308
309 QPainter *mPrevPainter = nullptr;
310 std::unique_ptr< QPainter > mEffectPainter;
311 std::unique_ptr< QPicture > mTempPicture;
312
313 QRectF imageBoundingRect( const QgsRenderContext &context ) const;
314
315 friend class QgsEffectStack;
316
317 QgsPaintEffect &operator= ( const QgsPaintEffect & ) = delete;
318
319};
320
332
334{
335 public:
336
338
344 static QgsPaintEffect *create( const QVariantMap &map ) SIP_FACTORY;
345
346 Qgis::PaintEffectFlags flags() const override;
347 QString type() const override { return QStringLiteral( "drawSource" ); }
348 QgsDrawSourceEffect *clone() const override SIP_FACTORY;
349 QVariantMap properties() const override;
350 void readProperties( const QVariantMap &props ) override;
351
358 void setOpacity( const double opacity ) { mOpacity = opacity; }
359
366 double opacity() const { return mOpacity; }
367
374 void setBlendMode( const QPainter::CompositionMode mode ) { mBlendMode = mode; }
375
382 QPainter::CompositionMode blendMode() const { return mBlendMode; }
383
384 protected:
385
386 void draw( QgsRenderContext &context ) override;
387
388 private:
389
390 double mOpacity = 1.0;
391 QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
392};
393
400class CORE_EXPORT QgsEffectPainter
401{
402 public:
403
409 QgsEffectPainter( QgsRenderContext &renderContext );
410
417 QgsEffectPainter( QgsRenderContext &renderContext, QgsPaintEffect *effect );
419
425 void setEffect( QgsPaintEffect *effect );
426
428
433 QPainter *operator->() { return mPainter; }
435
436 private:
437#ifdef SIP_RUN
438 const QgsEffectPainter &operator=( const QgsEffectPainter & );
439#endif
440
441 QgsRenderContext &mRenderContext;
442 QPainter *mPainter = nullptr;
443 QgsPaintEffect *mEffect = nullptr;
444};
445
446#endif // QGSPAINTEFFECT_H
447
QFlags< PaintEffectFlag > PaintEffectFlags
Flags which control how paint effects behave.
Definition qgis.h:2815
A paint effect which blurs a source picture, using a number of different blur methods.
A paint effect which alters the colors (e.g., brightness, contrast) in a source picture.
A paint effect which draws the source picture with minor or no alterations.
QPainter::CompositionMode blendMode() const
Returns the blend mode for the effect.
void setBlendMode(const QPainter::CompositionMode mode)
Sets the blend mode for the effect.
QgsDrawSourceEffect()=default
double opacity() const
Returns the opacity for the effect.
void setOpacity(const double opacity)
Sets the opacity for the effect.
QString type() const override
Returns the effect type.
static QgsPaintEffect * create(const QVariantMap &map)
Creates a new QgsDrawSource effect from a properties string map.
Qgis::PaintEffectFlags flags() const override
Returns flags which specify how the paint effect behaves.
A paint effect which draws an offset and optionally blurred drop shadow.
QgsEffectPainter(QgsRenderContext &renderContext)
QgsEffectPainter constructor.
void setEffect(QgsPaintEffect *effect)
Sets the effect to be painted.
A paint effect which draws a glow within a picture.
A paint effect which draws a glow outside of a picture.
Base class for visual effects which can be applied to QPicture drawings.
QgsPaintEffect()=default
virtual bool saveProperties(QDomDocument &doc, QDomElement &element) const
Saves the current state of the effect to a DOM element.
void drawSource(QPainter &painter)
Draws the source QPicture onto the specified painter.
virtual void readProperties(const QVariantMap &props)=0
Reads a string map of an effect's properties and restores the effect to the state described by the pr...
virtual void begin(QgsRenderContext &context)
Begins intercepting paint operations to a render context.
const QPicture & source() const
Returns the source QPicture.
friend class QgsEffectStack
DrawMode drawMode() const
Returns the draw mode for the effect.
virtual void end(QgsRenderContext &context)
Ends interception of paint operations to a render context, and draws the result to the render context...
bool enabled() const
Returns whether the effect is enabled.
virtual Qgis::PaintEffectFlags flags() const
Returns flags which specify how the paint effect behaves.
virtual void render(const QPicture &picture, QgsRenderContext &context)
Renders a picture using the effect.
virtual QgsPaintEffect * clone() const =0
Duplicates an effect by creating a deep copy of the effect.
virtual QVariantMap properties() const =0
Returns the properties describing the paint effect encoded in a string format.
DrawMode
Drawing modes for effects.
@ Render
The result of the effect is rendered on the destination, but does not affect subsequent effects in th...
@ Modifier
The result of the effect is not rendered, but is passed on to following effects in the stack.
@ ModifyAndRender
The result of the effect is both rendered and passed on to subsequent effects in the stack.
virtual void draw(QgsRenderContext &context)=0
Handles drawing of the effect's result on to the specified render context.
virtual QString type() const =0
Returns the effect type.
Contains information about the context of a rendering operation.
A paint effect which applies transformations (such as move, scale and rotate) to a picture.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:199
#define SIP_DEPRECATED
Definition qgis_sip.h:114
#define SIP_FACTORY
Definition qgis_sip.h:84
#define SIP_NODEFAULTCTORS
Definition qgis_sip.h:109
#define SIP_END
Definition qgis_sip.h:216