QGIS API Documentation 3.41.0-Master (25ec5511245)
|
Base class for visual effects which can be applied to QPicture drawings. More...
#include <qgspainteffect.h>
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 QgsPaintEffect * | clone () 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 |
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.
Definition at line 51 of file qgspainteffect.h.
Drawing modes for effects.
These modes are used only when effects are drawn as part of an effects stack
Definition at line 102 of file qgspainteffect.h.
|
default |
QgsPaintEffect::QgsPaintEffect | ( | const QgsPaintEffect & | other | ) |
Definition at line 27 of file qgspainteffect.cpp.
|
virtual |
Definition at line 34 of file qgspainteffect.cpp.
|
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.
context | destination render context |
Definition at line 89 of file qgspainteffect.cpp.
|
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.
rect | original source bounding rect |
context | destination render context |
Reimplemented in QgsBlurEffect, QgsGlowEffect, QgsShadowEffect, and QgsTransformEffect.
Definition at line 172 of file qgspainteffect.cpp.
|
pure virtual |
Duplicates an effect by creating a deep copy of the effect.
Implemented in QgsBlurEffect, QgsColorEffect, QgsEffectStack, QgsOuterGlowEffect, QgsInnerGlowEffect, QgsDrawSourceEffect, QgsDropShadowEffect, QgsInnerShadowEffect, and QgsTransformEffect.
|
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.
context | destination render context |
Implemented in QgsBlurEffect, QgsColorEffect, QgsEffectStack, QgsGlowEffect, QgsDrawSourceEffect, QgsShadowEffect, and QgsTransformEffect.
|
inline |
Returns the draw mode for the effect.
This property only has an effect if the paint effect is used in a QgsEffectStack.
Definition at line 208 of file qgspainteffect.h.
|
protected |
Draws the source QPicture onto the specified painter.
Handles scaling of the picture to account for the destination painter's DPI.
painter | destination painter |
Definition at line 130 of file qgspainteffect.cpp.
|
inline |
Returns whether the effect is enabled.
true
if effect is enabled Definition at line 193 of file qgspainteffect.h.
|
virtual |
Ends interception of paint operations to a render context, and draws the result to the render context after being modified by the effect.
context | destination render context |
Definition at line 104 of file qgspainteffect.cpp.
|
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.
painter | destination painter |
Definition at line 178 of file qgspainteffect.cpp.
|
protected |
Returns the offset which should be used when drawing the source image on to a destination render context.
context | destination render context |
Definition at line 167 of file qgspainteffect.cpp.
|
pure virtual |
Returns the properties describing the paint effect encoded in a string format.
Implemented in QgsBlurEffect, QgsColorEffect, QgsEffectStack, QgsGlowEffect, QgsDrawSourceEffect, QgsShadowEffect, and QgsTransformEffect.
|
virtual |
Restores the effect to the state described by a DOM element.
element | DOM element describing an effect's state |
true
if read was successful Reimplemented in QgsEffectStack.
Definition at line 67 of file qgspainteffect.cpp.
|
pure virtual |
Reads a string map of an effect's properties and restores the effect to the state described by the properties map.
props | effect properties encoded in a string map |
Implemented in QgsBlurEffect, QgsColorEffect, QgsEffectStack, QgsGlowEffect, QgsDrawSourceEffect, QgsShadowEffect, and QgsTransformEffect.
|
virtual |
Renders a picture using the effect.
picture | source QPicture to render |
context | destination render context |
Definition at line 79 of file qgspainteffect.cpp.
|
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().
doc | destination DOM document |
element | destination DOM element |
true
if save was successful Reimplemented in QgsEffectStack.
Definition at line 54 of file qgspainteffect.cpp.
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.
drawMode | draw mode for effect |
Definition at line 49 of file qgspainteffect.cpp.
void QgsPaintEffect::setEnabled | ( | bool | enabled | ) |
Sets whether the effect is enabled.
enabled | set to false to disable the effect |
Definition at line 44 of file qgspainteffect.cpp.
|
inlineprotected |
Returns the source QPicture.
The draw() member can utilize this when drawing the effect.
Definition at line 249 of file qgspainteffect.h.
|
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.
Definition at line 142 of file qgspainteffect.cpp.
|
pure virtual |
Returns the effect type.
Implemented in QgsBlurEffect, QgsColorEffect, QgsEffectStack, QgsOuterGlowEffect, QgsInnerGlowEffect, QgsDrawSourceEffect, QgsDropShadowEffect, QgsInnerShadowEffect, and QgsTransformEffect.
|
friend |
Definition at line 306 of file qgspainteffect.h.
|
protected |
Definition at line 221 of file qgspainteffect.h.
|
protected |
Definition at line 220 of file qgspainteffect.h.
|
protected |
Definition at line 222 of file qgspainteffect.h.