QGIS API Documentation
3.4.15-Madeira (e83d02e274)
|
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 | |
Constructor for QgsPaintEffect. More... | |
QgsPaintEffect (const QgsPaintEffect &other) | |
virtual | ~QgsPaintEffect () |
virtual void | begin (QgsRenderContext &context) |
Begins intercepting paint operations to a render context. More... | |
virtual QgsPaintEffect * | clone () const =0 |
Duplicates an effect by creating a deep copy of the effect. More... | |
DrawMode | drawMode () const |
Returns the draw mode for the effect. More... | |
bool | enabled () const |
Returns whether the effect is enabled. More... | |
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. More... | |
virtual QgsStringMap | properties () const =0 |
Returns the properties describing the paint effect encoded in a string format. More... | |
virtual void | readProperties (const QgsStringMap &props)=0 |
Reads a string map of an effect's properties and restores the effect to the state described by the properties map. More... | |
virtual bool | readProperties (const QDomElement &element) |
Restores the effect to the state described by a DOM element. More... | |
virtual void | render (QPicture &picture, QgsRenderContext &context) |
Renders a picture using the effect. More... | |
virtual bool | saveProperties (QDomDocument &doc, QDomElement &element) const |
Saves the current state of the effect to a DOM element. More... | |
void | setDrawMode (DrawMode drawMode) |
Sets the draw mode for the effect. More... | |
void | setEnabled (bool enabled) |
Sets whether the effect is enabled. More... | |
virtual QString | type () const =0 |
Returns the effect type. More... | |
Protected Member Functions | |
virtual QRectF | boundingRect (const QRectF &rect, const QgsRenderContext &context) const |
Returns the bounding rect required for drawing the effect. More... | |
virtual void | draw (QgsRenderContext &context)=0 |
Handles drawing of the effect's result on to the specified render context. More... | |
void | drawSource (QPainter &painter) |
Draws the source QPicture onto the specified painter. More... | |
void | fixQPictureDpi (QPainter *painter) const |
Applies a workaround to a QPainter to avoid an issue with incorrect scaling when drawing QPictures. More... | |
QPointF | imageOffset (const QgsRenderContext &context) const |
Returns the offset which should be used when drawing the source image on to a destination render context. More... | |
const QPicture * | source () const |
Returns the source QPicture. More... | |
QImage * | sourceAsImage (QgsRenderContext &context) |
Returns the source QPicture rendered to a new QImage. More... | |
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 52 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 103 of file qgspainteffect.h.
|
default |
Constructor for QgsPaintEffect.
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 117 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 QgsGlowEffect, QgsTransformEffect, QgsShadowEffect, and QgsBlurEffect.
Definition at line 203 of file qgspainteffect.cpp.
|
pure virtual |
Duplicates an effect by creating a deep copy of the effect.
Implemented in QgsInnerGlowEffect, QgsDrawSourceEffect, QgsOuterGlowEffect, QgsInnerShadowEffect, QgsDropShadowEffect, QgsEffectStack, QgsBlurEffect, QgsTransformEffect, and QgsColorEffect.
|
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 QgsDrawSourceEffect, QgsGlowEffect, QgsTransformEffect, QgsShadowEffect, QgsColorEffect, QgsBlurEffect, and QgsEffectStack.
|
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 212 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 158 of file qgspainteffect.cpp.
|
inline |
Returns whether the effect is enabled.
Definition at line 197 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 132 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 209 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 198 of file qgspainteffect.cpp.
|
pure virtual |
Returns the properties describing the paint effect encoded in a string format.
Implemented in QgsDrawSourceEffect, QgsEffectStack, QgsBlurEffect, QgsGlowEffect, QgsTransformEffect, QgsColorEffect, and QgsShadowEffect.
|
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 QgsDrawSourceEffect, QgsEffectStack, QgsBlurEffect, QgsGlowEffect, QgsTransformEffect, QgsColorEffect, and QgsShadowEffect.
|
virtual |
Restores the effect to the state described by a DOM element.
element | DOM element describing an effect's state |
Reimplemented in QgsEffectStack.
Definition at line 77 of file qgspainteffect.cpp.
|
virtual |
Renders a picture using the effect.
picture | source QPicture to render |
context | destination render context |
Definition at line 107 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 |
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 253 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 173 of file qgspainteffect.cpp.
|
pure virtual |
Returns the effect type.
Implemented in QgsInnerGlowEffect, QgsDrawSourceEffect, QgsOuterGlowEffect, QgsInnerShadowEffect, QgsDropShadowEffect, QgsEffectStack, QgsBlurEffect, QgsTransformEffect, and QgsColorEffect.
|
friend |
Definition at line 308 of file qgspainteffect.h.
|
protected |
Definition at line 225 of file qgspainteffect.h.
|
protected |
Definition at line 224 of file qgspainteffect.h.
|
protected |
Definition at line 226 of file qgspainteffect.h.