QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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#include <QString>
29
30using namespace Qt::StringLiterals;
31
33
56
58{
59#ifdef SIP_RUN
61 if ( sipCpp->type() == "drawSource" && dynamic_cast<QgsDrawSourceEffect *>( sipCpp ) != NULL )
62 {
63 sipType = sipType_QgsDrawSourceEffect;
64 }
65 else if ( sipCpp->type() == "effectStack" && dynamic_cast<QgsEffectStack *>( sipCpp ) != NULL )
66 {
67 sipType = sipType_QgsEffectStack;
68 }
69 else if ( sipCpp->type() == "blur" && dynamic_cast<QgsBlurEffect *>( sipCpp ) != NULL )
70 {
71 sipType = sipType_QgsBlurEffect;
72 }
73 else if ( sipCpp->type() == "dropShadow" && dynamic_cast<QgsDropShadowEffect *>( sipCpp ) != NULL )
74 {
75 sipType = sipType_QgsDropShadowEffect;
76 }
77 else if ( sipCpp->type() == "outerGlow" && dynamic_cast<QgsOuterGlowEffect *>( sipCpp ) != NULL )
78 {
79 sipType = sipType_QgsOuterGlowEffect;
80 }
81 else if ( sipCpp->type() == "innerGlow" && dynamic_cast<QgsInnerGlowEffect *>( sipCpp ) != NULL )
82 {
83 sipType = sipType_QgsInnerGlowEffect;
84 }
85 else if ( sipCpp->type() == "transform" && dynamic_cast<QgsTransformEffect *>( sipCpp ) != NULL )
86 {
87 sipType = sipType_QgsTransformEffect;
88 }
89 else if ( sipCpp->type() == "color" && dynamic_cast<QgsColorEffect *>( sipCpp ) != NULL )
90 {
91 sipType = sipType_QgsColorEffect;
92 }
93 else
94 {
95 sipType = 0;
96 }
98#endif
99
100 public:
112
113 QgsPaintEffect() = default;
114
115 QgsPaintEffect( const QgsPaintEffect &other );
116 virtual ~QgsPaintEffect();
117
122 virtual QString type() const = 0;
123
128 virtual QgsPaintEffect *clone() const = 0 SIP_FACTORY;
129
135 virtual Qgis::PaintEffectFlags flags() const;
136
144 virtual QVariantMap properties() const = 0;
145
152 virtual void readProperties( const QVariantMap &props ) = 0;
153
163 virtual bool saveProperties( QDomDocument &doc, QDomElement &element ) const;
164
171 virtual bool readProperties( const QDomElement &element );
172
179 virtual void render( const QPicture &picture, QgsRenderContext &context );
180
189 virtual void begin( QgsRenderContext &context );
190
197 virtual void end( QgsRenderContext &context );
198
204 bool enabled() const { return mEnabled; }
205
211 void setEnabled( bool enabled );
212
219 DrawMode drawMode() const { return mDrawMode; }
220
227 void setDrawMode( DrawMode drawMode );
228
229 protected:
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 QPicture mPicture;
306 QImage mSourceImage;
307
308 QPainter *mPrevPainter = nullptr;
309 std::unique_ptr< QPainter > mEffectPainter;
310 std::unique_ptr< QPicture > mTempPicture;
311
312 QRectF imageBoundingRect( const QgsRenderContext &context ) const;
313
314 friend class QgsEffectStack;
315
316 QgsPaintEffect &operator=( const QgsPaintEffect & ) = delete;
317};
318
330
332{
333 public:
335
341 static QgsPaintEffect *create( const QVariantMap &map ) SIP_FACTORY;
342
343 Qgis::PaintEffectFlags flags() const override;
344 QString type() const override { return u"drawSource"_s; }
345 QgsDrawSourceEffect *clone() const override SIP_FACTORY;
346 QVariantMap properties() const override;
347
348 using QgsPaintEffect::readProperties;
349 void readProperties( const QVariantMap &props ) override;
350
357 void setOpacity( const double opacity ) { mOpacity = opacity; }
358
365 double opacity() const { return mOpacity; }
366
373 void setBlendMode( const QPainter::CompositionMode mode ) { mBlendMode = mode; }
374
381 QPainter::CompositionMode blendMode() const { return mBlendMode; }
382
383 protected:
384 void draw( QgsRenderContext &context ) override;
385
386 private:
387 double mOpacity = 1.0;
388 QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
389};
390
397class CORE_EXPORT QgsEffectPainter
398{
399 public:
405 QgsEffectPainter( QgsRenderContext &renderContext );
406
413 QgsEffectPainter( QgsRenderContext &renderContext, QgsPaintEffect *effect );
415
421 void setEffect( QgsPaintEffect *effect );
422
424
429 QPainter *operator->() { return mPainter; }
431
432 private:
433#ifdef SIP_RUN
434 const QgsEffectPainter &operator=( const QgsEffectPainter & );
435#endif
436
437 QgsRenderContext &mRenderContext;
438 QPainter *mPainter = nullptr;
439 QgsPaintEffect *mEffect = nullptr;
440};
441
442#endif // QGSPAINTEFFECT_H
QFlags< PaintEffectFlag > PaintEffectFlags
Flags which control how paint effects behave.
Definition qgis.h:2912
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:198
#define SIP_DEPRECATED
Definition qgis_sip.h:113
#define SIP_FACTORY
Definition qgis_sip.h:83
#define SIP_NODEFAULTCTORS
Definition qgis_sip.h:108
#define SIP_END
Definition qgis_sip.h:215