28using namespace Qt::StringLiterals;
34 for (
int i = 0; i < other.
count(); ++i )
43 std::swap( mEffectList, other.mEffectList );
76 for (
int i = 0; i < rhs.
count(); ++i )
89 std::swap( mEffectList, other.mEffectList );
97 effect->readProperties( map );
103 QPainter *destPainter = context.
painter();
108 bool requiresRasterization =
false;
113 requiresRasterization =
true;
118 if ( requiresRasterization )
129 const QPicture sourcePic =
source();
130 const QPicture *currentPic = &sourcePic;
131 std::vector< QPicture > results;
132 results.reserve( mEffectList.count() );
133 for (
int i = mEffectList.count() - 1; i >= 0; --i )
141 const QPicture *pic =
nullptr;
142 if (
effect->type() ==
"drawSource"_L1 )
153 QPainter p( &resultPic );
157 effect->requiresQPainterDpiFix =
false;
158 effect->render( *pic, context );
159 effect->requiresQPainterDpiFix =
true;
162 results.emplace_back( std::move( resultPic ) );
165 currentPic = &results.back();
171 for (
int i = 0; i < mEffectList.count(); ++i )
173 if ( !mEffectList[i]->
enabled() )
194 if ( element.isNull() )
199 QDomElement effectElement = doc.createElement( u
"effect"_s );
200 effectElement.setAttribute( u
"type"_s,
type() );
201 effectElement.setAttribute( u
"enabled"_s,
mEnabled );
207 ok = ok &&
effect->saveProperties( doc, effectElement );
210 element.appendChild( effectElement );
216 if ( element.isNull() )
221 mEnabled = ( element.attribute( u
"enabled"_s, u
"0"_s ) !=
"0"_L1 );
226 const QDomNodeList childNodes = element.childNodes();
227 for (
int i = 0; i < childNodes.size(); ++i )
229 const QDomElement childElement = childNodes.at( i ).toElement();
248void QgsEffectStack::clearStack()
250 qDeleteAll( mEffectList );
256 mEffectList.append(
effect );
261 if ( index < 0 || index > mEffectList.count() )
266 mEffectList.insert( index,
effect );
272 if ( index < 0 || index >= mEffectList.count() )
277 delete mEffectList.at( index );
278 mEffectList[index] =
effect;
284 if ( index < 0 || index >= mEffectList.count() )
287 return mEffectList.takeAt( index );
297 if ( index >= 0 && index < mEffectList.count() )
299 return mEffectList.at( index );
@ ForceVector
Always force vector-based rendering, even when the result will be visually different to a raster-base...
@ RequiresRasterization
The effect requires raster-based rendering.
QFlags< PaintEffectFlag > PaintEffectFlags
Flags which control how paint effects behave.
static QgsPaintEffectRegistry * paintEffectRegistry()
Returns the application's paint effect registry, used for managing paint effects.
void appendEffect(QgsPaintEffect *effect)
Appends an effect to the end of the stack.
bool saveProperties(QDomDocument &doc, QDomElement &element) const override
Saves the current state of the effect to a DOM element.
void draw(QgsRenderContext &context) override
Handles drawing of the effect's result on to the specified render context.
QgsEffectStack & operator=(const QgsEffectStack &rhs)
QString type() const override
Returns the effect type.
Qgis::PaintEffectFlags flags() const override
Returns flags which specify how the paint effect behaves.
static QgsPaintEffect * create(const QVariantMap &map)
Creates a new QgsEffectStack effect.
bool readProperties(const QDomElement &element) override
Restores the effect to the state described by a DOM element.
~QgsEffectStack() override
QList< QgsPaintEffect * > * effectList()
Returns a pointer to the list of effects currently contained by the stack.
QVariantMap properties() const override
Unused for QgsEffectStack, will always return an empty string map.
int count() const
Returns count of effects contained by the stack.
QgsEffectStack * clone() const override
Duplicates an effect by creating a deep copy of the effect.
bool insertEffect(int index, QgsPaintEffect *effect)
Inserts an effect at a specified index within the stack.
QgsPaintEffect * takeEffect(int index)
Removes an effect from the stack and returns a pointer to it.
bool changeEffect(int index, QgsPaintEffect *effect)
Replaces the effect at a specified position within the stack.
QgsPaintEffect * effect(int index) const
Returns a pointer to the effect at a specified index within the stack.
QgsPaintEffect * createEffect(const QString &name, const QVariantMap &properties=QVariantMap()) const
Creates a new paint effect given the effect name and properties map.
void drawSource(QPainter &painter)
Draws the source QPicture onto the specified painter.
const QPicture & source() const
Returns the source QPicture.
bool enabled() const
Returns whether the effect is enabled.
virtual QgsPaintEffect * clone() const =0
Duplicates an effect by creating a deep copy of the effect.
@ Render
The result of the effect is rendered on the destination, but does not affect subsequent effects in th...
@ Modifier
The result of the effect is not rendered, but is passed on to following effects in the stack.
static void drawPicture(QPainter *painter, const QPointF &point, const QPicture &picture)
Draws a picture onto a painter, correctly applying workarounds to avoid issues with incorrect scaling...
Contains information about the context of a rendering operation.
QPainter * painter()
Returns the destination QPainter for the render operation.
Qgis::RasterizedRenderingPolicy rasterizedRenderingPolicy() const
Returns the policy controlling when rasterisation of content during renders is permitted.
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.