QGIS API Documentation 3.41.0-Master (3291e9ff48b)
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
QgsPaintEffect Class Referenceabstract

Base class for visual effects which can be applied to QPicture drawings. More...

#include <qgspainteffect.h>

Inheritance diagram for QgsPaintEffect:
Inheritance graph
[legend]

Public Types

enum  DrawMode { Modifier , Render , ModifyAndRender }
 Drawing modes for effects. More...
 

Public Member Functions

 QgsPaintEffect ()=default
 
 QgsPaintEffect (const QgsPaintEffect &other)
 
virtual ~QgsPaintEffect ()
 
virtual void begin (QgsRenderContext &context)
 Begins intercepting paint operations to a render context.
 
virtual QgsPaintEffectclone () const =0
 Duplicates an effect by creating a deep copy of the effect.
 
DrawMode drawMode () const
 Returns the draw mode for the effect.
 
bool enabled () const
 Returns whether the effect is enabled.
 
virtual void end (QgsRenderContext &context)
 Ends interception of paint operations to a render context, and draws the result to the render context after being modified by the effect.
 
virtual QVariantMap properties () const =0
 Returns the properties describing the paint effect encoded in a string format.
 
virtual bool readProperties (const QDomElement &element)
 Restores the effect to the state described by a DOM element.
 
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 properties map.
 
virtual void render (QPicture &picture, QgsRenderContext &context)
 Renders a picture using the effect.
 
virtual bool saveProperties (QDomDocument &doc, QDomElement &element) const
 Saves the current state of the effect to a DOM element.
 
void setDrawMode (DrawMode drawMode)
 Sets the draw mode for the effect.
 
void setEnabled (bool enabled)
 Sets whether the effect is enabled.
 
virtual QString type () const =0
 Returns the effect type.
 

Protected Member Functions

virtual QRectF boundingRect (const QRectF &rect, const QgsRenderContext &context) const
 Returns the bounding rect required for drawing the effect.
 
virtual void draw (QgsRenderContext &context)=0
 Handles drawing of the effect's result on to the specified render context.
 
void drawSource (QPainter &painter)
 Draws the source QPicture onto the specified painter.
 
Q_DECL_DEPRECATED void fixQPictureDpi (QPainter *painter) const
 Applies a workaround to a QPainter to avoid an issue with incorrect scaling when drawing QPictures.
 
QPointF imageOffset (const QgsRenderContext &context) const
 Returns the offset which should be used when drawing the source image on to a destination render context.
 
const QPicture * source () const
 Returns the source QPicture.
 
QImage * sourceAsImage (QgsRenderContext &context)
 Returns the source QPicture rendered to a new QImage.
 

Protected Attributes

DrawMode mDrawMode = ModifyAndRender
 
bool mEnabled = true
 
bool requiresQPainterDpiFix = true
 

Friends

class QgsEffectStack
 

Detailed Description

Base class for visual effects which can be applied to QPicture drawings.

QgsPaintEffect objects can be used to modify QPicture drawings prior to rendering them with a QPainter operation. There are two methods for drawing using an effect, either drawing a picture directly, or by intercepting drawing operations to a render context.

To directly draw a picture, use the render() method with a source QPicture and destination render context.

Intercepting drawing operations to a render context is achieved by first calling the begin() method, passing a render context. Any drawing operations performed on the render context will not directly affect the context's paint device. When the drawing operations have been completed, call the end() method. This will perform the paint effect on the intercepted drawing operations and render the result to the render context's paint device.

See also
QgsPaintEffectRegistry

Definition at line 51 of file qgspainteffect.h.

Member Enumeration Documentation

◆ DrawMode

Drawing modes for effects.

These modes are used only when effects are drawn as part of an effects stack

See also
QgsEffectStack
Enumerator
Modifier 

The result of the effect is not rendered, but is passed on to following effects in the stack.

Render 

The result of the effect is rendered on the destination, but does not affect subsequent effects in the stack.

ModifyAndRender 

The result of the effect is both rendered and passed on to subsequent effects in the stack.

Definition at line 102 of file qgspainteffect.h.

Constructor & Destructor Documentation

◆ QgsPaintEffect() [1/2]

QgsPaintEffect::QgsPaintEffect ( )
default

◆ QgsPaintEffect() [2/2]

QgsPaintEffect::QgsPaintEffect ( const QgsPaintEffect other)

Definition at line 27 of file qgspainteffect.cpp.

◆ ~QgsPaintEffect()

QgsPaintEffect::~QgsPaintEffect ( )
virtual

Definition at line 34 of file qgspainteffect.cpp.

Member Function Documentation

◆ begin()

void QgsPaintEffect::begin ( QgsRenderContext context)
virtual

Begins intercepting paint operations to a render context.

When the corresponding end() member is called all intercepted paint operations will be drawn to the render context after being modified by the effect.

Parameters
contextdestination render context
See also
end
render

Definition at line 89 of file qgspainteffect.cpp.

◆ boundingRect()

QRectF QgsPaintEffect::boundingRect ( const QRectF &  rect,
const QgsRenderContext context 
) const
protectedvirtual

Returns the bounding rect required for drawing the effect.

This method can be used to expand the bounding rect of a source picture to account for offset or blurring effects.

Parameters
rectoriginal source bounding rect
contextdestination render context
Returns
modified bounding rect
See also
sourceAsImage

Reimplemented in QgsBlurEffect, QgsGlowEffect, QgsShadowEffect, and QgsTransformEffect.

Definition at line 172 of file qgspainteffect.cpp.

◆ clone()

virtual QgsPaintEffect * QgsPaintEffect::clone ( ) const
pure virtual

Duplicates an effect by creating a deep copy of the effect.

Returns
clone of paint effect

Implemented in QgsBlurEffect, QgsColorEffect, QgsEffectStack, QgsOuterGlowEffect, QgsInnerGlowEffect, QgsDrawSourceEffect, QgsDropShadowEffect, QgsInnerShadowEffect, and QgsTransformEffect.

◆ draw()

virtual void QgsPaintEffect::draw ( QgsRenderContext context)
protectedpure virtual

Handles drawing of the effect's result on to the specified render context.

Derived classes must reimplement this method to apply any transformations to the source QPicture and draw the result using the context's painter.

Parameters
contextdestination render context
See also
drawSource

Implemented in QgsBlurEffect, QgsColorEffect, QgsEffectStack, QgsGlowEffect, QgsDrawSourceEffect, QgsShadowEffect, and QgsTransformEffect.

◆ drawMode()

DrawMode QgsPaintEffect::drawMode ( ) const
inline

Returns the draw mode for the effect.

This property only has an effect if the paint effect is used in a QgsEffectStack.

Returns
draw mode for effect
See also
setDrawMode

Definition at line 208 of file qgspainteffect.h.

◆ drawSource()

void QgsPaintEffect::drawSource ( QPainter &  painter)
protected

Draws the source QPicture onto the specified painter.

Handles scaling of the picture to account for the destination painter's DPI.

Parameters
painterdestination painter
See also
source
sourceAsImage

Definition at line 130 of file qgspainteffect.cpp.

◆ enabled()

bool QgsPaintEffect::enabled ( ) const
inline

Returns whether the effect is enabled.

Returns
true if effect is enabled
See also
setEnabled

Definition at line 193 of file qgspainteffect.h.

◆ end()

void QgsPaintEffect::end ( QgsRenderContext context)
virtual

Ends interception of paint operations to a render context, and draws the result to the render context after being modified by the effect.

Parameters
contextdestination render context
See also
begin

Definition at line 104 of file qgspainteffect.cpp.

◆ fixQPictureDpi()

void QgsPaintEffect::fixQPictureDpi ( QPainter *  painter) const
protected

Applies a workaround to a QPainter to avoid an issue with incorrect scaling when drawing QPictures.

This may need to be called by derived classes prior to rendering results onto a painter.

Parameters
painterdestination painter
Deprecated:
QGIS 3.40. Use QgsPainting::drawPicture() or QgsPainting::applyScaleFixForQPictureDpi() instead.

Definition at line 178 of file qgspainteffect.cpp.

◆ imageOffset()

QPointF QgsPaintEffect::imageOffset ( const QgsRenderContext context) const
protected

Returns the offset which should be used when drawing the source image on to a destination render context.

Parameters
contextdestination render context
Returns
point offset for image top left corner
See also
sourceAsImage

Definition at line 167 of file qgspainteffect.cpp.

◆ properties()

virtual QVariantMap QgsPaintEffect::properties ( ) const
pure virtual

Returns the properties describing the paint effect encoded in a string format.

Returns
string map of properties, in the form property key, value
See also
readProperties
saveProperties

Implemented in QgsBlurEffect, QgsColorEffect, QgsEffectStack, QgsGlowEffect, QgsDrawSourceEffect, QgsShadowEffect, and QgsTransformEffect.

◆ readProperties() [1/2]

bool QgsPaintEffect::readProperties ( const QDomElement &  element)
virtual

Restores the effect to the state described by a DOM element.

Parameters
elementDOM element describing an effect's state
Returns
true if read was successful
See also
saveProperties

Reimplemented in QgsEffectStack.

Definition at line 67 of file qgspainteffect.cpp.

◆ readProperties() [2/2]

virtual void QgsPaintEffect::readProperties ( const QVariantMap &  props)
pure virtual

Reads a string map of an effect's properties and restores the effect to the state described by the properties map.

Parameters
propseffect properties encoded in a string map
See also
properties

Implemented in QgsBlurEffect, QgsColorEffect, QgsEffectStack, QgsGlowEffect, QgsDrawSourceEffect, QgsShadowEffect, and QgsTransformEffect.

◆ render()

void QgsPaintEffect::render ( QPicture &  picture,
QgsRenderContext context 
)
virtual

Renders a picture using the effect.

Parameters
picturesource QPicture to render
contextdestination render context
See also
begin

Definition at line 79 of file qgspainteffect.cpp.

◆ saveProperties()

bool QgsPaintEffect::saveProperties ( QDomDocument &  doc,
QDomElement &  element 
) const
virtual

Saves the current state of the effect to a DOM element.

The default behavior is to save the properties string map returned by properties().

Parameters
docdestination DOM document
elementdestination DOM element
Returns
true if save was successful
See also
readProperties

Reimplemented in QgsEffectStack.

Definition at line 54 of file qgspainteffect.cpp.

◆ setDrawMode()

void QgsPaintEffect::setDrawMode ( const QgsPaintEffect::DrawMode  drawMode)

Sets the draw mode for the effect.

This property only has an effect if the paint effect is used in a QgsEffectStack.

Parameters
drawModedraw mode for effect
See also
drawMode

Definition at line 49 of file qgspainteffect.cpp.

◆ setEnabled()

void QgsPaintEffect::setEnabled ( bool  enabled)

Sets whether the effect is enabled.

Parameters
enabledset to false to disable the effect
See also
enabled

Definition at line 44 of file qgspainteffect.cpp.

◆ source()

const QPicture * QgsPaintEffect::source ( ) const
inlineprotected

Returns the source QPicture.

The draw() member can utilize this when drawing the effect.

Returns
source QPicture
See also
drawSource
sourceAsImage

Definition at line 249 of file qgspainteffect.h.

◆ sourceAsImage()

QImage * QgsPaintEffect::sourceAsImage ( QgsRenderContext context)
protected

Returns the source QPicture rendered to a new QImage.

The draw() member can utilize this when drawing the effect. The image will be padded or cropped from the original source QPicture by the results of the boundingRect() method. The result is cached to speed up subsequent calls to sourceAsImage.

Returns
source QPicture rendered to an image
See also
drawSource
source
imageOffset
boundingRect

Definition at line 142 of file qgspainteffect.cpp.

◆ type()

virtual QString QgsPaintEffect::type ( ) const
pure virtual

Returns the effect type.

Returns
unique string representation of the effect type

Implemented in QgsBlurEffect, QgsColorEffect, QgsEffectStack, QgsOuterGlowEffect, QgsInnerGlowEffect, QgsDrawSourceEffect, QgsDropShadowEffect, QgsInnerShadowEffect, and QgsTransformEffect.

Friends And Related Symbol Documentation

◆ QgsEffectStack

friend class QgsEffectStack
friend

Definition at line 306 of file qgspainteffect.h.

Member Data Documentation

◆ mDrawMode

DrawMode QgsPaintEffect::mDrawMode = ModifyAndRender
protected

Definition at line 221 of file qgspainteffect.h.

◆ mEnabled

bool QgsPaintEffect::mEnabled = true
protected

Definition at line 220 of file qgspainteffect.h.

◆ requiresQPainterDpiFix

bool QgsPaintEffect::requiresQPainterDpiFix = true
protected

Definition at line 222 of file qgspainteffect.h.


The documentation for this class was generated from the following files: