29 for (
int i = 0; i < other.
count(); ++i )
38 std::swap( mEffectList, other.mEffectList );
71 for (
int i = 0; i < rhs.
count(); ++i )
81 std::swap( mEffectList, other.mEffectList );
95 QPainter *destPainter = context.
painter();
100 bool requiresRasterization =
false;
105 requiresRasterization =
true;
110 if ( requiresRasterization )
121 const QPicture sourcePic =
source();
122 const QPicture *currentPic = &sourcePic;
123 std::vector< QPicture > results;
124 results.reserve( mEffectList.count() );
125 for (
int i = mEffectList.count() - 1; i >= 0; --i )
133 const QPicture *pic =
nullptr;
134 if (
effect->
type() == QLatin1String(
"drawSource" ) )
145 QPainter p( &resultPic );
154 results.emplace_back( std::move( resultPic ) );
157 currentPic = &results.back();
163 for (
int i = 0; i < mEffectList.count(); ++i )
165 if ( !mEffectList[i]->
enabled() )
186 if ( element.isNull() )
191 QDomElement effectElement = doc.createElement( QStringLiteral(
"effect" ) );
192 effectElement.setAttribute( QStringLiteral(
"type" ),
type() );
193 effectElement.setAttribute( QStringLiteral(
"enabled" ),
mEnabled );
202 element.appendChild( effectElement );
208 if ( element.isNull() )
213 mEnabled = ( element.attribute( QStringLiteral(
"enabled" ), QStringLiteral(
"0" ) ) != QLatin1String(
"0" ) );
218 const QDomNodeList childNodes = element.childNodes();
219 for (
int i = 0; i < childNodes.size(); ++i )
221 const QDomElement childElement = childNodes.at( i ).toElement();
240void QgsEffectStack::clearStack()
242 qDeleteAll( mEffectList );
248 mEffectList.append(
effect );
253 if ( index < 0 || index > mEffectList.count() )
258 mEffectList.insert( index,
effect );
264 if ( index < 0 || index >= mEffectList.count() )
269 delete mEffectList.at( index );
270 mEffectList[index] =
effect;
276 if ( index < 0 || index >= mEffectList.count() )
279 return mEffectList.takeAt( index );
289 if ( index >= 0 && index < mEffectList.count() )
291 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.
A paint effect which consists of a stack of other chained 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.
Base class for visual effects which can be applied to QPicture drawings.
bool requiresQPainterDpiFix
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...
const QPicture & source() const
Returns the source QPicture.
bool enabled() const
Returns whether the effect is enabled.
virtual Qgis::PaintEffectFlags flags() const
Returns flags which specify how the paint effect behaves.
virtual void render(const QPicture &picture, QgsRenderContext &context)
Renders a picture using the effect.
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.
virtual QString type() const =0
Returns the effect type.
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.