QGIS/python/core/effects/qgspainteffect.sip

461 lines
12 KiB
Plaintext
Raw Normal View History

2017-05-23 14:33:31 +02:00
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/effects/qgspainteffect.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
class QgsPaintEffect
{
2017-05-23 14:33:31 +02:00
%Docstring
Base class for visual effects which can be applied to QPicture drawings
2017-12-15 10:36:55 -04:00
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.
2017-05-23 14:33:31 +02:00
2017-12-15 10:36:55 -04:00
To directly draw a picture, use the render() method with a source
QPicture and destination render context.
2017-05-23 14:33:31 +02:00
2017-12-15 10:36:55 -04:00
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.
2017-05-23 14:33:31 +02:00
2017-12-05 20:04:14 -04:00
.. seealso:: :py:class:`QgsPaintEffectRegistry`
2017-12-15 10:36:55 -04:00
2017-05-23 14:33:31 +02:00
.. versionadded:: 2.9
%End
%TypeHeaderCode
2017-05-23 14:33:31 +02:00
#include "qgspainteffect.h"
%End
%ConvertToSubClassCode
2017-05-23 14:33:31 +02:00
if ( sipCpp->type() == "drawSource" && dynamic_cast<QgsDrawSourceEffect *>( sipCpp ) != NULL )
{
sipType = sipType_QgsDrawSourceEffect;
}
else if ( sipCpp->type() == "effectStack" && dynamic_cast<QgsEffectStack *>( sipCpp ) != NULL )
{
sipType = sipType_QgsEffectStack;
}
else if ( sipCpp->type() == "blur" && dynamic_cast<QgsBlurEffect *>( sipCpp ) != NULL )
{
sipType = sipType_QgsBlurEffect;
}
else if ( sipCpp->type() == "dropShadow" && dynamic_cast<QgsDropShadowEffect *>( sipCpp ) != NULL )
{
sipType = sipType_QgsDropShadowEffect;
}
else if ( sipCpp->type() == "outerGlow" && dynamic_cast<QgsOuterGlowEffect *>( sipCpp ) != NULL )
{
sipType = sipType_QgsOuterGlowEffect;
}
else if ( sipCpp->type() == "innerGlow" && dynamic_cast<QgsInnerGlowEffect *>( sipCpp ) != NULL )
{
sipType = sipType_QgsInnerGlowEffect;
}
else if ( sipCpp->type() == "transform" && dynamic_cast<QgsTransformEffect *>( sipCpp ) != NULL )
{
sipType = sipType_QgsTransformEffect;
}
else if ( sipCpp->type() == "color" && dynamic_cast<QgsColorEffect *>( sipCpp ) != NULL )
{
sipType = sipType_QgsColorEffect;
}
else
{
sipType = 0;
}
%End
public:
enum DrawMode
{
2017-05-23 14:33:31 +02:00
Modifier,
Render,
ModifyAndRender
};
QgsPaintEffect();
%Docstring
2017-12-15 10:36:55 -04:00
Constructor for QgsPaintEffect.
%End
QgsPaintEffect( const QgsPaintEffect &other );
virtual ~QgsPaintEffect();
virtual QString type() const = 0;
2017-05-23 14:33:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Returns the effect type.
:return: unique string representation of the effect type
2017-05-23 14:33:31 +02:00
%End
virtual QgsPaintEffect *clone() const = 0 /Factory/;
2017-05-23 14:33:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Duplicates an effect by creating a deep copy of the effect
:return: clone of paint effect
2017-05-23 14:33:31 +02:00
%End
virtual QgsStringMap properties() const = 0;
2017-05-23 14:33:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Returns the properties describing the paint effect encoded in a
string format.
:return: string map of properties, in the form property key, value
2017-12-05 20:04:14 -04:00
.. seealso:: :py:func:`readProperties`
2017-12-15 10:36:55 -04:00
2017-12-05 20:04:14 -04:00
.. seealso:: :py:func:`saveProperties`
2017-05-23 14:33:31 +02:00
%End
virtual void readProperties( const QgsStringMap &props ) = 0;
2017-05-23 14:33:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Reads a string map of an effect's properties and restores the effect
to the state described by the properties map.
2017-12-15 21:36:08 -04:00
2017-12-15 10:36:55 -04:00
:param props: effect properties encoded in a string map
2017-12-05 20:04:14 -04:00
.. seealso:: :py:func:`properties`
2017-05-23 14:33:31 +02:00
%End
virtual bool saveProperties( QDomDocument &doc, QDomElement &element ) const;
2017-05-23 14:33:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Saves the current state of the effect to a DOM element. The default
behavior is to save the properties string map returned by
properties().
2017-12-15 21:36:08 -04:00
2017-12-15 10:36:55 -04:00
:param doc: destination DOM document
:param element: destination DOM element
:return: true if save was successful
2017-12-05 20:04:14 -04:00
.. seealso:: :py:func:`readProperties`
2017-05-23 14:33:31 +02:00
%End
virtual bool readProperties( const QDomElement &element );
2017-05-23 14:33:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Restores the effect to the state described by a DOM element.
2017-12-15 21:36:08 -04:00
2017-12-15 10:36:55 -04:00
:param element: DOM element describing an effect's state
:return: true if read was successful
2017-12-05 20:04:14 -04:00
.. seealso:: :py:func:`saveProperties`
2017-05-23 14:33:31 +02:00
%End
virtual void render( QPicture &picture, QgsRenderContext &context );
2017-05-23 14:33:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Renders a picture using the effect.
2017-12-15 21:36:08 -04:00
2017-12-15 10:36:55 -04:00
:param picture: source QPicture to render
:param context: destination render context
2017-12-05 20:04:14 -04:00
.. seealso:: :py:func:`begin`
2017-05-23 14:33:31 +02:00
%End
virtual void begin( QgsRenderContext &context );
2017-05-23 14:33:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
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.
2017-12-15 21:36:08 -04:00
2017-12-15 10:36:55 -04:00
:param context: destination render context
2017-12-05 20:04:14 -04:00
.. seealso:: :py:func:`end`
2017-12-15 10:36:55 -04:00
2017-12-05 20:04:14 -04:00
.. seealso:: :py:func:`render`
2017-05-23 14:33:31 +02:00
%End
virtual void end( QgsRenderContext &context );
2017-05-23 14:33:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Ends interception of paint operations to a render context, and draws the result
to the render context after being modified by the effect.
2017-12-15 21:36:08 -04:00
2017-12-15 10:36:55 -04:00
:param context: destination render context
2017-12-05 20:04:14 -04:00
.. seealso:: :py:func:`begin`
2017-05-23 14:33:31 +02:00
%End
bool enabled() const;
2017-05-23 14:33:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Returns whether the effect is enabled
:return: true if effect is enabled
2017-12-05 20:04:14 -04:00
.. seealso:: :py:func:`setEnabled`
2017-05-23 14:33:31 +02:00
%End
void setEnabled( const bool enabled );
2017-05-23 14:33:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Sets whether the effect is enabled
2017-12-15 21:36:08 -04:00
2017-12-15 10:36:55 -04:00
:param enabled: set to false to disable the effect
2017-12-05 20:04:14 -04:00
.. seealso:: :py:func:`enabled`
2017-05-23 14:33:31 +02:00
%End
DrawMode drawMode() const;
2017-05-23 14:33:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Returns the draw mode for the effect. This property only has an
2017-12-19 11:43:52 -04:00
effect if the paint effect is used in a :py:class:`QgsEffectStack`.
2017-12-15 10:36:55 -04:00
:return: draw mode for effect
2017-12-05 20:04:14 -04:00
.. seealso:: :py:func:`setDrawMode`
2017-05-23 14:33:31 +02:00
%End
void setDrawMode( const DrawMode drawMode );
2017-05-23 14:33:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Sets the draw mode for the effect. This property only has an
2017-12-19 11:43:52 -04:00
effect if the paint effect is used in a :py:class:`QgsEffectStack`.
2017-12-15 21:36:08 -04:00
2017-12-15 10:36:55 -04:00
:param drawMode: draw mode for effect
2017-12-05 20:04:14 -04:00
.. seealso:: :py:func:`drawMode`
2017-05-23 14:33:31 +02:00
%End
protected:
2017-05-23 14:33:31 +02:00
virtual void draw( QgsRenderContext &context ) = 0;
2017-05-23 14:33:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
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.
2017-12-15 21:36:08 -04:00
2017-12-15 10:36:55 -04:00
:param context: destination render context
2017-12-05 20:04:14 -04:00
.. seealso:: :py:func:`drawSource`
2017-05-23 14:33:31 +02:00
%End
void drawSource( QPainter &painter );
2017-05-23 14:33:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Draws the source QPicture onto the specified painter. Handles scaling of the picture
to account for the destination painter's DPI.
2017-12-15 21:36:08 -04:00
2017-12-15 10:36:55 -04:00
:param painter: destination painter
2017-12-05 20:04:14 -04:00
.. seealso:: :py:func:`source`
2017-12-15 10:36:55 -04:00
2017-12-05 20:04:14 -04:00
.. seealso:: :py:func:`sourceAsImage`
2017-05-23 14:33:31 +02:00
%End
const QPicture *source() const;
2017-05-23 14:33:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Returns the source QPicture. The draw() member can utilize this when
drawing the effect.
:return: source QPicture
2017-12-05 20:04:14 -04:00
.. seealso:: :py:func:`drawSource`
2017-12-15 10:36:55 -04:00
2017-12-05 20:04:14 -04:00
.. seealso:: :py:func:`sourceAsImage`
2017-05-23 14:33:31 +02:00
%End
QImage *sourceAsImage( QgsRenderContext &context );
2017-05-23 14:33:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
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.
:return: source QPicture rendered to an image
2017-12-05 20:04:14 -04:00
.. seealso:: :py:func:`drawSource`
2017-12-15 10:36:55 -04:00
2017-12-05 20:04:14 -04:00
.. seealso:: :py:func:`source`
2017-12-15 10:36:55 -04:00
2017-12-05 20:04:14 -04:00
.. seealso:: :py:func:`imageOffset`
2017-12-15 10:36:55 -04:00
2017-12-05 20:04:14 -04:00
.. seealso:: :py:func:`boundingRect`
2017-05-23 14:33:31 +02:00
%End
QPointF imageOffset( const QgsRenderContext &context ) const;
2017-05-23 14:33:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Returns the offset which should be used when drawing the source image on to a destination
render context.
2017-12-15 21:36:08 -04:00
2017-12-15 10:36:55 -04:00
:param context: destination render context
:return: point offset for image top left corner
2017-12-05 20:04:14 -04:00
.. seealso:: :py:func:`sourceAsImage`
2017-05-23 14:33:31 +02:00
%End
virtual QRectF boundingRect( const QRectF &rect, const QgsRenderContext &context ) const;
2017-05-23 14:33:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
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.
2017-12-15 21:36:08 -04:00
2017-12-15 10:36:55 -04:00
:param rect: original source bounding rect
:param context: destination render context
:return: modified bounding rect
2017-12-05 20:04:14 -04:00
.. seealso:: :py:func:`sourceAsImage`
2017-05-23 14:33:31 +02:00
%End
void fixQPictureDpi( QPainter *painter ) const;
2017-05-23 14:33:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
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.
2017-12-15 21:36:08 -04:00
2017-12-15 10:36:55 -04:00
:param painter: destination painter
2017-05-23 14:33:31 +02:00
%End
};
class QgsDrawSourceEffect : QgsPaintEffect
{
2017-05-23 14:33:31 +02:00
%Docstring
A paint effect which draws the source picture with minor or no alterations
2017-12-15 10:36:55 -04:00
The draw source effect can be used to draw an unaltered copy of the original source
picture. Minor changes like lowering the opacity and applying a blend mode are
supported, however these changes will force the resultant output to be rasterized.
If no alterations are performed then the original picture will be rendered as a vector.
2017-05-23 14:33:31 +02:00
.. versionadded:: 2.9
%End
2017-05-23 14:33:31 +02:00
%TypeHeaderCode
#include "qgspainteffect.h"
%End
public:
QgsDrawSourceEffect();
2017-11-11 11:29:45 +10:00
%Docstring
Constructor for QgsDrawSourceEffect
%End
static QgsPaintEffect *create( const QgsStringMap &map ) /Factory/;
2017-05-23 14:33:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Creates a new QgsDrawSource effect from a properties string map.
2017-12-15 21:36:08 -04:00
2017-12-15 10:36:55 -04:00
:param map: encoded properties string map
:return: new QgsDrawSourceEffect
2017-05-23 14:33:31 +02:00
%End
virtual QString type() const;
virtual QgsDrawSourceEffect *clone() const /Factory/;
virtual QgsStringMap properties() const;
virtual void readProperties( const QgsStringMap &props );
void setOpacity( const double opacity );
2017-05-23 14:33:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Sets the ``opacity`` for the effect.
2017-12-15 21:36:08 -04:00
2017-12-15 10:36:55 -04:00
:param opacity: double between 0 and 1 inclusive, where 0 is fully transparent
and 1 is fully opaque
2017-12-05 20:04:14 -04:00
.. seealso:: :py:func:`opacity()`
2017-05-23 14:33:31 +02:00
%End
double opacity() const;
2017-05-23 14:33:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Returns the opacity for the effect
:return: opacity value between 0 and 1 inclusive, where 0 is fully transparent
and 1 is fully opaque
2017-12-05 20:04:14 -04:00
.. seealso:: :py:func:`setOpacity()`
2017-05-23 14:33:31 +02:00
%End
void setBlendMode( const QPainter::CompositionMode mode );
2017-05-23 14:33:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Sets the blend mode for the effect
2017-12-15 21:36:08 -04:00
2017-12-15 10:36:55 -04:00
:param mode: blend mode used for drawing the source on to a destination
paint device
2017-12-05 20:04:14 -04:00
.. seealso:: :py:func:`blendMode`
2017-05-23 14:33:31 +02:00
%End
QPainter::CompositionMode blendMode() const;
2017-05-23 14:33:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Returns the blend mode for the effect
:return: blend mode used for drawing the source on to a destination
paint device
2017-12-05 20:04:14 -04:00
.. seealso:: :py:func:`setBlendMode`
2017-05-23 14:33:31 +02:00
%End
2015-04-07 14:27:39 +02:00
protected:
virtual void draw( QgsRenderContext &context );
};
class QgsEffectPainter
{
2017-05-23 14:33:31 +02:00
%Docstring
A class to manager painter saving and restoring required for effect drawing
.. versionadded:: 3.0
%End
%TypeHeaderCode
2017-05-23 14:33:31 +02:00
#include "qgspainteffect.h"
%End
public:
QgsEffectPainter( QgsRenderContext &renderContext );
2017-05-23 14:33:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
QgsEffectPainter constructor
:param renderContext: the QgsRenderContext object
2017-05-23 14:33:31 +02:00
.. versionadded:: 3.0
%End
QgsEffectPainter( QgsRenderContext &renderContext, QgsPaintEffect *effect );
2017-05-23 14:33:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
QgsEffectPainter constructor alternative if no painter translation is needed
:param renderContext: the QgsRenderContext object
:param effect: the QgsPaintEffect object
2017-05-23 14:33:31 +02:00
.. versionadded:: 3.0
%End
~QgsEffectPainter();
void setEffect( QgsPaintEffect *effect );
2017-05-23 14:33:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Sets the effect to be painted
2017-05-23 14:33:31 +02:00
2017-12-15 10:36:55 -04:00
:param effect: the QgsPaintEffect object
2017-05-23 14:33:31 +02:00
%End
};
2017-05-23 14:33:31 +02:00
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/effects/qgspainteffect.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/