QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
28 : mEnabled( other.enabled() )
29 , mDrawMode( other.drawMode() )
40 delete mEffectPainter;
56 if ( element.isNull() )
61 QDomElement effectElement = doc.createElement( QStringLiteral(
"effect" ) );
62 effectElement.setAttribute( QStringLiteral(
"type" ),
type() );
65 for ( QgsStringMap::iterator it = props.begin(); it != props.end(); ++it )
67 QDomElement propEl = doc.createElement( QStringLiteral(
"prop" ) );
68 propEl.setAttribute( QStringLiteral(
"k" ), it.key() );
69 propEl.setAttribute( QStringLiteral(
"v" ), it.value() );
70 effectElement.appendChild( propEl );
73 element.appendChild( effectElement );
79 if ( element.isNull() )
87 QDomElement e = element.firstChildElement();
90 if ( e.tagName() != QLatin1String(
"prop" ) )
96 QString propKey = e.attribute( QStringLiteral(
"k" ) );
97 QString propValue = e.attribute( QStringLiteral(
"v" ) );
98 props[propKey] = propValue;
100 e = e.nextSiblingElement();
112 mSourceImage =
nullptr;
120 mPrevPainter = context.
painter();
123 mTempPicture =
new QPicture();
125 delete mEffectPainter;
126 mEffectPainter =
new QPainter();
127 mEffectPainter->begin( mTempPicture );
134 if ( !mEffectPainter )
137 mEffectPainter->end();
138 delete mEffectPainter;
139 mEffectPainter =
nullptr;
143 mPrevPainter =
nullptr;
147 context.
painter()->setPen( Qt::NoPen );
148 context.
painter()->setBrush( Qt::NoBrush );
151 render( *mTempPicture, context );
155 mTempPicture =
nullptr;
164 painter.drawPicture( 0, 0, *mPicture );
168 painter.drawPicture( 0, 0, *mPicture );
185 QRectF bounds = imageBoundingRect( context );
186 mSourceImage =
new QImage( bounds.width(), bounds.height(), QImage::Format_ARGB32 );
187 mSourceImage->fill( Qt::transparent );
188 QPainter imagePainter( mSourceImage );
189 imagePainter.setRenderHint( QPainter::Antialiasing );
190 imagePainter.translate( -bounds.left(), -bounds.top() );
191 imagePainter.drawPicture( 0, 0, *mPicture );
199 return imageBoundingRect( context ).topLeft();
214 painter->scale(
static_cast< double >(
qt_defaultDpiX() ) / painter->device()->logicalDpiX(),
215 static_cast< double >(
qt_defaultDpiY() ) / painter->device()->logicalDpiY() );
218 QRectF QgsPaintEffect::imageBoundingRect(
const QgsRenderContext &context )
const
220 return boundingRect( mPicture->boundingRect(), context );
240 QPainter *painter = context.
painter();
242 if ( mBlendMode == QPainter::CompositionMode_SourceOver &&
qgsDoubleNear( mOpacity, 1.0 ) )
253 painter->setCompositionMode( mBlendMode );
254 painter->drawImage(
imageOffset( context ), image );
266 props.insert( QStringLiteral(
"enabled" ),
mEnabled ?
"1" :
"0" );
267 props.insert( QStringLiteral(
"draw_mode" ), QString::number(
int(
mDrawMode ) ) );
268 props.insert( QStringLiteral(
"blend_mode" ), QString::number(
int( mBlendMode ) ) );
269 props.insert( QStringLiteral(
"opacity" ), QString::number( mOpacity ) );
276 QPainter::CompositionMode mode =
static_cast< QPainter::CompositionMode
>( props.value( QStringLiteral(
"blend_mode" ) ).toInt( &ok ) );
281 if ( props.contains( QStringLiteral(
"transparency" ) ) )
283 double transparency = props.value( QStringLiteral(
"transparency" ) ).toDouble( &ok );
286 mOpacity = 1.0 - transparency;
291 double opacity = props.value( QStringLiteral(
"opacity" ) ).toDouble( &ok );
297 mEnabled = props.value( QStringLiteral(
"enabled" ), QStringLiteral(
"1" ) ).toInt();
307 : mRenderContext( renderContext )
310 mPainter = renderContext.
painter();
315 : mRenderContext( renderContext )
318 mPainter = mRenderContext.
painter();
320 mEffect->
begin( mRenderContext );
325 Q_ASSERT( !mEffect );
328 mEffect->
begin( mRenderContext );
335 mEffect->
end( mRenderContext );
void drawSource(QPainter &painter)
Draws the source QPicture onto the specified painter.
DrawMode
Drawing modes for effects.
void setEffect(QgsPaintEffect *effect)
Sets the effect to be painted.
bool requiresQPainterDpiFix
virtual void render(QPicture &picture, QgsRenderContext &context)
Renders a picture using the effect.
void fixQPictureDpi(QPainter *painter) const
Applies a workaround to a QPainter to avoid an issue with incorrect scaling when drawing QPictures.
QgsStringMap properties() const override
Returns the properties describing the paint effect encoded in a string format.
QgsEffectPainter(QgsRenderContext &renderContext)
QgsEffectPainter constructor.
virtual void begin(QgsRenderContext &context)
Begins intercepting paint operations to a render context.
virtual QgsStringMap properties() const =0
Returns the properties describing the paint effect encoded in a string format.
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.
static void multiplyOpacity(QImage &image, double factor)
Multiplies opacity of image pixel values by a factor.
A paint effect which draws the source picture with minor or no alterations.
Contains information about the context of a rendering operation.
virtual bool saveProperties(QDomDocument &doc, QDomElement &element) const
Saves the current state of the effect to a DOM element.
QgsDrawSourceEffect()=default
Constructor for QgsDrawSourceEffect.
QgsDrawSourceEffect * clone() const override
Duplicates an effect by creating a deep copy of the effect.
void setDrawMode(DrawMode drawMode)
Sets the draw mode for the effect.
QgsPaintEffect()=default
Constructor for QgsPaintEffect.
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_defaultDpiY()
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 pr...
virtual QRectF boundingRect(const QRectF &rect, const QgsRenderContext &context) const
Returns the bounding rect required for drawing the effect.
void draw(QgsRenderContext &context) override
Handles drawing of the effect's result on to the specified render context.
virtual void end(QgsRenderContext &context)
Ends interception of paint operations to a render context, and draws the result to the render context...
DrawMode drawMode() const
Returns the draw mode for the effect.
Scoped object for saving and restoring a QPainter object's state.
QPointF imageOffset(const QgsRenderContext &context) const
Returns the offset which should be used when drawing the source image on to a destination render cont...
void setEnabled(bool enabled)
Sets whether the effect is enabled.
static QgsPaintEffect * create(const QgsStringMap &map)
Creates a new QgsDrawSource effect from a properties string map.
QMap< QString, QString > QgsStringMap
QImage * sourceAsImage(QgsRenderContext &context)
Returns the source QPicture rendered to a new QImage.
Base class for visual effects which can be applied to QPicture drawings.
virtual ~QgsPaintEffect()
Q_GUI_EXPORT int qt_defaultDpiX()
QPainter * painter()
Returns the destination QPainter for the render operation.
bool enabled() const
Returns whether the effect is enabled.
void readProperties(const QgsStringMap &props) override
Reads a string map of an effect's properties and restores the effect to the state described by the pr...
virtual QString type() const =0
Returns the effect type.
double opacity() const
Returns the opacity for the effect.
virtual void draw(QgsRenderContext &context)=0
Handles drawing of the effect's result on to the specified render context.