29 : mEnabled( other.enabled() )
30 , mDrawMode( other.drawMode() )
41 delete mEffectPainter;
57 if ( element.isNull() )
61 QDomElement effectElement = doc.createElement( QStringLiteral(
"effect" ) );
62 effectElement.setAttribute( QStringLiteral(
"type" ),
type() );
64 element.appendChild( effectElement );
70 if ( element.isNull() )
85 mSourceImage =
nullptr;
93 mPrevPainter = context.
painter();
96 mTempPicture =
new QPicture();
98 delete mEffectPainter;
99 mEffectPainter =
new QPainter();
100 mEffectPainter->begin( mTempPicture );
107 if ( !mEffectPainter )
110 mEffectPainter->end();
111 delete mEffectPainter;
112 mEffectPainter =
nullptr;
116 mPrevPainter =
nullptr;
120 context.
painter()->setPen( Qt::NoPen );
121 context.
painter()->setBrush( Qt::NoBrush );
124 render( *mTempPicture, context );
128 mTempPicture =
nullptr;
137 painter.drawPicture( 0, 0, *mPicture );
141 painter.drawPicture( 0, 0, *mPicture );
158 const QRectF bounds = imageBoundingRect( context );
159 mSourceImage =
new QImage( bounds.width(), bounds.height(), QImage::Format_ARGB32 );
160 mSourceImage->fill( Qt::transparent );
161 QPainter imagePainter( mSourceImage );
162 imagePainter.setRenderHint( QPainter::Antialiasing );
163 imagePainter.translate( -bounds.left(), -bounds.top() );
164 imagePainter.drawPicture( 0, 0, *mPicture );
172 return imageBoundingRect( context ).topLeft();
187 painter->scale(
static_cast< double >(
qt_defaultDpiX() ) / painter->device()->logicalDpiX(),
188 static_cast< double >(
qt_defaultDpiY() ) / painter->device()->logicalDpiY() );
191 QRectF QgsPaintEffect::imageBoundingRect(
const QgsRenderContext &context )
const
193 return boundingRect( mPicture->boundingRect(), context );
213 QPainter *painter = context.
painter();
215 if ( mBlendMode == QPainter::CompositionMode_SourceOver &&
qgsDoubleNear( mOpacity, 1.0 ) )
226 painter->setCompositionMode( mBlendMode );
227 painter->drawImage(
imageOffset( context ), image );
239 props.insert( QStringLiteral(
"enabled" ),
mEnabled ?
"1" :
"0" );
240 props.insert( QStringLiteral(
"draw_mode" ), QString::number(
int(
mDrawMode ) ) );
241 props.insert( QStringLiteral(
"blend_mode" ), QString::number(
int( mBlendMode ) ) );
242 props.insert( QStringLiteral(
"opacity" ), QString::number( mOpacity ) );
249 const QPainter::CompositionMode mode =
static_cast< QPainter::CompositionMode
>( props.value( QStringLiteral(
"blend_mode" ) ).toInt( &ok ) );
254 if ( props.contains( QStringLiteral(
"transparency" ) ) )
256 const double transparency = props.value( QStringLiteral(
"transparency" ) ).toDouble( &ok );
259 mOpacity = 1.0 - transparency;
264 const double opacity = props.value( QStringLiteral(
"opacity" ) ).toDouble( &ok );
270 mEnabled = props.value( QStringLiteral(
"enabled" ), QStringLiteral(
"1" ) ).toInt();
280 : mRenderContext( renderContext )
283 mPainter = renderContext.
painter();
288 : mRenderContext( renderContext )
291 mPainter = mRenderContext.
painter();
293 mEffect->
begin( mRenderContext );
298 Q_ASSERT( !mEffect );
301 mEffect->
begin( mRenderContext );
308 mEffect->
end( mRenderContext );
A paint effect which draws the source picture with minor or no alterations.
QVariantMap properties() const override
Returns the properties describing the paint effect encoded in a string format.
QgsDrawSourceEffect()=default
Constructor for QgsDrawSourceEffect.
double opacity() const
Returns the opacity for the effect.
void draw(QgsRenderContext &context) override
Handles drawing of the effect's result on to the specified render context.
QgsDrawSourceEffect * clone() const override
Duplicates an effect by creating a deep copy of the effect.
static QgsPaintEffect * create(const QVariantMap &map)
Creates a new QgsDrawSource effect from a properties string map.
void readProperties(const QVariantMap &props) override
Reads a string map of an effect's properties and restores the effect to the state described by the pr...
QgsEffectPainter(QgsRenderContext &renderContext)
QgsEffectPainter constructor.
void setEffect(QgsPaintEffect *effect)
Sets the effect to be painted.
static void multiplyOpacity(QImage &image, double factor, QgsFeedback *feedback=nullptr)
Multiplies opacity of image pixel values by a factor.
Base class for visual effects which can be applied to QPicture drawings.
QgsPaintEffect()=default
Constructor for QgsPaintEffect.
bool requiresQPainterDpiFix
void setDrawMode(DrawMode drawMode)
Sets the draw mode for the effect.
void setEnabled(bool enabled)
Sets whether the effect is enabled.
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.
QPointF imageOffset(const QgsRenderContext &context) const
Returns the offset which should be used when drawing the source image on to a destination render cont...
virtual void render(QPicture &picture, QgsRenderContext &context)
Renders a picture using the effect.
DrawMode drawMode() const
Returns the draw mode for the effect.
virtual ~QgsPaintEffect()
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 QRectF boundingRect(const QRectF &rect, const QgsRenderContext &context) const
Returns the bounding rect required for drawing the effect.
virtual QVariantMap properties() const =0
Returns the properties describing the paint effect encoded in a string format.
void fixQPictureDpi(QPainter *painter) const
Applies a workaround to a QPainter to avoid an issue with incorrect scaling when drawing QPictures.
DrawMode
Drawing modes for effects.
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.
QImage * sourceAsImage(QgsRenderContext &context)
Returns the source QPicture rendered to a new QImage.
Contains information about the context of a rendering operation.
QPainter * painter()
Returns the destination QPainter for the render operation.
QgsFeedback * feedback() const
Returns the feedback object that can be queried regularly during rendering to check if rendering shou...
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.
Scoped object for saving and restoring a QPainter object's state.
static void saveProperties(QVariantMap props, QDomDocument &doc, QDomElement &element)
Saves the map of properties to XML.
static QVariantMap parseProperties(const QDomElement &element)
Parses the properties from XML and returns a map.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Q_GUI_EXPORT int qt_defaultDpiX()
Q_GUI_EXPORT int qt_defaultDpiY()