QGIS API Documentation  2.18.3-Las Palmas (77b8c3d)
qgspainteffect.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgspainteffect.h
3  ----------------
4  begin : December 2014
5  copyright : (C) 2014 Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 #ifndef QGSPAINTEFFECT_H
18 #define QGSPAINTEFFECT_H
19 
20 #include "qgis.h"
21 #include "qgsrendercontext.h"
22 #include <QPainter>
23 #include <QDomDocument>
24 #include <QDomElement>
25 
49 class CORE_EXPORT QgsPaintEffect
50 {
51 
52  public:
53 
58  enum DrawMode
59  {
62  ModifyAndRender
63  };
64 
66  QgsPaintEffect( const QgsPaintEffect& other );
67  virtual ~QgsPaintEffect();
68 
72  virtual QString type() const = 0;
73 
77  virtual QgsPaintEffect* clone() const = 0;
78 
85  virtual QgsStringMap properties() const = 0;
86 
92  virtual void readProperties( const QgsStringMap& props ) = 0;
93 
102  virtual bool saveProperties( QDomDocument& doc, QDomElement& element ) const;
103 
109  virtual bool readProperties( const QDomElement& element );
110 
116  virtual void render( QPicture& picture, QgsRenderContext& context );
117 
125  virtual void begin( QgsRenderContext& context );
126 
132  virtual void end( QgsRenderContext& context );
133 
138  bool enabled() const { return mEnabled; }
139 
144  void setEnabled( const bool enabled );
145 
151  DrawMode drawMode() const { return mDrawMode; }
152 
158  void setDrawMode( const DrawMode drawMode );
159 
160  protected:
161 
162  bool mEnabled;
165 
172  virtual void draw( QgsRenderContext& context ) = 0;
173 
180  void drawSource( QPainter& painter );
181 
188  const QPicture* source() const { return mPicture; }
189 
200  QImage* sourceAsImage( QgsRenderContext &context );
201 
208  QPointF imageOffset( const QgsRenderContext& context ) const;
209 
218  virtual QRectF boundingRect( const QRectF& rect, const QgsRenderContext& context ) const;
219 
225  void fixQPictureDpi( QPainter* painter ) const;
226 
227  private:
228 
229  const QPicture* mPicture;
230  QImage* mSourceImage;
231  bool mOwnsImage;
232 
233  QPainter* mPrevPainter;
234  QPainter* mEffectPainter;
235  QPicture* mTempPicture;
236 
237  QRectF imageBoundingRect( const QgsRenderContext& context ) const;
238 
239  friend class QgsEffectStack;
240 
241 };
242 
255 class CORE_EXPORT QgsDrawSourceEffect : public QgsPaintEffect
256 {
257  public:
258 
260  virtual ~QgsDrawSourceEffect();
261 
266  static QgsPaintEffect* create( const QgsStringMap& map );
267 
268  virtual QString type() const override { return QString( "drawSource" ); }
269  virtual QgsDrawSourceEffect* clone() const override;
270  virtual QgsStringMap properties() const override;
271  virtual void readProperties( const QgsStringMap& props ) override;
272 
278  void setTransparency( const double transparency ) { mTransparency = transparency; }
279 
285  double transparency() const { return mTransparency; }
286 
292  void setBlendMode( const QPainter::CompositionMode mode ) { mBlendMode = mode; }
293 
299  QPainter::CompositionMode blendMode() const { return mBlendMode; }
300 
301  protected:
302 
303  virtual void draw( QgsRenderContext& context ) override;
304 
305  private:
306 
307  double mTransparency;
308  QPainter::CompositionMode mBlendMode;
309 };
310 
311 #endif // QGSPAINTEFFECT_H
312 
virtual QgsStringMap properties() const =0
Returns the properties describing the paint effect encoded in a string format.
DrawMode mDrawMode
DrawMode drawMode() const
Returns the draw mode for the effect.
bool enabled() const
Returns whether the effect is enabled.
Base class for visual effects which can be applied to QPicture drawings.
double transparency() const
Returns the transparency for the effect.
virtual QgsPaintEffect * clone() const =0
Duplicates an effect by creating a deep copy of the effect.
void setTransparency(const double transparency)
Sets the transparency for the effect.
void setBlendMode(const QPainter::CompositionMode mode)
Sets the blend mode for the effect.
A paint effect which consists of a stack of other chained paint effects.
bool requiresQPainterDpiFix
DrawMode
Drawing modes for effects.
virtual void readProperties(const QgsStringMap &props)=0
Reads a string map of an effect&#39;s properties and restores the effect to the state described by the pr...
Contains information about the context of a rendering operation.
const QPicture * source() const
Returns the source QPicture.
virtual void draw(QgsRenderContext &context)=0
Handles drawing of the effect&#39;s result on to the specified render context.
virtual QString type() const override
Returns the effect type.
A paint effect which draws the source picture with minor or no alterations.
QPainter::CompositionMode blendMode() const
Returns the blend mode for the effect.